Skip to content

Commit b715a6b

Browse files
committed
Swift: Add test containing local declarations.
1 parent da90440 commit b715a6b

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,3 +4785,99 @@ cfg.swift:
47854785

47864786
# 405| DeclRefExpr
47874787
#-----| -> TupleExpr
4788+
4789+
# 410| TBD (YieldStmt)
4790+
#-----| -> exit AccessorDecl (normal)
4791+
4792+
# 410| enter AccessorDecl
4793+
4794+
# 410| enter AccessorDecl
4795+
4796+
# 410| enter AccessorDecl
4797+
#-----| -> TBD (YieldStmt)
4798+
4799+
# 410| exit AccessorDecl
4800+
4801+
# 410| exit AccessorDecl
4802+
4803+
# 410| exit AccessorDecl
4804+
4805+
# 410| exit AccessorDecl (normal)
4806+
#-----| -> exit AccessorDecl
4807+
4808+
# 410| exit AccessorDecl (normal)
4809+
#-----| -> exit AccessorDecl
4810+
4811+
# 410| exit AccessorDecl (normal)
4812+
#-----| -> exit AccessorDecl
4813+
4814+
# 411| enter ConstructorDecl
4815+
#-----| -> DeclRefExpr
4816+
4817+
# 411| exit ConstructorDecl
4818+
4819+
# 411| exit ConstructorDecl (normal)
4820+
#-----| -> exit ConstructorDecl
4821+
4822+
# 412| DeclRefExpr
4823+
#-----| -> MemberRefExpr
4824+
4825+
# 412| MemberRefExpr
4826+
#-----| -> IntegerLiteralExpr
4827+
4828+
# 412| AssignExpr
4829+
#-----| -> ReturnStmt
4830+
4831+
# 412| IntegerLiteralExpr
4832+
#-----| -> AssignExpr
4833+
4834+
# 413| ReturnStmt
4835+
#-----| return -> exit ConstructorDecl (normal)
4836+
4837+
# 417| TBD (YieldStmt)
4838+
#-----| -> exit AccessorDecl (normal)
4839+
4840+
# 417| enter AccessorDecl
4841+
4842+
# 417| enter AccessorDecl
4843+
4844+
# 417| enter AccessorDecl
4845+
#-----| -> TBD (YieldStmt)
4846+
4847+
# 417| exit AccessorDecl
4848+
4849+
# 417| exit AccessorDecl
4850+
4851+
# 417| exit AccessorDecl
4852+
4853+
# 417| exit AccessorDecl (normal)
4854+
#-----| -> exit AccessorDecl
4855+
4856+
# 417| exit AccessorDecl (normal)
4857+
#-----| -> exit AccessorDecl
4858+
4859+
# 417| exit AccessorDecl (normal)
4860+
#-----| -> exit AccessorDecl
4861+
4862+
# 418| enter ConstructorDecl
4863+
#-----| -> DeclRefExpr
4864+
4865+
# 418| exit ConstructorDecl
4866+
4867+
# 418| exit ConstructorDecl (normal)
4868+
#-----| -> exit ConstructorDecl
4869+
4870+
# 419| DeclRefExpr
4871+
#-----| -> MemberRefExpr
4872+
4873+
# 419| MemberRefExpr
4874+
#-----| -> IntegerLiteralExpr
4875+
4876+
# 419| AssignExpr
4877+
#-----| -> ReturnStmt
4878+
4879+
# 419| IntegerLiteralExpr
4880+
#-----| -> AssignExpr
4881+
4882+
# 420| ReturnStmt
4883+
#-----| return -> exit ConstructorDecl (normal)

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,41 @@ class Structors {
403403

404404
func dictionaryLiteral(x: Int, y: Int) -> [String: Int] {
405405
return ["x": x, "y": y]
406+
}
407+
408+
func localDeclarations() -> Int {
409+
class MyLocalClass {
410+
var x: Int
411+
init() {
412+
x = 10
413+
}
414+
}
415+
416+
struct MyLocalStruct {
417+
var x: Int
418+
init() {
419+
x = 10
420+
}
421+
}
422+
423+
enum MyLocalEnum {
424+
case A
425+
case B
426+
}
427+
428+
var myLocalVar : Int;
429+
430+
// Error: declaration is only valid at file scope
431+
// extension Int {
432+
// func myExtensionMethod() -> Int {
433+
// return self
434+
// }
435+
// }
436+
437+
// protocol 'MyProtocol' cannot be nested inside another declaration
438+
// protocol MyProtocol {
439+
// func myMethod()
440+
// }
441+
442+
return 0
406443
}

0 commit comments

Comments
 (0)