Skip to content

Commit ff7dd73

Browse files
committed
Unified: Add type inference test case for implicit struct constructor
1 parent eae42e6 commit ff7dd73

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎unified/ql/test/library-tests/type-inference/constructors.swift‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ class C1 {
88

99
var c11 = C1() // $ type=c11:C1 target=C1.init_conv $ SPURIOUS: target=C1.init
1010
var c12 = C1.init() // $ type=c12:C1 target=C1.init_conv $ SPURIOUS: target=C1.init
11+
12+
struct S1<T> { // implicit `init(f1: T, f2: String = "default", f3: (T) -> T = { $0 })`
13+
var f1: T
14+
var f2: String = "default"
15+
var f3: (T) -> T = { $0 }
16+
}
17+
18+
var s11 = S1(f1: 0) // $ target=S1.init $ MISSING: type=s11@S1<T>:Int
19+
var s12 = S1(f1: true, f2: "") // $ target=S1.init $ MISSING: type=s12@S1<T>:Bool
20+
S1(f1: 0, f2: "", f3: { x in x }) // $ target=S1.init $ MISSING:type=x:Int

‎unified/ql/test/library-tests/type-inference/type-inference.expected‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ inferCertainType
129129
| closures.swift:66:9:68:9 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
130130
| constructors.swift:2:12:2:12 | x | | {EXTERNAL LOCATION} | Int |
131131
| constructors.swift:5:9:5:12 | self | | constructors.swift:1:1:7:1 | C1 |
132+
| constructors.swift:13:9:13:10 | f1 | | constructors.swift:12:11:12:11 | T |
133+
| constructors.swift:14:9:14:10 | f2 | | {EXTERNAL LOCATION} | String |
134+
| constructors.swift:15:9:15:10 | f3 | | {EXTERNAL LOCATION} | Function |
135+
| constructors.swift:15:9:15:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
136+
| constructors.swift:15:9:15:10 | f3 | Args.T0 | constructors.swift:12:11:12:11 | T |
137+
| constructors.swift:15:9:15:10 | f3 | Return | constructors.swift:12:11:12:11 | T |
138+
| constructors.swift:15:24:15:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
139+
| constructors.swift:20:23:20:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
140+
| constructors.swift:20:23:20:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
132141
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
133142
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |
134143
| fields.swift:7:7:7:18 | genericField | | fields.swift:5:22:5:22 | T |
@@ -1084,6 +1093,7 @@ inferType
10841093
| closures.swift:69:5:69:5 | _ | | {EXTERNAL LOCATION} | String |
10851094
| closures.swift:69:5:69:14 | ... = ... | | {EXTERNAL LOCATION} | String |
10861095
| closures.swift:69:9:69:14 | result | | {EXTERNAL LOCATION} | String |
1096+
| constructors.swift:1:1:20:33 | Block | | constructors.swift:12:1:16:1 | S1 |
10871097
| constructors.swift:2:12:2:12 | x | | {EXTERNAL LOCATION} | Int |
10881098
| constructors.swift:4:24:6:5 | Block | | constructors.swift:1:1:7:1 | C1 |
10891099
| constructors.swift:5:9:5:12 | self | | constructors.swift:1:1:7:1 | C1 |
@@ -1093,6 +1103,26 @@ inferType
10931103
| constructors.swift:9:11:9:14 | C1(...) | | constructors.swift:1:1:7:1 | C1 |
10941104
| constructors.swift:10:5:10:7 | c12 | | constructors.swift:1:1:7:1 | C1 |
10951105
| constructors.swift:10:11:10:19 | ... .init(...) | | constructors.swift:1:1:7:1 | C1 |
1106+
| constructors.swift:13:9:13:10 | f1 | | constructors.swift:12:11:12:11 | T |
1107+
| constructors.swift:14:9:14:10 | f2 | | {EXTERNAL LOCATION} | String |
1108+
| constructors.swift:14:22:14:30 | "default" | | {EXTERNAL LOCATION} | String |
1109+
| constructors.swift:15:9:15:10 | f3 | | {EXTERNAL LOCATION} | Function |
1110+
| constructors.swift:15:9:15:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
1111+
| constructors.swift:15:9:15:10 | f3 | Args.T0 | constructors.swift:12:11:12:11 | T |
1112+
| constructors.swift:15:9:15:10 | f3 | Return | constructors.swift:12:11:12:11 | T |
1113+
| constructors.swift:15:24:15:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1114+
| constructors.swift:18:5:18:7 | s11 | | constructors.swift:12:1:16:1 | S1 |
1115+
| constructors.swift:18:11:18:19 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1116+
| constructors.swift:18:18:18:18 | 0 | | {EXTERNAL LOCATION} | Int |
1117+
| constructors.swift:19:5:19:7 | s12 | | constructors.swift:12:1:16:1 | S1 |
1118+
| constructors.swift:19:11:19:30 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1119+
| constructors.swift:19:18:19:21 | true | | {EXTERNAL LOCATION} | Bool |
1120+
| constructors.swift:19:28:19:29 | "" | | {EXTERNAL LOCATION} | String |
1121+
| constructors.swift:20:1:20:33 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1122+
| constructors.swift:20:8:20:8 | 0 | | {EXTERNAL LOCATION} | Int |
1123+
| constructors.swift:20:15:20:16 | "" | | {EXTERNAL LOCATION} | String |
1124+
| constructors.swift:20:23:20:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1125+
| constructors.swift:20:23:20:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
10961126
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
10971127
| fields.swift:2:29:2:29 | 0 | | {EXTERNAL LOCATION} | Int |
10981128
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |

0 commit comments

Comments
 (0)