Skip to content

Commit 445148c

Browse files
committed
[Sema] TypeWrappers: Allow let properties to be managed by a type wrapper
1 parent 18dd738 commit 445148c

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,8 @@ static void finishStorageImplInfo(AbstractStorageDecl *storage,
33063306
} else if (var->hasAttachedPropertyWrapper()) {
33073307
finishPropertyWrapperImplInfo(var, info);
33083308
} else if (var->isAccessedViaTypeWrapper()) {
3309-
info = StorageImplInfo::getMutableComputed();
3309+
info = var->isLet() ? StorageImplInfo::getImmutableComputed()
3310+
: StorageImplInfo::getMutableComputed();
33103311
}
33113312
}
33123313

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ bool IsPropertyAccessedViaTypeWrapper::evaluate(Evaluator &evaluator,
325325
if (!(parent && parent->hasTypeWrapper()))
326326
return false;
327327

328-
if (property->isStatic() || property->isLet())
328+
if (property->isStatic())
329329
return false;
330330

331331
// If this property has `@typeWrapperIgnored` attribute

test/Interpreter/Inputs/type_wrapper_defs.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ public struct Wrapper<S> {
77
self.underlying = memberwise
88
}
99

10+
public subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
11+
get {
12+
print("in read-only getter")
13+
return underlying[keyPath: path]
14+
}
15+
}
16+
1017
public subscript<V>(storageKeyPath path: WritableKeyPath<S, V>) -> V {
1118
get {
1219
print("in getter")

test/Interpreter/type_wrappers.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,11 @@ testPropertyWrappers()
358358

359359
do {
360360
var person = PersonWithUnmanagedTest(name: "Arthur Dent")
361-
// CHECK: Wrapper.init($Storage(_favoredColor: type_wrapper_defs.PropWrapper<Swift.String>(value: "red")))
361+
// CHECK: Wrapper.init($Storage(name: "Arthur Dent", _favoredColor: type_wrapper_defs.PropWrapper<Swift.String>(value: "red")))
362362

363363
print(person.name)
364-
// CHECK: Arthur Dent
364+
// CHECK: in read-only getter
365+
// CHECK-NEXT: Arthur Dent
365366

366367
print(person.age)
367368
// CHECK: 30

test/type/type_wrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func testDeclarationsWithUnmanagedProperties() {
351351
}
352352

353353
_ = WithDefaultedLet(age: 32) // Ok
354-
_ = WithDefaultedLet(name: "", age: 0) // expected-error {{extra argument 'name' in call}}
354+
_ = WithDefaultedLet(name: "", age: 0) // Ok
355355

356356
@NoopWrapper
357357
struct WithLazy {

0 commit comments

Comments
 (0)