Skip to content

Commit

Permalink
Merge pull request #8140 from TheOtherDave/SR-4232
Browse files Browse the repository at this point in the history
A clarification of an error message
  • Loading branch information
jrose-apple committed Mar 17, 2017
2 parents fbec8c1 + 7eee82a commit 5aa02eb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Expand Up @@ -2952,7 +2952,7 @@ ERROR(invalid_nonobjc_decl,none,
ERROR(objc_in_extension_context,none,
"members of constrained extensions cannot be declared @objc", ())
ERROR(objc_in_generic_extension,none,
"@objc is not supported within extensions of generic classes", ())
"@objc is not supported within extensions of generic classes or classes that inherit from generic classes", ())
ERROR(objc_operator, none,
"operator methods cannot be declared @objc", ())
ERROR(objc_operator_proto, none,
Expand Down
49 changes: 49 additions & 0 deletions test/decl/ext/extension-generic-objc.swift
@@ -0,0 +1,49 @@
// 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() {}
}

0 comments on commit 5aa02eb

Please sign in to comment.