Skip to content

Commit

Permalink
Allow 'Any' as an IBAction's sender and an IBOutlet's type. (#4320)
Browse files Browse the repository at this point in the history
With id-as-Any, /existing/ IBAction methods that have unconstrained
sender parameters are being imported as taking 'Any?', and those
methods then can't be overridden in Swift.

We still don't allow arbitrary bridgeable types for IBActions and
IBOutlets. This makes enough sense for value types, but might get us
into trouble with swift_newtype at some point.

rdar://problem/27853737
  • Loading branch information
jrose-apple committed Aug 16, 2016
1 parent 560ffef commit ed01f89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void AttributeEarlyChecker::visitSILStoredAttr(SILStoredAttr *attr) {

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

auto nominal = type->getAnyNominal();
Expand Down Expand Up @@ -800,8 +800,8 @@ static bool checkObjectOrOptionalObjectType(TypeChecker &TC, Decl *D,
.highlight(param->getSourceRange());
return true;
}
} else if (ty->isObjCExistentialType()) {
// @objc existential types are okay
} else if (ty->isObjCExistentialType() || ty->isAny()) {
// @objc existential types are okay, as is Any.
// Nothing to do.
} else {
// No other types are permitted.
Expand Down
5 changes: 5 additions & 0 deletions test/attr/attr_ibaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ protocol CP2 : class { }
@IBAction func action5(_: AnyObject?) {}
@IBAction func action6(_: AnyObject!) {}

// Any
@IBAction func action4a(_: Any) {}
@IBAction func action5a(_: Any?) {}
@IBAction func action6a(_: Any!) {}

// Protocol types
@IBAction func action7(_: P1) {} // expected-error{{argument to @IBAction method cannot have non-object type 'P1'}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
Expand Down
4 changes: 4 additions & 0 deletions test/attr/attr_iboutlet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class NonObjC {}
@IBOutlet var outlet5: AnyObject?
@IBOutlet var outlet6: AnyObject!

// Any
@IBOutlet var outlet5a: Any?
@IBOutlet var outlet6a: Any!

// Protocol types
@IBOutlet var outlet7: P1 // expected-error{{@IBOutlet property cannot have non-'@objc' protocol type 'P1'}} {{3-13=}}
@IBOutlet var outlet8: CP1 // expected-error{{@IBOutlet property cannot have non-'@objc' protocol type 'CP1'}} {{3-13=}}
Expand Down

0 comments on commit ed01f89

Please sign in to comment.