Skip to content

Commit 9f0bc69

Browse files
committed
[Type checker] Classes don't need backing properties to create their implicit constructors
Fixes a crash caused by an undiagnosed cycle, rdar://problem/52679284.
1 parent bd9b18e commit 9f0bc69

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5313,7 +5313,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53135313
}
53145314

53155315
} else {
5316-
SmallPtrSet<VarDecl *, 4> backingStorageVars;
53175316
for (auto member : decl->getMembers()) {
53185317
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
53195318
// Initializers that were synthesized to fulfill derived conformances
@@ -5336,17 +5335,9 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53365335
}
53375336

53385337
if (auto var = dyn_cast<VarDecl>(member)) {
5339-
// If this variable has a property wrapper, go validate it to ensure
5340-
// that we create the backing storage property.
5341-
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
5342-
validateDecl(var);
5343-
maybeAddAccessorsToStorage(var);
5344-
5345-
backingStorageVars.insert(backingVar);
5346-
}
5347-
5348-
// Ignore the backing storage for properties with attached wrappers.
5349-
if (backingStorageVars.count(var) > 0)
5338+
// If this is a backing storage property for a property wrapper,
5339+
// skip it.
5340+
if (var->getOriginalWrappedProperty())
53505341
continue;
53515342

53525343
if (var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true)) {
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)