File: objc_redeclaration.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (81 lines) | stat: -rw-r--r-- 3,864 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -module-name ZZZ %s -disable-objc-attr-requires-foundation-module -verify -verify-ignore-unknown

import Foundation

// REQUIRES: objc_interop

@objc class Redecl1 { // expected-note{{implicit deinitializer declared here}}
  @objc init() { } // expected-note{{initializer 'init()' declared here}}

  @objc
  func method1() { } // expected-note 2{{method 'method1()' declared here}}

  @objc var value: Int // expected-note{{setter for 'value' declared here}}

  @objc(wibble) var other: Int
  // expected-note@-1{{getter for 'other' declared here}}
  // expected-note@-2{{setter for 'other' declared here}}
}

extension Redecl1 {
  @objc(method1)
  func method1_alias() { } // expected-error{{method 'method1_alias()' with Objective-C selector 'method1' conflicts with method 'method1()' with the same Objective-C selector}}
}

extension Redecl1 {
  @objc var method1_var_alias: Int {
    @objc(method1) get { return 5 } // expected-error{{getter for 'method1_var_alias' with Objective-C selector 'method1' conflicts with method 'method1()' with the same Objective-C selector}}

    @objc(method2:) set { } // expected-error{{setter for 'method1_var_alias' with Objective-C selector 'method2:' conflicts with method 'method2' with the same Objective-C selector}}
  }

  @objc subscript (i: Int) -> Redecl1 {
    get { return self } // expected-note{{subscript getter declared here}}
    set { }
  }
}

extension Redecl1 {
  @objc
  func method2(_ x: Int) { } // expected-note{{method 'method2' declared here}}

  @objc(objectAtIndexedSubscript:)
  func indexed(_ x: Int) { } // expected-error{{method 'indexed' with Objective-C selector 'objectAtIndexedSubscript:' conflicts with subscript getter with the same Objective-C selector}}

  @objc(init)
  func initialize() { } // expected-error{{method 'initialize()' with Objective-C selector 'init' conflicts with initializer 'init()' with the same Objective-C selector}}

  @objc
  func dealloc() { } // expected-error{{method 'dealloc()' with Objective-C selector 'dealloc' conflicts with implicit deinitializer with the same Objective-C selector}}

  @objc func setValue(_ x: Int) { } // expected-error{{method 'setValue' with Objective-C selector 'setValue:' conflicts with setter for 'value' with the same Objective-C selector}}
}

extension Redecl1 {
  @objc func setWibble(_ other: Int) { } // expected-error{{method 'setWibble' with Objective-C selector 'setWibble:' conflicts with setter for 'other' with the same Objective-C selector}}
  @objc func wibble() -> Int { return 0 } // expected-error{{method 'wibble()' with Objective-C selector 'wibble' conflicts with getter for 'other' with the same Objective-C selector}}
}

extension DummyClass {
  @objc func nsstringProperty2() -> Int { return 0 } // expected-error{{method 'nsstringProperty2()' with Objective-C selector 'nsstringProperty2' conflicts with getter for 'nsstringProperty2' with the same Objective-C selector}}
}

open class MyObject: NSObject {} // expected-note{{implicit initializer 'init()' declared here}}

extension MyObject {
    public override convenience init() {} // expected-error{{initializer 'init()' with Objective-C selector 'init' conflicts with implicit initializer 'init()' with the same Objective-C selector}}
}

// Ensure that we don't have cycles with the "renamed decl" request.
@available(SwiftStdlib 5.1, *)
@objc protocol MyProtocolWithAsync {
  @available(*, renamed: "confirm(thing:)")
  @objc(confirmThing:completion:)
  optional func confirm(thing: AnyObject, completion: @escaping (AnyObject) -> Void)

  @objc(confirmThing:completion:)
  optional func confirm(thing: AnyObject) async -> AnyObject
}

// FIXME: Remove -verify-ignore-unknown.
// <unknown>:0: error: unexpected note produced: 'nsstringProperty2' previously declared here