Skip to content

Commit b3d54b6

Browse files
committed
[Property Wrappers] Don't allow parameters with attached property wrappers
in protocol requirements.
1 parent b7a170c commit b3d54b6

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,9 +5524,9 @@ ERROR(property_with_wrapper_conflict_attribute,none,
55245524
ERROR(property_wrapper_not_single_var, none,
55255525
"property wrapper can only apply to a single variable", ())
55265526
ERROR(property_with_wrapper_in_bad_context,none,
5527-
"%select{|non-static |non-static }1property %0 declared inside "
5527+
"%select{|non-static|non-static}1 %2 %0 declared inside "
55285528
"%select{a protocol|an extension|an enum}1 cannot have a wrapper",
5529-
(Identifier, int))
5529+
(Identifier, int, DescriptiveDeclKind))
55305530
ERROR(property_with_wrapper_overrides,none,
55315531
"property %0 with attached wrapper cannot override another property",
55325532
(Identifier))

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ AttachedPropertyWrappersRequest::evaluate(Evaluator &evaluator,
455455
continue;
456456
}
457457

458+
if (isa<ParamDecl>(var) && isa<AbstractFunctionDecl>(dc)) {
459+
dc = dc->getAsDecl()->getDeclContext();
460+
}
461+
458462
// A property with a wrapper cannot be declared in a protocol, enum, or
459463
// an extension.
460464
if (isa<ProtocolDecl>(dc) ||
@@ -468,7 +472,7 @@ AttachedPropertyWrappersRequest::evaluate(Evaluator &evaluator,
468472
else
469473
whichKind = 2;
470474
var->diagnose(diag::property_with_wrapper_in_bad_context,
471-
var->getName(), whichKind)
475+
var->getName(), whichKind, var->getDescriptiveKind())
472476
.highlight(attr->getRange());
473477

474478
continue;

test/Sema/property_wrapper_parameter_invalid.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ func testInvalidArgLabel() {
8383
// expected-error@+1 {{cannot use property wrapper projection argument; parameter does not have an attached property wrapper}}
8484
noWrappers($argLabel: 10)
8585
}
86+
87+
protocol P {
88+
// expected-error@+1 {{parameter 'arg' declared inside a protocol cannot have a wrapper}}
89+
func requirement(@Wrapper arg: Int)
90+
}

0 commit comments

Comments
 (0)