Skip to content

Commit 001c897

Browse files
paldepindCopilot
andcommitted
Unified: Add tests for conditional compilation in switch cases and members
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2ce1abc6-e036-4c6c-8479-2d0e052d4cc6
1 parent b939420 commit 001c897

4 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎unified/extractor/tests/corpus/swift/conditional-compilation/conditional-compilation-in-switch-cases.output‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ func f(_ x: Int) {
33
#if DEBUG
44
case 0: break
55
case 1: break
6+
#elseif RELEASE
7+
case 2: break
8+
#else
9+
case 3: break
610
#endif
711
default: break
812
}
@@ -72,6 +76,49 @@ sourceFile
7276
declReferenceExpr
7377
baseName: identifier "DEBUG"
7478
poundKeyword: #if
79+
ifConfigClause
80+
elements:
81+
switchCase
82+
label:
83+
switchCaseLabel
84+
colon: :
85+
caseKeyword: case
86+
caseItems:
87+
switchCaseItem
88+
pattern:
89+
expressionPattern
90+
expression:
91+
integerLiteralExpr
92+
literal: integerLiteral "2"
93+
statements:
94+
codeBlockItem
95+
item:
96+
breakStmt
97+
breakKeyword: break
98+
condition:
99+
declReferenceExpr
100+
baseName: identifier "RELEASE"
101+
poundKeyword: #elseif
102+
ifConfigClause
103+
elements:
104+
switchCase
105+
label:
106+
switchCaseLabel
107+
colon: :
108+
caseKeyword: case
109+
caseItems:
110+
switchCaseItem
111+
pattern:
112+
expressionPattern
113+
expression:
114+
integerLiteralExpr
115+
literal: integerLiteral "3"
116+
statements:
117+
codeBlockItem
118+
item:
119+
breakStmt
120+
breakKeyword: break
121+
poundKeyword: #else
75122
poundEndif: #endif
76123
switchCase
77124
label:
@@ -123,7 +170,7 @@ top_level source="⟨body⟩"
123170
body:
124171
block source="{\n ⟨stmt⟩\n}"
125172
stmt:
126-
switch_expr source="switch ⟨value⟩ {\n #if DEBUG\n ⟨case⟩\n ⟨case⟩\n #endif\n ⟨case⟩\n }"
173+
switch_expr source="switch ⟨value⟩ {\n #if DEBUG\n ⟨case⟩\n ⟨case⟩\n #elseif RELEASE\n case 2: break\n #else\n case 3: break\n #endif\n ⟨case⟩\n }"
127174
value: identifier "x" source="x"
128175
case:
129176
switch_case source="case ⟨pattern⟩: ⟨body⟩"

‎unified/extractor/tests/corpus/swift/conditional-compilation/conditional-compilation-in-switch-cases.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ func f(_ x: Int) {
33
#if DEBUG
44
case 0: break
55
case 1: break
6+
#elseif RELEASE
7+
case 2: break
8+
#else
9+
case 3: break
610
#endif
711
default: break
812
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ let e2: E2<_, String> = E2.a(1) // $ target=E2.a type=.a(...)@E2<B>:String
9191
enum E3<T> { case value(payload: T) }
9292

9393
let e2 = E3.value(payload: 1) // $ target=E3.value type=e2@E3<T>:Int
94+
95+
struct S2 {
96+
#if DEBUG
97+
var f: (Int) -> Int
98+
#else
99+
var f: (String) -> String
100+
#endif
101+
}
102+
103+
S2(f: { x in x }) // $ target=S2.init type=x:Int

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ inferCertainType
321321
| constructors.swift:89:5:89:6 | e2 | | constructors.swift:87:1:87:27 | E2 |
322322
| constructors.swift:89:5:89:6 | e2 | B | {EXTERNAL LOCATION} | String |
323323
| constructors.swift:91:25:91:31 | payload | | constructors.swift:91:9:91:9 | T |
324+
| constructors.swift:97:9:97:9 | f | | {EXTERNAL LOCATION} | Function |
325+
| constructors.swift:97:9:97:9 | f | Args | {EXTERNAL LOCATION} | Tuple1 |
326+
| constructors.swift:97:9:97:9 | f | Args.T0 | {EXTERNAL LOCATION} | Int |
327+
| constructors.swift:97:9:97:9 | f | Return | {EXTERNAL LOCATION} | Int |
328+
| constructors.swift:103:4:103:16 | Argument | | {EXTERNAL LOCATION} | Function |
329+
| constructors.swift:103:4:103:16 | Argument | Args | {EXTERNAL LOCATION} | Tuple1 |
330+
| constructors.swift:103:7:103:16 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
331+
| constructors.swift:103:7:103:16 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
324332
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
325333
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |
326334
| fields.swift:7:7:7:18 | genericField | | fields.swift:5:22:5:22 | T |
@@ -2467,6 +2475,7 @@ inferType
24672475
| conditional-compilation.swift:9:5:10:17 | Block | | {EXTERNAL LOCATION} | String |
24682476
| conditional-compilation.swift:10:7:10:6 | #base | | conditional-compilation.swift:1:1:3:1 | Postfix |
24692477
| conditional-compilation.swift:10:7:10:17 | ... .toString(...) | | {EXTERNAL LOCATION} | String |
2478+
| constructors.swift:1:1:103:17 | Block | | constructors.swift:95:1:101:1 | S2 |
24702479
| constructors.swift:2:12:2:12 | x | | {EXTERNAL LOCATION} | Int |
24712480
| constructors.swift:4:24:6:5 | Block | | constructors.swift:1:1:7:1 | C1 |
24722481
| constructors.swift:5:9:5:12 | self | | constructors.swift:1:1:7:1 | C1 |
@@ -2663,6 +2672,23 @@ inferType
26632672
| constructors.swift:93:10:93:29 | ... .value(...) | T | {EXTERNAL LOCATION} | Int |
26642673
| constructors.swift:93:19:93:28 | Argument | | {EXTERNAL LOCATION} | Int |
26652674
| constructors.swift:93:28:93:28 | 1 | | {EXTERNAL LOCATION} | Int |
2675+
| constructors.swift:97:9:97:9 | f | | {EXTERNAL LOCATION} | Function |
2676+
| constructors.swift:97:9:97:9 | f | Args | {EXTERNAL LOCATION} | Tuple1 |
2677+
| constructors.swift:97:9:97:9 | f | Args.T0 | {EXTERNAL LOCATION} | Int |
2678+
| constructors.swift:97:9:97:9 | f | Return | {EXTERNAL LOCATION} | Int |
2679+
| constructors.swift:103:1:103:2 | S2 | | constructors.swift:95:1:101:1 | S2 |
2680+
| constructors.swift:103:1:103:17 | S2(...) | | constructors.swift:95:1:101:1 | S2 |
2681+
| constructors.swift:103:4:103:16 | Argument | | {EXTERNAL LOCATION} | Function |
2682+
| constructors.swift:103:4:103:16 | Argument | Args | {EXTERNAL LOCATION} | Tuple1 |
2683+
| constructors.swift:103:4:103:16 | Argument | Args.T0 | {EXTERNAL LOCATION} | Int |
2684+
| constructors.swift:103:4:103:16 | Argument | Return | {EXTERNAL LOCATION} | Int |
2685+
| constructors.swift:103:7:103:16 | FunctionExpr | | {EXTERNAL LOCATION} | Function |
2686+
| constructors.swift:103:7:103:16 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 |
2687+
| constructors.swift:103:7:103:16 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int |
2688+
| constructors.swift:103:7:103:16 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int |
2689+
| constructors.swift:103:9:103:9 | x | | {EXTERNAL LOCATION} | Int |
2690+
| constructors.swift:103:14:103:14 | Block | | {EXTERNAL LOCATION} | Int |
2691+
| constructors.swift:103:14:103:14 | x | | {EXTERNAL LOCATION} | Int |
26662692
| fields.swift:2:7:2:20 | inheritedField | | {EXTERNAL LOCATION} | Int |
26672693
| fields.swift:2:29:2:29 | 0 | | {EXTERNAL LOCATION} | Int |
26682694
| fields.swift:6:7:6:17 | storedField | | {EXTERNAL LOCATION} | String |

0 commit comments

Comments
 (0)