mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The Swift class model does not support overriding declarations where either the overridden declaration or the overriding declaration are in an extension. However, the Objective-C class model does, so marking the declaration as @objc (when possible) will work around the limitation. Customize the "cannot override declaration in extension" diagnostic to suggest adding @objc to the overridden declaration in cases where @objc is permitted. Fixes SR-6512 / rdar://problem/35787914.
40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
// RUN: %target-typecheck-verify-swift -swift-version 4
|
|
//
|
|
// REQUIRES: objc_interop
|
|
|
|
class MixedKeywordsAndAttributes { // expected-note{{in declaration of 'MixedKeywordsAndAttributes'}}
|
|
// expected-error@+1 {{expected declaration}} expected-error@+1 {{consecutive declarations on a line must be separated by ';'}} {{11-11=;}}
|
|
override @objc func f1() {}
|
|
}
|
|
|
|
@objc class ObjCClass {}
|
|
struct SwiftStruct { }
|
|
|
|
class A {
|
|
@objc subscript (a: ObjCClass) -> ObjCClass { // expected-note{{overridden declaration here has type '(ObjCClass) -> ObjCClass'}}
|
|
get { return ObjCClass() }
|
|
}
|
|
|
|
func bar() { } // expected-note{{add '@objc' to make this declaration overridable}}{{3-3=@objc }}
|
|
}
|
|
|
|
extension A {
|
|
func foo() { } // expected-note{{add '@objc' to make this declaration overridable}}{{3-3=@objc }}
|
|
func wibble(_: SwiftStruct) { } // expected-note{{overridden declaration is here}}
|
|
}
|
|
|
|
class B : A {
|
|
// Objective-C
|
|
@objc subscript (a: ObjCClass) -> AnyObject { // expected-error{{overriding keyed subscript with incompatible type '(ObjCClass) -> AnyObject'}}
|
|
get { return self }
|
|
}
|
|
|
|
override func foo() { } // expected-error{{overriding non-@objc declarations from extensions is not supported}}
|
|
|
|
override func wibble(_: SwiftStruct) { } // expected-error{{overriding declarations in extensions is not supported}}
|
|
}
|
|
|
|
extension B {
|
|
override func bar() { } // expected-error{{overriding non-@objc declarations from extensions is not supported}}
|
|
}
|