Skip to content

Commit 2a4cb24

Browse files
paldepindCopilot
andcommitted
Unified: Add exhaustive Swift switch CFG test fixtures
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4a9b52f8-d07b-4692-8fb9-409f0efd64f2
1 parent 96852da commit 2a4cb24

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎unified/ql/test/library-tests/controlflow/basicblock-slices.expected‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| 1 | cfg.swift:1:1:613:1 | Block | 'Block -V var topLevelDecl -V topLevelDecl -> Int -> 0' |
1+
| 1 | cfg.swift:1:1:635:1 | Block | 'Block -V var topLevelDecl -V topLevelDecl -> Int -> 0' |
22
| 2 | cfg.swift:2:1:2:1 | 0 | '0' |
33
| 3 | cfg.swift:3:1:3:12 | topLevelDecl | 'topLevelDecl -> 1 -^ ... + ...' |
44
| 5 | cfg.swift:5:1:5:37 | func returnZero | 'func returnZero -V returnZero' |
@@ -494,3 +494,21 @@
494494
| 610 | cfg.swift:610:5:610:13 | var x | 'var x -V x -> N' |
495495
| 611 | cfg.swift:611:5:611:9 | print | 'print -> Argument -V x -^ print(...)' |
496496
| 612 | cfg.swift:612:5:612:5 | _ | '_ -> value -^ ... = ...' |
497+
| 615 | cfg.swift:615:1:623:1 | func exhaustiveBoolSwitch | 'func exhaustiveBoolSwitch -V exhaustiveBoolSwitch' |
498+
| 615 | cfg.swift:615:29:615:33 | value | 'value -> Block' |
499+
| 616 | cfg.swift:616:3:621:3 | SwitchExpr | 'SwitchExpr -V value' |
500+
| 617 | cfg.swift:617:5:618:14 | SwitchCase | 'SwitchCase -V true' |
501+
| 618 | cfg.swift:618:7:618:14 | Block | 'Block -V 1 -^ ReturnExpr' |
502+
| 619 | cfg.swift:619:5:620:14 | SwitchCase | 'SwitchCase -V false' |
503+
| 620 | cfg.swift:620:7:620:14 | Block | 'Block -V 0 -^ ReturnExpr' |
504+
| 622 | cfg.swift:622:11:622:11 | 1 | '1 -^ - ... -^ ReturnExpr' |
505+
| 625 | cfg.swift:625:1:635:1 | func exhaustiveEnumSwitch | 'func exhaustiveEnumSwitch -V exhaustiveEnumSwitch' |
506+
| 625 | cfg.swift:625:29:625:33 | value | 'value -> flag -> Block' |
507+
| 626 | cfg.swift:626:3:633:3 | SwitchExpr | 'SwitchExpr -V value' |
508+
| 627 | cfg.swift:627:5:628:14 | SwitchCase | 'SwitchCase -V flag -? . -^ ... .error1 -^ ConditionalPattern' |
509+
| 628 | cfg.swift:628:7:628:14 | Block | 'Block -V 1 -^ ReturnExpr' |
510+
| 629 | cfg.swift:629:5:630:14 | SwitchCase | 'SwitchCase -V . -^ ... .error1' |
511+
| 630 | cfg.swift:630:7:630:14 | Block | 'Block -V 2 -^ ReturnExpr' |
512+
| 631 | cfg.swift:631:5:632:14 | SwitchCase | 'SwitchCase -V . -^ ... .error2 -> . -^ ... .error3 -^ OrPattern' |
513+
| 632 | cfg.swift:632:7:632:14 | Block | 'Block -V 3 -^ ReturnExpr' |
514+
| 634 | cfg.swift:634:11:634:11 | 1 | '1 -^ - ... -^ ReturnExpr' |

‎unified/ql/test/library-tests/controlflow/cfg.expected‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ bbStep
150150
| cfg.swift:597:14:597:14 | 2 | '2 : successor -> let b(+2)' |
151151
| cfg.swift:600:13:600:18 | ... < ... | '... < ... : false -> Block(+1)' |
152152
| cfg.swift:600:13:600:18 | ... < ... | '... < ... : true -> Block(+0)' |
153+
| cfg.swift:617:10:617:13 | true | 'true : match -> Block(+1)' |
154+
| cfg.swift:617:10:617:13 | true | 'true : no-match -> SwitchCase(+2)' |
155+
| cfg.swift:619:10:619:14 | false | 'false : match -> Block(+1)' |
156+
| cfg.swift:619:10:619:14 | false | 'false : no-match -> 1(+3)' |
157+
| cfg.swift:627:10:627:27 | ConditionalPattern | 'ConditionalPattern : match -> Block(+1)' |
158+
| cfg.swift:627:10:627:27 | ConditionalPattern | 'ConditionalPattern : no-match -> SwitchCase(+2)' |
159+
| cfg.swift:629:10:629:16 | ... .error1 | '... .error1 : match -> Block(+1)' |
160+
| cfg.swift:629:10:629:16 | ... .error1 | '... .error1 : no-match -> SwitchCase(+2)' |
161+
| cfg.swift:631:10:631:25 | OrPattern | 'OrPattern : match -> Block(+1)' |
162+
| cfg.swift:631:10:631:25 | OrPattern | 'OrPattern : no-match -> 1(+3)' |
153163
noCfg
154164
| cfg.swift:47:42:47:47 | String |
155165
| cfg.swift:53:34:53:34 | _ |
@@ -172,3 +182,4 @@ noCfg
172182
nonSimple
173183
| cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' |
174184
| cfg.swift:35:5:35:5 | CatchClause | 'CatchClause -V MyError -^ ... .error1 -> isZero -> Argument -V x -^ isZero(...) -? MyError -^ ... .error2 -^ ConditionalPattern -^ OrPattern' |
185+
| cfg.swift:627:5:627:5 | SwitchCase | 'SwitchCase -V flag -? . -^ ... .error1 -^ ConditionalPattern' |

‎unified/ql/test/library-tests/controlflow/cfg.swift‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,25 @@ func valueGenericsFn<let N: Int>(_ value: ValueGenericsStruct<N>) {
611611
print(x);
612612
_ = value;
613613
}
614+
615+
func exhaustiveBoolSwitch(_ value: Bool) -> Int {
616+
switch value {
617+
case true: // $ bbStep='true : match -> Block(+1)' bbStep='true : no-match -> SwitchCase(+2)'
618+
return 1
619+
case false: // $ bbStep='false : match -> Block(+1)' bbStep='false : no-match -> 1(+3)'
620+
return 0
621+
}
622+
return -1
623+
}
624+
625+
func exhaustiveEnumSwitch(_ value: MyError, _ flag: Bool) -> Int {
626+
switch value {
627+
case .error1 where flag: // $ bbStep='ConditionalPattern : match -> Block(+1)' bbStep='ConditionalPattern : no-match -> SwitchCase(+2)' nonSimple='SwitchCase -V flag -? . -^ ... .error1 -^ ConditionalPattern'
628+
return 1
629+
case .error1: // $ bbStep='... .error1 : match -> Block(+1)' bbStep='... .error1 : no-match -> SwitchCase(+2)'
630+
return 2
631+
case .error2, .error3: // $ bbStep='OrPattern : match -> Block(+1)' bbStep='OrPattern : no-match -> 1(+3)'
632+
return 3
633+
}
634+
return -1
635+
}

0 commit comments

Comments
 (0)