Files
swift-mirror/test/decl/ext/extension-generic-objc.swift
2017-03-15 20:58:11 -07:00

50 lines
1.3 KiB
Swift

// RUN: %target-swift-frontend -typecheck -verify %s
// REQUIRES: objc_interop
import Foundation
// Tests for correct detection of the "objc_in_generic_extension" error,
// declared in {Swift Source}/include/swift/AST/DiagnosticsSema.def
// Test "0 levels" deep
class A<T> : NSObject {
init(a: ()) {
super.init()
}
}
extension A {
// This should throw an error
@objc func a1() {} // expected-error{{@objc is not supported within extensions of generic classes or classes that inherit from generic classes}}
// This should *not* throw an error
func a2() {}
}
// Test "1 level" deep
class B : A<Int> {
init(b: ()) {
super.init(a: ())
}
}
extension B {
// This should throw an error
@objc func b1() {} // expected-error{{@objc is not supported within extensions of generic classes or classes that inherit from generic classes}}
// This should *not* throw an error
func b2() {}
}
// Test "many levels" deep
class C : B {}
class D : C {
init(d: ()) {
super.init(b: ())
}
}
extension D {
// This should throw an error
@objc func d1() {} // expected-error{{@objc is not supported within extensions of generic classes or classes that inherit from generic classes}}
// This should *not* throw an error
func d2() {}
}