Skip to content

[Type checker] Classes don't need backing properties to create their implicit constructors #26239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(void) VD->isGetterMutating();
(void) VD->isSetterMutating();

// Retrieve the backing property of a wrapped property.
(void) VD->getPropertyWrapperBackingProperty();

// Set up accessors, also lowering lazy and @NSManaged properties.
maybeAddAccessorsToStorage(VD);

Expand Down Expand Up @@ -5313,7 +5316,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
}

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

if (auto var = dyn_cast<VarDecl>(member)) {
// If this variable has a property wrapper, go validate it to ensure
// that we create the backing storage property.
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
validateDecl(var);
maybeAddAccessorsToStorage(var);

backingStorageVars.insert(backingVar);
}

// Ignore the backing storage for properties with attached wrappers.
if (backingStorageVars.count(var) > 0)
// If this is a backing storage property for a property wrapper,
// skip it.
if (var->getOriginalWrappedProperty())
continue;

if (var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true)) {
Expand Down
21 changes: 21 additions & 0 deletions test/decl/protocol/conforms/redundant_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,24 @@ extension OtherGenericConditionalConformsToP: P1 {
typealias A = Double
func f() -> Double { return 0.0 }
}

// FB6114209: spurious ambiguity errors
protocol MyUsefulProtocol {
var someInt: Int { get }
}

class Class1 {
typealias ProviderOne = MyUsefulProtocol
}

class Class2 {
typealias ProviderTwo = MyUsefulProtocol
}

class Class3 {
typealias ProviderThree = Class1.ProviderOne & Class2.ProviderTwo
}

class SomeMockClass: Class3.ProviderThree { // okay
var someInt: Int = 5
}
14 changes: 14 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0199-rdar52679284.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %target-swift-frontend -typecheck %s -verify

public protocol MyBindableObject {}

@propertyWrapper
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)}}
public var wrappedValue: T
}
class BeaconDetector: MyBindableObject {
@MyBinding var detector = BeaconDetector()
init() {
detector.undefined = 45 // expected-error{{value of type 'BeaconDetector' has no member 'undefined'}}
}
}