Skip to content

Commit d004bba

Browse files
committed
---
yaml --- r: 347894 b: refs/heads/master c: 598bff9 h: refs/heads/master
1 parent 51f02b5 commit d004bba

13 files changed

+57
-95
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: cdf9a8b00bd0fa71373fea3fa2b5adba1cf3a83a
2+
refs/heads/master: 598bff9b8306ad74fb4492f9169e217cf78238c3
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,17 +3953,9 @@ ERROR(borrowed_on_objc_protocol_requirement,none,
39533953
// MARK: dynamic
39543954
//------------------------------------------------------------------------------
39553955

3956-
ERROR(dynamic_not_in_class,none,
3957-
"only members of classes may be dynamic", ())
3958-
ERROR(dynamic_with_nonobjc,none,
3959-
"a declaration cannot be both '@nonobjc' and 'dynamic'",
3960-
())
39613956
ERROR(dynamic_with_transparent,none,
39623957
"a declaration cannot be both '@_tranparent' and 'dynamic'",
39633958
())
3964-
ERROR(dynamic_requires_objc,none,
3965-
"'dynamic' %0 %1 must also be '@objc'",
3966-
(DescriptiveDeclKind, DeclName))
39673959

39683960
//------------------------------------------------------------------------------
39693961
// MARK: @_dynamicReplacement(for:)

trunk/lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ PropertyDelegateBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17941794
VarDecl *storageVar = nullptr;
17951795
if (delegateInfo.delegateValueVar) {
17961796
storageVar = synthesizePropertyDelegateStorageDelegateProperty(
1797-
ctx, var, delegateType, delegateInfo.delegateValueVar);
1797+
ctx, var, storageType, delegateInfo.delegateValueVar);
17981798
}
17991799

18001800
// Get the property delegate information.

trunk/lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,8 @@ void AttributeEarlyChecker::visitMutationAttr(DeclAttribute *attr) {
328328
}
329329

330330
void AttributeEarlyChecker::visitDynamicAttr(DynamicAttr *attr) {
331-
// Members cannot be both dynamic and @nonobjc.
332-
if (D->getAttrs().hasAttribute<NonObjCAttr>())
333-
diagnoseAndRemoveAttr(attr, diag::dynamic_with_nonobjc);
334-
335331
// Members cannot be both dynamic and @_transparent.
336-
if (D->getASTContext().LangOpts.isSwiftVersionAtLeast(5) &&
337-
D->getAttrs().hasAttribute<TransparentAttr>())
332+
if (D->getAttrs().hasAttribute<TransparentAttr>())
338333
diagnoseAndRemoveAttr(attr, diag::dynamic_with_transparent);
339334
}
340335

trunk/lib/Sema/TypeCheckDecl.cpp

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,36 +1110,14 @@ static bool inferFinalAndDiagnoseIfNeeded(ValueDecl *D,
11101110
return true;
11111111
}
11121112

1113-
/// Try to make the given declaration 'dynamic', checking any semantic
1114-
/// constraints before doing so.
1115-
///
1116-
/// \returns true if it can be made dynamic, false otherwise.
1117-
static bool makeObjCDynamic(ValueDecl *decl) {
1118-
// Only members of classes can be dynamic.
1119-
auto classDecl = decl->getDeclContext()->getSelfClassDecl();
1120-
if (!classDecl) {
1121-
auto attr = decl->getAttrs().getAttribute<DynamicAttr>();
1122-
decl->diagnose(diag::dynamic_not_in_class)
1123-
.fixItRemove(attr ? SourceRange(attr->getLocation()) : SourceRange());
1124-
return false;
1125-
}
1126-
1127-
// '@objc dynamic' is only supported through the Objective-C runtime.
1128-
if (!decl->isObjC()) {
1129-
decl->diagnose(diag::dynamic_requires_objc,
1130-
decl->getDescriptiveKind(), decl->getFullName())
1131-
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/false),
1132-
"@objc ");
1133-
return false;
1134-
}
1135-
1113+
/// Make the given declaration 'dynamic', if it isn't already marked as such.
1114+
static void makeDynamic(ValueDecl *decl) {
11361115
// If there isn't already a 'dynamic' attribute, add an inferred one.
1137-
if (!decl->getAttrs().hasAttribute<DynamicAttr>()) {
1138-
auto attr = new (decl->getASTContext()) DynamicAttr(/*implicit=*/true);
1139-
decl->getAttrs().add(attr);
1140-
}
1141-
1142-
return true;
1116+
if (decl->getAttrs().hasAttribute<DynamicAttr>())
1117+
return;
1118+
1119+
auto attr = new (decl->getASTContext()) DynamicAttr(/*implicit=*/true);
1120+
decl->getAttrs().add(attr);
11431121
}
11441122

11451123
static llvm::Expected<bool> isStorageDynamic(Evaluator &evaluator,
@@ -1301,9 +1279,7 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
13011279

13021280
// If 'dynamic' was explicitly specified, check it.
13031281
if (decl->getAttrs().hasAttribute<DynamicAttr>()) {
1304-
if (decl->getASTContext().LangOpts.isSwiftVersionAtLeast(5))
1305-
return true;
1306-
return makeObjCDynamic(decl);
1282+
return true;
13071283
}
13081284

13091285
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
@@ -1319,15 +1295,11 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
13191295
case AccessorKind::Get:
13201296
case AccessorKind::Set: {
13211297
auto isDynamicResult = evaluator(
1322-
IsDynamicRequest{accessor->getStorage()});
1323-
1324-
if (!isDynamicResult)
1325-
return isDynamicResult;
1326-
1327-
if (*isDynamicResult)
1328-
return makeObjCDynamic(decl);
1329-
1330-
return false;
1298+
IsDynamicRequest{accessor->getStorage()});
1299+
if (isDynamicResult && *isDynamicResult)
1300+
makeDynamic(decl);
1301+
1302+
return isDynamicResult;
13311303
}
13321304

13331305
#define OBJC_ACCESSOR(ID, KEYWORD)
@@ -1342,7 +1314,8 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
13421314
// FIXME: Use a semantic check for NSManaged rather than looking for the
13431315
// attribute (which could be ill-formed).
13441316
if (decl->getAttrs().hasAttribute<NSManagedAttr>()) {
1345-
return makeObjCDynamic(decl);
1317+
makeDynamic(decl);
1318+
return true;
13461319
}
13471320

13481321
// The presence of 'final' blocks the inference of 'dynamic'.
@@ -1361,7 +1334,8 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
13611334
// This is intended to enable overriding the declarations.
13621335
auto dc = decl->getDeclContext();
13631336
if (isa<ExtensionDecl>(dc) && dc->getSelfClassDecl()) {
1364-
return makeObjCDynamic(decl);
1337+
makeDynamic(decl);
1338+
return true;
13651339
}
13661340

13671341
// If any of the declarations overridden by this declaration are dynamic
@@ -1372,13 +1346,10 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
13721346
auto overriddenDecls = evaluateOrDefault(evaluator,
13731347
OverriddenDeclsRequest{decl}, {});
13741348
for (auto overridden : overriddenDecls) {
1375-
if (overridden->isDynamic() &&
1376-
(!decl->getASTContext().LangOpts.isSwiftVersionAtLeast(5) ||
1377-
overridden->isObjC()))
1378-
return makeObjCDynamic(decl);
1379-
1380-
if (overridden->hasClangNode())
1381-
return makeObjCDynamic(decl);
1349+
if (overridden->isDynamic() || overridden->hasClangNode()) {
1350+
makeDynamic(decl);
1351+
return true;
1352+
}
13821353
}
13831354

13841355
return false;

trunk/lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,15 +1241,6 @@ Optional<ObjCReason> shouldMarkAsObjC(const ValueDecl *VD, bool allowImplicit) {
12411241

12421242
return ObjCReason(ObjCReason::ExplicitlyDynamic);
12431243
}
1244-
if (!ctx.isSwiftVersionAtLeast(5)) {
1245-
// Complain that 'dynamic' requires '@objc', but (quietly) infer @objc
1246-
// anyway for better recovery.
1247-
VD->diagnose(diag::dynamic_requires_objc, VD->getDescriptiveKind(),
1248-
VD->getFullName())
1249-
.fixItInsert(VD->getAttributeInsertionLoc(/*forModifier=*/false),
1250-
"@objc ");
1251-
return ObjCReason(ObjCReason::ImplicitlyObjC);
1252-
}
12531244
}
12541245

12551246
// If we aren't provided Swift 3's @objc inference rules, we're done.
@@ -2363,4 +2354,4 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
23632354
}
23642355

23652356
return anyDiagnosed;
2366-
}
2357+
}

trunk/test/attr/attr_dynamic.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@ dynamic prefix operator +!+ // expected-error{{'dynamic' modifier cannot be app
1212
class Foo {
1313
@objc dynamic init() {}
1414
@objc dynamic init(x: NotObjCAble) {} // expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
15-
// expected-error@-1{{'dynamic' initializer 'init(x:)' must also be '@objc}}
1615

1716
@objc dynamic var x: Int
1817

1918
@objc dynamic var nonObjcVar: NotObjCAble // expected-error{{property cannot be marked @objc because its type cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
20-
// expected-error@-1{{'dynamic' property 'nonObjcVar' must also be '@objc'}}
2119

2220
@objc dynamic func foo(x: Int) {}
2321
@objc dynamic func bar(x: Int) {}
2422

2523
@objc dynamic func nonObjcFunc(x: NotObjCAble) {} // expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
26-
// expected-error@-1{{'dynamic' instance method 'nonObjcFunc(x:)' must also be '@objc'}}
2724

2825
@objc dynamic subscript(x: Int) -> ObjCClass { get {} }
2926

3027
@objc dynamic subscript(x: Int) -> NotObjCAble { get {} } // expected-error{{subscript cannot be marked @objc because its type cannot be represented in Objective-C}} expected-note{{Swift structs cannot be represented in Objective-C}}
31-
// expected-error@-1{{'dynamic' subscript 'subscript(_:)' must also be '@objc'}}
3228

3329
dynamic deinit {} // expected-error{{'dynamic' modifier cannot be applied to this declaration}} {{3-11=}}
3430

@@ -38,13 +34,13 @@ class Foo {
3834
}
3935

4036
struct Bar {
41-
dynamic init() {} // expected-error{{only members of classes may be dynamic}} {{3-11=}}
37+
dynamic init() {}
4238

43-
dynamic var x: Int // expected-error{{only members of classes may be dynamic}} {{3-11=}}
39+
dynamic var x: Int
4440

45-
dynamic subscript(x: Int) -> ObjCClass { get {} } // expected-error{{only members of classes may be dynamic}} {{3-11=}}
41+
dynamic subscript(x: Int) -> ObjCClass { get {} }
4642

47-
dynamic func foo(x: Int) {} // expected-error{{only members of classes may be dynamic}} {{3-11=}}
43+
dynamic func foo(x: Int) {}
4844
}
4945

5046
// CHECK-LABEL: class InheritsDynamic : Foo {
@@ -61,5 +57,5 @@ class InheritsDynamic: Foo {
6157
// SR-5317
6258
@objcMembers
6359
class ObjCMemberCheck {
64-
dynamic var s = NotObjCAble(c: Foo()) // expected-error{{'dynamic' property 's' must also be '@objc'}}
60+
dynamic var s = NotObjCAble(c: Foo())
6561
}

trunk/test/attr/attr_nonobjc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class ObjCAndNonObjCNotAllowed {
6767
@objc @nonobjc func redundantAttributes() { } // expected-error {{declaration is marked @objc, and cannot be marked @nonobjc}}
6868
}
6969

70-
class DynamicAndNonObjCNotAllowed {
71-
@nonobjc dynamic func redundantAttributes() { } // expected-error {{a declaration cannot be both '@nonobjc' and 'dynamic'}}
70+
class DynamicAndNonObjCAreFineNow {
71+
@nonobjc dynamic func someAttributes() { }
7272
}
7373

7474
class IBOutletAndNonObjCNotAllowed {

trunk/test/attr/attr_objc.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,7 @@ class HasNSManaged {
17241724
var badManaged: PlainStruct
17251725
// expected-error@-1 {{property cannot be marked @NSManaged because its type cannot be represented in Objective-C}}
17261726
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
1727-
// expected-error@-3{{'dynamic' property 'badManaged' must also be '@objc'}}
1728-
// CHECK-LABEL: {{^}} @NSManaged var badManaged: PlainStruct {
1727+
// CHECK-LABEL: {{^}} @NSManaged dynamic var badManaged: PlainStruct {
17291728
// CHECK-NEXT: {{^}} get
17301729
// CHECK-NEXT: {{^}} set
17311730
// CHECK-NEXT: {{^}} }

trunk/test/attr/attr_objc_swift4.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ class ObjCSubclass : NSObject {
99
}
1010

1111
class DynamicMembers {
12-
dynamic func foo() { } // expected-error{{'dynamic' instance method 'foo()' must also be '@objc'}}{{3-3=@objc }}
12+
@objc dynamic func foo() { }
1313

14-
dynamic var bar: NSObject? = nil
15-
// expected-error@-1{{'dynamic' property 'bar' must also be '@objc'}}{{3-3=@objc }}
14+
@objc dynamic var bar: NSObject? = nil
1615
}
1716

1817
func test(sc: ObjCSubclass, dm: DynamicMembers) {

trunk/test/decl/inherit/override.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class A {
1313
@objc var v2: Int { return 0 } // expected-note{{overri}}
1414
@objc var v3: Int = 0 // expected-note{{overri}}
1515

16-
dynamic func f3D() { } // expected-error{{'dynamic' instance method 'f3D()' must also be '@objc'}}{{3-3=@objc }}
17-
dynamic func f4D() -> ObjCClassA { } // expected-error{{'dynamic' instance method 'f4D()' must also be '@objc'}}{{3-3=@objc }}
16+
@objc dynamic func f3D() { }
17+
@objc dynamic func f4D() -> ObjCClassA { }
1818
}
1919

2020
extension A {

trunk/test/decl/var/NSManaged_properties.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class SwiftGizmo : A {
3838

3939
// expected-error@+1{{property cannot be marked @NSManaged because its type cannot be represented in Objective-C}}
4040
@NSManaged var nonobjc_var: SwiftProto?
41-
// expected-error@-1{{'dynamic' property 'nonobjc_var' must also be '@objc'}}
4241

4342
// expected-error@+4 {{@NSManaged only allowed on an instance property or method}}
4443
// expected-error@+3 {{@NSManaged property cannot have an initial value}}

trunk/test/decl/var/property_delegates.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,26 @@ func testStorageRef(tsr: TestStorageRef) {
667667
_ = tsr.$$x // expected-error{{'$$x' is inaccessible due to 'private' protection level}}
668668
}
669669

670+
// rdar://problem/50873275 - crash when using wrapper with delegateValue in
671+
// generic type.
672+
@_propertyDelegate
673+
struct InitialValueWrapperWithStorageRef<T> {
674+
var value: T
675+
676+
init(initialValue: T) {
677+
value = initialValue
678+
}
679+
680+
var delegateValue: Wrapper<T> {
681+
return Wrapper(value: value)
682+
}
683+
}
684+
685+
struct TestGenericStorageRef<T> {
686+
struct Inner { }
687+
@InitialValueWrapperWithStorageRef var inner: Inner = Inner()
688+
}
689+
670690
// ---------------------------------------------------------------------------
671691
// Misc. semantic issues
672692
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)