Skip to content

Commit bf98b34

Browse files
committed
Unified: Add type inference test case for implicit struct constructor
1 parent 4aa361a commit bf98b34

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 |
@@ -1049,6 +1058,7 @@ inferType
10491058
| closures.swift:69:5:69:5 | _ | | {EXTERNAL LOCATION} | String |
10501059
| closures.swift:69:5:69:14 | ... = ... | | {EXTERNAL LOCATION} | String |
10511060
| closures.swift:69:9:69:14 | result | | {EXTERNAL LOCATION} | String |
1061+
| constructors.swift:1:1:20:33 | Block | | constructors.swift:12:1:16:1 | S1 |
10521062
| constructors.swift:2:12:2:12 | x | | {EXTERNAL LOCATION} | Int |
10531063
| constructors.swift:4:24:6:5 | Block | | constructors.swift:1:1:7:1 | C1 |
10541064
| constructors.swift:5:9:5:12 | self | | constructors.swift:1:1:7:1 | C1 |
@@ -1058,6 +1068,26 @@ inferType
10581068
| constructors.swift:9:11:9:14 | C1(...) | | constructors.swift:1:1:7:1 | C1 |
10591069
| constructors.swift:10:5:10:7 | c12 | | constructors.swift:1:1:7:1 | C1 |
10601070
| constructors.swift:10:11:10:19 | ... .init(...) | | constructors.swift:1:1:7:1 | C1 |
1071+
| constructors.swift:13:9:13:10 | f1 | | constructors.swift:12:11:12:11 | T |
1072+
| constructors.swift:14:9:14:10 | f2 | | {EXTERNAL LOCATION} | String |
1073+
| constructors.swift:14:22:14:30 | "default" | | {EXTERNAL LOCATION} | String |
1074+
| constructors.swift:15:9:15:10 | f3 | | {EXTERNAL LOCATION} | Function |
1075+
| constructors.swift:15:9:15:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
1076+
| constructors.swift:15:9:15:10 | f3 | Args.T0 | constructors.swift:12:11:12:11 | T |
1077+
| constructors.swift:15:9:15:10 | f3 | Return | constructors.swift:12:11:12:11 | T |
1078+
| constructors.swift:15:24:15:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1079+
| constructors.swift:18:5:18:7 | s11 | | constructors.swift:12:1:16:1 | S1 |
1080+
| constructors.swift:18:11:18:19 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1081+
| constructors.swift:18:18:18:18 | 0 | | {EXTERNAL LOCATION} | Int |
1082+
| constructors.swift:19:5:19:7 | s12 | | constructors.swift:12:1:16:1 | S1 |
1083+
| constructors.swift:19:11:19:30 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1084+
| constructors.swift:19:18:19:21 | true | | {EXTERNAL LOCATION} | Bool |
1085+
| constructors.swift:19:28:19:29 | "" | | {EXTERNAL LOCATION} | String |
1086+
| constructors.swift:20:1:20:33 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1087+
| constructors.swift:20:8:20:8 | 0 | | {EXTERNAL LOCATION} | Int |
1088+
| constructors.swift:20:15:20:16 | "" | | {EXTERNAL LOCATION} | String |
1089+
| constructors.swift:20:23:20:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1090+
| constructors.swift:20:23:20:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
10611091
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
10621092
| fields.swift:2:29:2:29 | 0 | | {EXTERNAL LOCATION} | Int |
10631093
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |

0 commit comments

Comments
 (0)