Skip to content

Commit 7dffff7

Browse files
committed
[Property Wrappers] Let PropertyWrapperBackingPropertyTypeRequest
handle all errors with a property wrapper backing type.
1 parent f555bfe commit 7dffff7

File tree

4 files changed

+5
-30
lines changed

4 files changed

+5
-30
lines changed

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,10 +4171,6 @@ bool ConstraintSystem::generateConstraints(
41714171

41724172
case SolutionApplicationTarget::Kind::uninitializedWrappedVar: {
41734173
auto *wrappedVar = target.getAsUninitializedWrappedVar();
4174-
Type propertyType = wrappedVar->getType();
4175-
if (propertyType->hasError())
4176-
return true;
4177-
41784174
auto *outermostWrapper = wrappedVar->getAttachedPropertyWrappers().front();
41794175
auto *typeRepr = outermostWrapper->getTypeRepr();
41804176
auto backingType = openUnboundGenericTypes(outermostWrapper->getType(),
@@ -4183,6 +4179,9 @@ bool ConstraintSystem::generateConstraints(
41834179

41844180
auto wrappedValueType =
41854181
generateWrappedPropertyTypeConstraints(*this, backingType, wrappedVar);
4182+
Type propertyType = wrappedVar->getType();
4183+
if (!wrappedValueType || propertyType->hasError())
4184+
return true;
41864185

41874186
addConstraint(ConstraintKind::Equal, propertyType, wrappedValueType,
41884187
getConstraintLocator(wrappedVar, LocatorPathElt::ContextualType()));

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,6 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
577577
if (!rawType || rawType->hasError())
578578
return Type();
579579

580-
if (!rawType->hasUnboundGenericType())
581-
return rawType->mapTypeOutOfContext();
582-
583580
auto binding = var->getParentPatternBinding();
584581
if (!binding)
585582
return Type();

lib/Sema/TypeCheckStorage.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,27 +2605,6 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
26052605
Type storageInterfaceType = wrapperType;
26062606
Type storageType = dc->mapTypeIntoContext(storageInterfaceType);
26072607

2608-
// Make sure that the property type matches the value of the
2609-
// wrapper type.
2610-
if (!storageInterfaceType->hasError()) {
2611-
Type expectedPropertyType =
2612-
computeWrappedValueType(var, storageInterfaceType);
2613-
Type propertyType = var->getValueInterfaceType();
2614-
assert(propertyType);
2615-
if (!expectedPropertyType->hasError() &&
2616-
!propertyType->hasError() &&
2617-
!propertyType->isEqual(expectedPropertyType)) {
2618-
var->diagnose(diag::property_wrapper_incompatible_property,
2619-
propertyType, wrapperType);
2620-
var->setInvalid();
2621-
if (auto nominalWrapper = wrapperType->getAnyNominal()) {
2622-
nominalWrapper->diagnose(diag::property_wrapper_declared_here,
2623-
nominalWrapper->getName());
2624-
}
2625-
return PropertyWrapperBackingPropertyInfo();
2626-
}
2627-
}
2628-
26292608
// Create the backing storage property and note it in the cache.
26302609
VarDecl *backingVar = new (ctx) VarDecl(/*IsStatic=*/var->isStatic(),
26312610
VarDecl::Introducer::Var,

test/decl/var/property_wrappers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,12 @@ struct UsesWrapperRequiringP {
958958

959959
// SR-10899 / rdar://problem/51588022
960960
@propertyWrapper
961-
struct SR_10899_Wrapper { // expected-note{{property wrapper type 'SR_10899_Wrapper' declared here}}
961+
struct SR_10899_Wrapper {
962962
var wrappedValue: String { "hi" }
963963
}
964964

965965
struct SR_10899_Usage {
966-
@SR_10899_Wrapper var thing: Bool // expected-error{{property type 'Bool' does not match that of the 'wrappedValue' property of its wrapper type 'SR_10899_Wrapper'}}
966+
@SR_10899_Wrapper var thing: Bool // expected-error{{property type 'Bool' does not match 'wrappedValue' type 'String'}}
967967
}
968968

969969
// SR-11061 / rdar://problem/52593304 assertion with DeclContext mismatches

0 commit comments

Comments
 (0)