Skip to content

Commit fdeeec8

Browse files
committed
Unified: Add more type inference tests for constructors
1 parent f4659c7 commit fdeeec8

2 files changed

Lines changed: 142 additions & 41 deletions

File tree

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,53 @@ class C1 {
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
1111

12+
class C2: C1 {} // inherits `init`
13+
14+
var c21 = C2() // $ type=c21:C2 $ MISSING: target=C1.init_conv $ SPURIOUS: target=C2.init
15+
var c22 = C2.init() // $ target=C1.init_conv $ MISSING: type=c22:C2 $ SPURIOUS: target=C1.init
16+
17+
class C3 {
18+
init() {}
19+
}
20+
21+
var c3 = C3() // $ type=c3:C3 target=C3.init
22+
23+
class C4: C3 {
24+
init(_ x: Int) {
25+
super.init() // $ target=C3.init
26+
}
27+
28+
override convenience init() {
29+
self.init(0) // $ target=C4.init
30+
}
31+
}
32+
33+
class C5: C4 {} // inherits `init` and `convenience init`
34+
35+
var c51 = C5() // $ type=c51:C5 $ MISSING: target=C4.init $ SPURIOUS: target=C5.init
36+
var c52 = C5(0) // $ type=c52:C5 $ MISSING: target=C4.init $ SPURIOUS: target=C5.init
37+
38+
class C6<T1, T2> {
39+
init(x: T1, y: T2) {}
40+
41+
private init(s: String) {}
42+
43+
convenience init(x: T1) {
44+
fatalError("Convenience initializer not implemented")
45+
}
46+
}
47+
48+
class C7<T3, T4>: C6<T4, T3> {} // inherits `init(x: T4, y: T3)` and `convenience init(x: T4)`
49+
50+
var c71 = C7(x: "string", y: true) // $ MISSING: type=c71@C7<T3>:Bool type=c71@C7<T4>:String target=C6.init $ SPURIOUS: target=C7.init
51+
var c72 = C7<Bool, _>(x: 0) // $ type=c72@C7<T3>:Bool $ MISSING: type=c72@C7<T4>:Int target=C6.init $ SPURIOUS: target=C7.init
52+
53+
class C8: C7<Int, String> { // inherits `init(x: String, y: Int)`
54+
convenience init(x: String) { // name=C8.init_conv
55+
self.init(x: x, y: 0) // $ target=C6.init $ SPURIOUS: target=C8.init_conv
56+
}
57+
}
58+
1259
struct S1<T> { // implicit `init(f1: T, f2: String = "default", f3: (T) -> T = { $0 })`
1360
var f1: T
1461
var f2: String = "default"

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

Lines changed: 95 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,24 @@ 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 |
132+
| constructors.swift:24:12:24:12 | x | | {EXTERNAL LOCATION} | Int |
133+
| constructors.swift:29:9:29:12 | self | | constructors.swift:23:1:31:1 | C4 |
134+
| constructors.swift:39:10:39:10 | x | | constructors.swift:38:10:38:11 | T1 |
135+
| constructors.swift:39:17:39:17 | y | | constructors.swift:38:14:38:15 | T2 |
136+
| constructors.swift:41:18:41:18 | s | | {EXTERNAL LOCATION} | String |
137+
| constructors.swift:43:22:43:22 | x | | constructors.swift:38:10:38:11 | T1 |
138+
| constructors.swift:54:22:54:22 | x | | {EXTERNAL LOCATION} | String |
139+
| constructors.swift:55:9:55:12 | self | | constructors.swift:53:1:57:1 | C8 |
140+
| constructors.swift:55:22:55:22 | x | | {EXTERNAL LOCATION} | String |
141+
| constructors.swift:60:9:60:10 | f1 | | constructors.swift:59:11:59:11 | T |
142+
| constructors.swift:61:9:61:10 | f2 | | {EXTERNAL LOCATION} | String |
143+
| constructors.swift:62:9:62:10 | f3 | | {EXTERNAL LOCATION} | Function |
144+
| constructors.swift:62:9:62:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
145+
| constructors.swift:62:9:62:10 | f3 | Args.T0 | constructors.swift:59:11:59:11 | T |
146+
| constructors.swift:62:9:62:10 | f3 | Return | constructors.swift:59:11:59:11 | T |
147+
| constructors.swift:62:24:62:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
148+
| constructors.swift:67:23:67:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
149+
| constructors.swift:67:23:67:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
141150
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
142151
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |
143152
| fields.swift:7:7:7:18 | genericField | | fields.swift:5:22:5:22 | T |
@@ -1093,8 +1102,8 @@ inferType
10931102
| closures.swift:69:5:69:5 | _ | | {EXTERNAL LOCATION} | String |
10941103
| closures.swift:69:5:69:14 | ... = ... | | {EXTERNAL LOCATION} | String |
10951104
| 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 |
1097-
| constructors.swift:1:1:20:33 | Block | T | {EXTERNAL LOCATION} | Int |
1105+
| constructors.swift:1:1:67:33 | Block | | constructors.swift:59:1:63:1 | S1 |
1106+
| constructors.swift:1:1:67:33 | Block | T | {EXTERNAL LOCATION} | Int |
10981107
| constructors.swift:2:12:2:12 | x | | {EXTERNAL LOCATION} | Int |
10991108
| constructors.swift:4:24:6:5 | Block | | constructors.swift:1:1:7:1 | C1 |
11001109
| constructors.swift:5:9:5:12 | self | | constructors.swift:1:1:7:1 | C1 |
@@ -1104,36 +1113,81 @@ inferType
11041113
| constructors.swift:9:11:9:14 | C1(...) | | constructors.swift:1:1:7:1 | C1 |
11051114
| constructors.swift:10:5:10:7 | c12 | | constructors.swift:1:1:7:1 | C1 |
11061115
| constructors.swift:10:11:10:19 | ... .init(...) | | constructors.swift:1:1:7:1 | C1 |
1107-
| constructors.swift:13:9:13:10 | f1 | | constructors.swift:12:11:12:11 | T |
1108-
| constructors.swift:14:9:14:10 | f2 | | {EXTERNAL LOCATION} | String |
1109-
| constructors.swift:14:22:14:30 | "default" | | {EXTERNAL LOCATION} | String |
1110-
| constructors.swift:15:9:15:10 | f3 | | {EXTERNAL LOCATION} | Function |
1111-
| constructors.swift:15:9:15:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
1112-
| constructors.swift:15:9:15:10 | f3 | Args.T0 | constructors.swift:12:11:12:11 | T |
1113-
| constructors.swift:15:9:15:10 | f3 | Return | constructors.swift:12:11:12:11 | T |
1114-
| constructors.swift:15:24:15:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1115-
| constructors.swift:18:5:18:7 | s11 | | constructors.swift:12:1:16:1 | S1 |
1116-
| constructors.swift:18:5:18:7 | s11 | T | {EXTERNAL LOCATION} | Int |
1117-
| constructors.swift:18:11:18:19 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1118-
| constructors.swift:18:11:18:19 | S1(...) | T | {EXTERNAL LOCATION} | Int |
1119-
| constructors.swift:18:18:18:18 | 0 | | {EXTERNAL LOCATION} | Int |
1120-
| constructors.swift:19:5:19:7 | s12 | | constructors.swift:12:1:16:1 | S1 |
1121-
| constructors.swift:19:5:19:7 | s12 | T | {EXTERNAL LOCATION} | Bool |
1122-
| constructors.swift:19:11:19:30 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1123-
| constructors.swift:19:11:19:30 | S1(...) | T | {EXTERNAL LOCATION} | Bool |
1124-
| constructors.swift:19:18:19:21 | true | | {EXTERNAL LOCATION} | Bool |
1125-
| constructors.swift:19:28:19:29 | "" | | {EXTERNAL LOCATION} | String |
1126-
| constructors.swift:20:1:20:33 | S1(...) | | constructors.swift:12:1:16:1 | S1 |
1127-
| constructors.swift:20:1:20:33 | S1(...) | T | {EXTERNAL LOCATION} | Int |
1128-
| constructors.swift:20:8:20:8 | 0 | | {EXTERNAL LOCATION} | Int |
1129-
| constructors.swift:20:15:20:16 | "" | | {EXTERNAL LOCATION} | String |
1130-
| constructors.swift:20:23:20:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1131-
| constructors.swift:20:23:20:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
1132-
| constructors.swift:20:23:20:32 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int |
1133-
| constructors.swift:20:23:20:32 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int |
1134-
| constructors.swift:20:25:20:25 | x | | {EXTERNAL LOCATION} | Int |
1135-
| constructors.swift:20:30:20:30 | Block | | {EXTERNAL LOCATION} | Int |
1136-
| constructors.swift:20:30:20:30 | x | | {EXTERNAL LOCATION} | Int |
1116+
| constructors.swift:14:5:14:7 | c21 | | constructors.swift:12:1:12:15 | C2 |
1117+
| constructors.swift:14:11:14:14 | C2(...) | | constructors.swift:12:1:12:15 | C2 |
1118+
| constructors.swift:15:5:15:7 | c22 | | constructors.swift:1:1:7:1 | C1 |
1119+
| constructors.swift:15:11:15:19 | ... .init(...) | | constructors.swift:1:1:7:1 | C1 |
1120+
| constructors.swift:21:5:21:6 | c3 | | constructors.swift:17:1:19:1 | C3 |
1121+
| constructors.swift:21:10:21:13 | C3(...) | | constructors.swift:17:1:19:1 | C3 |
1122+
| constructors.swift:24:12:24:12 | x | | {EXTERNAL LOCATION} | Int |
1123+
| constructors.swift:24:20:26:5 | Block | | constructors.swift:17:1:19:1 | C3 |
1124+
| constructors.swift:25:9:25:13 | super | | constructors.swift:17:1:19:1 | C3 |
1125+
| constructors.swift:25:9:25:20 | ... .init(...) | | constructors.swift:17:1:19:1 | C3 |
1126+
| constructors.swift:28:33:30:5 | Block | | constructors.swift:23:1:31:1 | C4 |
1127+
| constructors.swift:29:9:29:12 | self | | constructors.swift:23:1:31:1 | C4 |
1128+
| constructors.swift:29:9:29:20 | ... .init(...) | | constructors.swift:23:1:31:1 | C4 |
1129+
| constructors.swift:29:19:29:19 | 0 | | {EXTERNAL LOCATION} | Int |
1130+
| constructors.swift:35:5:35:7 | c51 | | constructors.swift:33:1:33:15 | C5 |
1131+
| constructors.swift:35:11:35:14 | C5(...) | | constructors.swift:33:1:33:15 | C5 |
1132+
| constructors.swift:36:5:36:7 | c52 | | constructors.swift:33:1:33:15 | C5 |
1133+
| constructors.swift:36:11:36:15 | C5(...) | | constructors.swift:33:1:33:15 | C5 |
1134+
| constructors.swift:36:14:36:14 | 0 | | {EXTERNAL LOCATION} | Int |
1135+
| constructors.swift:39:10:39:10 | x | | constructors.swift:38:10:38:11 | T1 |
1136+
| constructors.swift:39:17:39:17 | y | | constructors.swift:38:14:38:15 | T2 |
1137+
| constructors.swift:41:18:41:18 | s | | {EXTERNAL LOCATION} | String |
1138+
| constructors.swift:43:22:43:22 | x | | constructors.swift:38:10:38:11 | T1 |
1139+
| constructors.swift:44:20:44:60 | "Convenience initializer not implemented" | | {EXTERNAL LOCATION} | String |
1140+
| constructors.swift:50:5:50:7 | c71 | | constructors.swift:48:1:48:31 | C7 |
1141+
| constructors.swift:50:11:50:34 | C7(...) | | constructors.swift:48:1:48:31 | C7 |
1142+
| constructors.swift:50:17:50:24 | "string" | | {EXTERNAL LOCATION} | String |
1143+
| constructors.swift:50:30:50:33 | true | | {EXTERNAL LOCATION} | Bool |
1144+
| constructors.swift:51:5:51:7 | c72 | | constructors.swift:48:1:48:31 | C7 |
1145+
| constructors.swift:51:5:51:7 | c72 | T3 | {EXTERNAL LOCATION} | Bool |
1146+
| constructors.swift:51:11:51:27 | ...(...) | | constructors.swift:48:1:48:31 | C7 |
1147+
| constructors.swift:51:11:51:27 | ...(...) | T3 | {EXTERNAL LOCATION} | Bool |
1148+
| constructors.swift:51:26:51:26 | 0 | | {EXTERNAL LOCATION} | Int |
1149+
| constructors.swift:54:22:54:22 | x | | {EXTERNAL LOCATION} | String |
1150+
| constructors.swift:54:33:56:5 | Block | | constructors.swift:38:1:46:1 | C6 |
1151+
| constructors.swift:54:33:56:5 | Block | | constructors.swift:53:1:57:1 | C8 |
1152+
| constructors.swift:54:33:56:5 | Block | T1 | {EXTERNAL LOCATION} | String |
1153+
| constructors.swift:54:33:56:5 | Block | T2 | {EXTERNAL LOCATION} | Int |
1154+
| constructors.swift:55:9:55:12 | self | | constructors.swift:53:1:57:1 | C8 |
1155+
| constructors.swift:55:9:55:29 | ... .init(...) | | constructors.swift:38:1:46:1 | C6 |
1156+
| constructors.swift:55:9:55:29 | ... .init(...) | | constructors.swift:53:1:57:1 | C8 |
1157+
| constructors.swift:55:9:55:29 | ... .init(...) | T1 | {EXTERNAL LOCATION} | String |
1158+
| constructors.swift:55:9:55:29 | ... .init(...) | T2 | {EXTERNAL LOCATION} | Int |
1159+
| constructors.swift:55:22:55:22 | x | | {EXTERNAL LOCATION} | String |
1160+
| constructors.swift:55:28:55:28 | 0 | | {EXTERNAL LOCATION} | Int |
1161+
| constructors.swift:60:9:60:10 | f1 | | constructors.swift:59:11:59:11 | T |
1162+
| constructors.swift:61:9:61:10 | f2 | | {EXTERNAL LOCATION} | String |
1163+
| constructors.swift:61:22:61:30 | "default" | | {EXTERNAL LOCATION} | String |
1164+
| constructors.swift:62:9:62:10 | f3 | | {EXTERNAL LOCATION} | Function |
1165+
| constructors.swift:62:9:62:10 | f3 | Args | {EXTERNAL LOCATION} | Tuple1 |
1166+
| constructors.swift:62:9:62:10 | f3 | Args.T0 | constructors.swift:59:11:59:11 | T |
1167+
| constructors.swift:62:9:62:10 | f3 | Return | constructors.swift:59:11:59:11 | T |
1168+
| constructors.swift:62:24:62:29 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1169+
| constructors.swift:65:5:65:7 | s11 | | constructors.swift:59:1:63:1 | S1 |
1170+
| constructors.swift:65:5:65:7 | s11 | T | {EXTERNAL LOCATION} | Int |
1171+
| constructors.swift:65:11:65:19 | S1(...) | | constructors.swift:59:1:63:1 | S1 |
1172+
| constructors.swift:65:11:65:19 | S1(...) | T | {EXTERNAL LOCATION} | Int |
1173+
| constructors.swift:65:18:65:18 | 0 | | {EXTERNAL LOCATION} | Int |
1174+
| constructors.swift:66:5:66:7 | s12 | | constructors.swift:59:1:63:1 | S1 |
1175+
| constructors.swift:66:5:66:7 | s12 | T | {EXTERNAL LOCATION} | Bool |
1176+
| constructors.swift:66:11:66:30 | S1(...) | | constructors.swift:59:1:63:1 | S1 |
1177+
| constructors.swift:66:11:66:30 | S1(...) | T | {EXTERNAL LOCATION} | Bool |
1178+
| constructors.swift:66:18:66:21 | true | | {EXTERNAL LOCATION} | Bool |
1179+
| constructors.swift:66:28:66:29 | "" | | {EXTERNAL LOCATION} | String |
1180+
| constructors.swift:67:1:67:33 | S1(...) | | constructors.swift:59:1:63:1 | S1 |
1181+
| constructors.swift:67:1:67:33 | S1(...) | T | {EXTERNAL LOCATION} | Int |
1182+
| constructors.swift:67:8:67:8 | 0 | | {EXTERNAL LOCATION} | Int |
1183+
| constructors.swift:67:15:67:16 | "" | | {EXTERNAL LOCATION} | String |
1184+
| constructors.swift:67:23:67:32 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
1185+
| constructors.swift:67:23:67:32 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
1186+
| constructors.swift:67:23:67:32 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int |
1187+
| constructors.swift:67:23:67:32 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int |
1188+
| constructors.swift:67:25:67:25 | x | | {EXTERNAL LOCATION} | Int |
1189+
| constructors.swift:67:30:67:30 | Block | | {EXTERNAL LOCATION} | Int |
1190+
| constructors.swift:67:30:67:30 | x | | {EXTERNAL LOCATION} | Int |
11371191
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
11381192
| fields.swift:2:29:2:29 | 0 | | {EXTERNAL LOCATION} | Int |
11391193
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |

0 commit comments

Comments
 (0)