Skip to content

Commit 347c87b

Browse files
committed
[Property Wrappers] Improve Error Message to include var wrappedValue:
<#Value#>" fix when declaring a new property wrapper Fixes rdar://65045235
1 parent 9f71ee1 commit 347c87b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
5454
switch (vars.size()) {
5555
case 0:
5656
if (!allowMissing) {
57+
std::string fixIt = "var wrappedValue: <#Value#>";
58+
auto fixitLocation = nominal->getBraces().Start;
5759
nominal->diagnose(diag::property_wrapper_no_value_property,
58-
nominal->getDeclaredType(), name);
60+
nominal->getDeclaredType(), name)
61+
.fixItInsertAfter(fixitLocation, fixIt);
5962
}
63+
6064
return nullptr;
6165

6266
case 1:

test/decl/var/property_wrappers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ struct WrapperAcceptingAutoclosure<T> {
5858

5959
@propertyWrapper
6060
struct MissingValue<T> { }
61-
// expected-error@-1{{property wrapper type 'MissingValue' does not contain a non-static property named 'wrappedValue'}} {{educational-notes=property-wrapper-requirements}}
61+
// expected-error@-1{{property wrapper type 'MissingValue' does not contain a non-static property named 'wrappedValue'}} {{educational-notes=property-wrapper-requirements}}{{25-25=var wrappedValue: <#Value#>}}
6262

6363
@propertyWrapper
6464
struct StaticValue {
6565
static var wrappedValue: Int = 17
6666
}
67-
// expected-error@-3{{property wrapper type 'StaticValue' does not contain a non-static property named 'wrappedValue'}}
67+
// expected-error@-3{{property wrapper type 'StaticValue' does not contain a non-static property named 'wrappedValue'}}{{20-20=var wrappedValue: <#Value#>}}
6868

6969

7070
// expected-error@+1{{'@propertyWrapper' attribute cannot be applied to this declaration}}

0 commit comments

Comments
 (0)