Skip to content

Commit 1e0e671

Browse files
committed
[SE-0258] Warn about (but still use) 'delegateValue' in lieu of 'wrapperValue'.
Provide some backward compatibilty for property delegates written before they became property wrapper, picking up 'delegateValue' (if present) but warning about it.
1 parent c36683f commit 1e0e671

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,6 +4462,9 @@ ERROR(property_wrapper_type_not_usable_from_inline,none,
44624462
"%select{%select{variable|constant}0|property}1 "
44634463
"must be '@usableFromInline' or public",
44644464
(bool, bool))
4465+
WARNING(property_wrapper_delegateValue,none,
4466+
"property wrapper's `delegateValue` property should be renamed to "
4467+
"'wrapperValue'; use of 'delegateValue' is deprecated", ())
44654468

44664469
//------------------------------------------------------------------------------
44674470
// MARK: function builder diagnostics

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ PropertyWrapperTypeInfoRequest::evaluate(
245245
result.wrapperValueVar =
246246
findValueProperty(ctx, nominal, ctx.Id_wrapperValue, /*allowMissing=*/true);
247247

248+
// If there was no wrapperValue property, but there is a delegateValue
249+
// property, use that and warn.
250+
if (!result.wrapperValueVar) {
251+
result.wrapperValueVar =
252+
findValueProperty(ctx, nominal, ctx.Id_delegateValue,
253+
/*allowMissing=*/true);
254+
if (result.wrapperValueVar) {
255+
result.wrapperValueVar->diagnose(diag::property_wrapper_delegateValue)
256+
.fixItReplace(result.wrapperValueVar->getNameLoc(), "wrapperValue");
257+
}
258+
}
259+
248260
return result;
249261
}
250262

test/decl/var/property_wrapper_aliases.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
@propertyDelegate
66
struct Delegate<T> {
77
var value: T
8+
9+
var delegateValue: Wrapper<T> { // expected-warning{{property wrapper's `delegateValue` property should be renamed to 'wrapperValue'; use of 'delegateValue' is deprecated}}{{7-20=wrapperValue}}
10+
return Wrapper(value: value)
11+
}
12+
}
13+
14+
struct TestDelegateValue {
15+
@Delegate var foo: String
16+
17+
func test() -> Wrapper<String> {
18+
return $foo
19+
}
820
}
921

1022
@propertyWrapper

0 commit comments

Comments
 (0)