Skip to content

Commit 251e595

Browse files
authored
Merge pull request #4328 from jrose-apple/swift-3-IBAction-as-Any
Allow 'Any' as an IBAction's sender and an IBOutlet's type. (#4320)
2 parents 827366d + f6a240b commit 251e595

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void AttributeEarlyChecker::visitSILStoredAttr(SILStoredAttr *attr) {
343343

344344
static Optional<Diag<bool,Type>>
345345
isAcceptableOutletType(Type type, bool &isArray, TypeChecker &TC) {
346-
if (type->isObjCExistentialType())
346+
if (type->isObjCExistentialType() || type->isAny())
347347
return None; // @objc existential types are okay
348348

349349
auto nominal = type->getAnyNominal();
@@ -800,8 +800,8 @@ static bool checkObjectOrOptionalObjectType(TypeChecker &TC, Decl *D,
800800
.highlight(param->getSourceRange());
801801
return true;
802802
}
803-
} else if (ty->isObjCExistentialType()) {
804-
// @objc existential types are okay
803+
} else if (ty->isObjCExistentialType() || ty->isAny()) {
804+
// @objc existential types are okay, as is Any.
805805
// Nothing to do.
806806
} else {
807807
// No other types are permitted.

test/attr/attr_ibaction.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protocol CP2 : class { }
6363
@IBAction func action5(_: AnyObject?) {}
6464
@IBAction func action6(_: AnyObject!) {}
6565

66+
// Any
67+
@IBAction func action4a(_: Any) {}
68+
@IBAction func action5a(_: Any?) {}
69+
@IBAction func action6a(_: Any!) {}
70+
6671
// Protocol types
6772
@IBAction func action7(_: P1) {} // expected-error{{argument to @IBAction method cannot have non-object type 'P1'}}
6873
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}

test/attr/attr_iboutlet.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class NonObjC {}
6464
@IBOutlet var outlet5: AnyObject?
6565
@IBOutlet var outlet6: AnyObject!
6666

67+
// Any
68+
@IBOutlet var outlet5a: Any?
69+
@IBOutlet var outlet6a: Any!
70+
6771
// Protocol types
6872
@IBOutlet var outlet7: P1 // expected-error{{@IBOutlet property cannot have non-'@objc' protocol type 'P1'}} {{3-13=}}
6973
@IBOutlet var outlet8: CP1 // expected-error{{@IBOutlet property cannot have non-'@objc' protocol type 'CP1'}} {{3-13=}}

0 commit comments

Comments
 (0)