Skip to content

Commit 108a462

Browse files
authored
Merge pull request swiftlang#27320 from DougGregor/property-wrappers-subscript-multifile-sr11458
[Type checker] Validate subscript declaration before using it.
2 parents 83b34ab + 4c1fc19 commit 108a462

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

test/multifile/Inputs/sr11458.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
protocol Observed: AnyObject {
2+
}
3+
4+
struct Other<Value: Equatable> {
5+
var value: Value
6+
7+
func hello() -> String {
8+
return "Hello from \(value)"
9+
}
10+
}
11+
12+
@propertyWrapper
13+
struct Observable<Value: Equatable> {
14+
private var stored: Value
15+
16+
17+
init(wrappedValue: Value) {
18+
self.stored = wrappedValue
19+
}
20+
21+
var wrappedValue: Value {
22+
get { fatalError("called wrappedValue getter") }
23+
set { fatalError("called wrappedValue setter") }
24+
}
25+
26+
var projectedValue: Other<Value> {
27+
get { fatalError("called projectedValue getter") }
28+
set { fatalError("called projectedValue setter") }
29+
}
30+
31+
static subscript<EnclosingSelf: Observed, FinalValue>(
32+
_enclosingInstance observed: EnclosingSelf,
33+
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, FinalValue>,
34+
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
35+
) -> Value {
36+
get {
37+
fatalError("blah")
38+
}
39+
set {
40+
}
41+
}
42+
43+
static subscript<EnclosingSelf: Observed>(
44+
_enclosingInstance observed: EnclosingSelf,
45+
projected wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Other<Value>>,
46+
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
47+
) -> Other<Value> {
48+
get {
49+
fatalError("blah")
50+
}
51+
set {
52+
}
53+
}
54+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/sr11458.swift
2+
3+
// SR-11458: crash involving subscript in other file
4+
class MyOtherType<T: Equatable>: Observed {
5+
@Observable var x: T
6+
7+
init(x: T) {
8+
self.x = x
9+
}
10+
}

0 commit comments

Comments
 (0)