Skip to content

Commit abc9b19

Browse files
authored
Merge pull request swiftlang#26010 from DougGregor/property-wrappers-missing-wrappedvalue
[SE-0258] Check for an invalid property wrapper type definition.
2 parents 9fb6ec2 + bee789e commit abc9b19

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,9 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26032603

26042604
for (unsigned i : indices(wrappedVar->getAttachedPropertyWrappers())) {
26052605
auto wrapperInfo = wrappedVar->getAttachedPropertyWrapperTypeInfo(i);
2606+
if (!wrapperInfo)
2607+
break;
2608+
26062609
Type memberType =
26072610
cs->createTypeVariable(emptyLocator, TVO_CanBindToLValue);
26082611
cs->addValueMemberConstraint(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
@propertyWrapper
3+
public struct Wrapper<T> {
4+
public var wrappedV: T // part-way through typing wrappedValue
5+
6+
public init(initialValue: T) {
7+
self.value = initialValue
8+
}
9+
10+
public init(body: () -> T) {
11+
self.value = body()
12+
}
13+
}
14+
15+
var globalInt: Int { return 17 }
16+
17+
public struct HasWrappers {
18+
@Wrapper
19+
public var x: Int = globalInt
20+
21+
@Wrapper(body: { globalInt })
22+
public var y: Int
23+
24+
@Wrapper(body: {
25+
struct Inner {
26+
@Wrapper
27+
var x: Int = globalInt
28+
}
29+
return Inner().x + globalInt
30+
})
31+
public var z: Int
32+
33+
func backingUse() {
34+
_ = $y.value + $z.value + x + $x.value
35+
}
36+
}
37+
38+
func useMemberwiseInits(i: Int) {
39+
_ = HasWrappers(x: i)
40+
_ = HasWrappers(y: Wrapper(initialValue: i))
41+
}

0 commit comments

Comments
 (0)