Skip to content

Commit 8c476c2

Browse files
authored
Merge pull request #26239 from DougGregor/property-wrappers-rdar52679284
2 parents ab995ec + 10680e4 commit 8c476c2

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24412441
(void) VD->isGetterMutating();
24422442
(void) VD->isSetterMutating();
24432443

2444+
// Retrieve the backing property of a wrapped property.
2445+
(void) VD->getPropertyWrapperBackingProperty();
2446+
24442447
// Set up accessors, also lowering lazy and @NSManaged properties.
24452448
maybeAddAccessorsToStorage(VD);
24462449

@@ -5341,7 +5344,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53415344
}
53425345

53435346
} else {
5344-
SmallPtrSet<VarDecl *, 4> backingStorageVars;
53455347
for (auto member : decl->getMembers()) {
53465348
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
53475349
// Initializers that were synthesized to fulfill derived conformances
@@ -5364,17 +5366,9 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53645366
}
53655367

53665368
if (auto var = dyn_cast<VarDecl>(member)) {
5367-
// If this variable has a property wrapper, go validate it to ensure
5368-
// that we create the backing storage property.
5369-
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
5370-
validateDecl(var);
5371-
maybeAddAccessorsToStorage(var);
5372-
5373-
backingStorageVars.insert(backingVar);
5374-
}
5375-
5376-
// Ignore the backing storage for properties with attached wrappers.
5377-
if (backingStorageVars.count(var) > 0)
5369+
// If this is a backing storage property for a property wrapper,
5370+
// skip it.
5371+
if (var->getOriginalWrappedProperty())
53785372
continue;
53795373

53805374
if (var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true)) {

test/decl/protocol/conforms/redundant_conformance.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,24 @@ extension OtherGenericConditionalConformsToP: P1 {
6565
typealias A = Double
6666
func f() -> Double { return 0.0 }
6767
}
68+
69+
// FB6114209: spurious ambiguity errors
70+
protocol MyUsefulProtocol {
71+
var someInt: Int { get }
72+
}
73+
74+
class Class1 {
75+
typealias ProviderOne = MyUsefulProtocol
76+
}
77+
78+
class Class2 {
79+
typealias ProviderTwo = MyUsefulProtocol
80+
}
81+
82+
class Class3 {
83+
typealias ProviderThree = Class1.ProviderOne & Class2.ProviderTwo
84+
}
85+
86+
class SomeMockClass: Class3.ProviderThree { // okay
87+
var someInt: Int = 5
88+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -typecheck %s -verify
2+
3+
public protocol MyBindableObject {}
4+
5+
@propertyWrapper
6+
public struct MyBinding<T> where T : MyBindableObject { // expected-error{{internal initializer 'init(wrappedValue:)' cannot have more restrictive access than its enclosing property wrapper type 'MyBinding' (which is public)}}
7+
public var wrappedValue: T
8+
}
9+
class BeaconDetector: MyBindableObject {
10+
@MyBinding var detector = BeaconDetector()
11+
init() {
12+
detector.undefined = 45 // expected-error{{value of type 'BeaconDetector' has no member 'undefined'}}
13+
}
14+
}

0 commit comments

Comments
 (0)