Skip to content

Commit 086f20a

Browse files
committed
Describe ObjC reason for effectful properites
1 parent e611e10 commit 086f20a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,9 @@ bool swift::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
10491049
// to mark them as @objc
10501050
if (VD->getEffectfulGetAccessor()) {
10511051
VD->diagnose(diag::effectful_not_representable_objc,
1052-
VD->getDescriptiveKind());
1052+
VD->getDescriptiveKind())
1053+
.limitBehavior(behavior);
1054+
Reason.describe(VD);
10531055
return false;
10541056
}
10551057

@@ -1088,7 +1090,9 @@ bool swift::isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason) {
10881090
// to mark them as @objc
10891091
if (SD->getEffectfulGetAccessor()) {
10901092
SD->diagnose(diag::effectful_not_representable_objc,
1091-
SD->getDescriptiveKind());
1093+
SD->getDescriptiveKind())
1094+
.limitBehavior(behavior);
1095+
Reason.describe(SD);
10921096
return false;
10931097
}
10941098

test/decl/protocol/effectful_properties_objc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
/////////
66
// check for disallowed attributes in protocols
77
@objc protocol Tea {
8-
var temperature : Double { get throws } // expected-error{{property with 'throws' or 'async' is not representable in Objective-C}}
9-
subscript(_ d : Double) -> Bool { get async throws } // expected-error{{subscript with 'throws' or 'async' is not representable in Objective-C}}
8+
var temperature : Double { get throws } // expected-error{{property with 'throws' or 'async' is not representable in Objective-C}} expected-note{{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
9+
subscript(_ d : Double) -> Bool { get async throws } // expected-error{{subscript with 'throws' or 'async' is not representable in Objective-C}} expected-note{{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
1010

1111
// NOTE: this seems counter-intuitive, but TSPL says @nonobjc applies to
1212
// members that are representable in ObjC, and this is not representable.
13-
@nonobjc var sugar : Bool { get async } // expected-error{{property with 'throws' or 'async' is not representable in Objective-C}}
14-
}
13+
@nonobjc var sugar : Bool { get async } // expected-error{{property with 'throws' or 'async' is not representable in Objective-C}} expected-note{{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
14+
}

0 commit comments

Comments
 (0)