Skip to content

Commit 25fafc4

Browse files
authored
Merge pull request #25353 from DougGregor/property-wrappers-consistency-sr-10899
2 parents 891494e + 5e00f01 commit 25fafc4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,13 +1756,34 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
17561756
auto dc = var->getDeclContext();
17571757
Type storageInterfaceType = wrapperType;
17581758

1759-
Type storageType =
1760-
var->getDeclContext()->mapTypeIntoContext(storageInterfaceType);
1759+
Type storageType = dc->mapTypeIntoContext(storageInterfaceType);
17611760
if (!storageType) {
17621761
storageType = ErrorType::get(ctx);
17631762
isInvalid = true;
17641763
}
17651764

1765+
// Make sure that the property type matches the value of the
1766+
// wrapper type.
1767+
if (!storageType->hasError()) {
1768+
Type expectedPropertyType =
1769+
storageType->getTypeOfMember(
1770+
dc->getParentModule(),
1771+
wrapperInfo.valueVar,
1772+
wrapperInfo.valueVar->getValueInterfaceType());
1773+
Type propertyType =
1774+
dc->mapTypeIntoContext(var->getValueInterfaceType());
1775+
if (!expectedPropertyType->hasError() &&
1776+
!propertyType->hasError() &&
1777+
!propertyType->isEqual(expectedPropertyType)) {
1778+
var->diagnose(diag::property_wrapper_incompatible_property,
1779+
propertyType, wrapperType);
1780+
if (auto nominalWrapper = wrapperType->getAnyNominal()) {
1781+
nominalWrapper->diagnose(diag::property_wrapper_declared_here,
1782+
nominalWrapper->getFullName());
1783+
}
1784+
}
1785+
}
1786+
17661787
// Create the backing storage property and note it in the cache.
17671788
VarDecl *backingVar = new (ctx) VarDecl(/*IsStatic=*/var->isStatic(),
17681789
VarDecl::Specifier::Var,

test/decl/var/property_wrappers.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,13 @@ struct UsesWrapperRequiringP {
758758
// expected-error@-2{{expected declaration}}
759759
// expected-error@-3{{type annotation missing in pattern}}
760760
}
761+
762+
// SR-10899 / rdar://problem/51588022
763+
@_propertyWrapper
764+
struct SR_10899_Wrapper { // expected-note{{property wrapper type 'SR_10899_Wrapper' declared here}}
765+
var value: String { "hi" }
766+
}
767+
768+
struct SR_10899_Usage {
769+
@SR_10899_Wrapper var thing: Bool // expected-error{{property type 'Bool' does not match that of the 'value' property of its wrapper type 'SR_10899_Wrapper'}}
770+
}

0 commit comments

Comments
 (0)