Skip to content

Commit dd01da4

Browse files
committed
Swift: AST and CFG tests for nil coalescing
1 parent 7e7852e commit dd01da4

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

swift/ql/test/library-tests/ast/PrintAst.expected

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,21 @@ cfg.swift:
33003300
# 526| Type = Int
33013301
# 533| [ConcreteVarDecl] i
33023302
# 533| Type = Int
3303+
# 538| [NamedFunction] testNilCoalescing(x:)
3304+
# 538| InterfaceType = (Int?) -> Int
3305+
# 538| getParam(0): [ParamDecl] x
3306+
# 538| Type = Int?
3307+
# 538| getBody(): [BraceStmt] { ... }
3308+
# 539| getElement(0): [ReturnStmt] return ...
3309+
# 539| getResult(): [BinaryExpr] ... ??(_:_:) ...
3310+
# 539| getFunction(): [DeclRefExpr] ??(_:_:)
3311+
# 539| getArgument(0): [Argument] : x
3312+
# 539| getExpr(): [DeclRefExpr] x
3313+
# 539| getArgument(1): [Argument] : { ... }
3314+
# 539| getExpr(): [AutoClosureExpr] { ... }
3315+
# 539| getBody(): [BraceStmt] { ... }
3316+
# 539| getElement(0): [ReturnStmt] return ...
3317+
# 539| getResult(): [IntegerLiteralExpr] 0
33033318
declarations.swift:
33043319
# 1| [StructDecl] Foo
33053320
# 2| getMember(0): [PatternBindingDecl] var ... = ...

swift/ql/test/library-tests/ast/cfg.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,7 @@ func testAsyncFor () async {
534534
print(i)
535535
}
536536
}
537+
538+
func testNilCoalescing(x: Int?) -> Int {
539+
return x ?? 0
540+
}

swift/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6180,3 +6180,36 @@ cfg.swift:
61806180

61816181
# 534| i
61826182
#-----| -> (Any) ...
6183+
6184+
# 538| enter testNilCoalescing(x:)
6185+
#-----| -> testNilCoalescing(x:)
6186+
6187+
# 538| exit testNilCoalescing(x:)
6188+
6189+
# 538| exit testNilCoalescing(x:) (abnormal)
6190+
#-----| -> exit testNilCoalescing(x:)
6191+
6192+
# 538| exit testNilCoalescing(x:) (normal)
6193+
#-----| -> exit testNilCoalescing(x:)
6194+
6195+
# 538| testNilCoalescing(x:)
6196+
#-----| -> x
6197+
6198+
# 538| x
6199+
#-----| -> ??(_:_:)
6200+
6201+
# 539| return ...
6202+
#-----| return -> exit testNilCoalescing(x:) (normal)
6203+
6204+
# 539| x
6205+
#-----| -> { ... }
6206+
6207+
# 539| ... ??(_:_:) ...
6208+
#-----| exception -> exit testNilCoalescing(x:) (abnormal)
6209+
#-----| -> return ...
6210+
6211+
# 539| ??(_:_:)
6212+
#-----| -> x
6213+
6214+
# 539| { ... }
6215+
#-----| -> ... ??(_:_:) ...

swift/ql/test/library-tests/controlflow/graph/cfg.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,7 @@ func testAsyncFor () async {
534534
print(i)
535535
}
536536
}
537+
538+
func testNilCoalescing(x: Int?) -> Int {
539+
return x ?? 0
540+
}

0 commit comments

Comments
 (0)