Skip to content

Commit 2c2d671

Browse files
committed
[Property Wrappers] Add an unsupported error message for property wrapper
parameters in subscript declarations.
1 parent 36008a1 commit 2c2d671

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,6 +5482,9 @@ ERROR(property_wrapper_dynamic_self_type, none,
54825482
ERROR(property_wrapper_attribute_not_on_property, none,
54835483
"property wrapper attribute %0 can only be applied to a property",
54845484
(Identifier))
5485+
ERROR(property_wrapper_param_not_supported,none,
5486+
"property wrapper attribute on parameter not yet supported on %0",
5487+
(DescriptiveDeclKind))
54855488
NOTE(property_wrapper_declared_here,none,
54865489
"property wrapper type %0 declared here", (Identifier))
54875490
ERROR(property_wrapper_param_no_projection,none,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,18 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
29952995
return;
29962996
}
29972997

2998+
if (isa<ParamDecl>(D)) {
2999+
// Check for unsupported declarations.
3000+
auto *context = D->getDeclContext()->getAsDecl();
3001+
if (context && isa<SubscriptDecl>(context)) {
3002+
diagnose(attr->getLocation(),
3003+
diag::property_wrapper_param_not_supported,
3004+
context->getDescriptiveKind());
3005+
attr->setInvalid();
3006+
return;
3007+
}
3008+
}
3009+
29983010
return;
29993011
}
30003012

test/Sema/property_wrapper_parameter_invalid.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ func testWrapperAttributeArg(projection: Projection<Int>) {
6868
// expected-error@+1 {{cannot use property wrapper projection argument; pass wrapped value type 'Int' instead}}
6969
hasWrapperAttributeArg($value: projection)
7070
}
71+
72+
struct S {
73+
// expected-error@+1 {{property wrapper attribute on parameter not yet supported on subscript}}
74+
subscript(@Wrapper position: Int) -> Int { 0 }
75+
}

0 commit comments

Comments
 (0)