From b8ea8400d136731abb481b2aa9bc17a7e001705a Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 17 Oct 2024 15:37:31 +0100 Subject: [PATCH] Add type param decls to PrintAST tests --- .../semmle/go/PrintAst/PrintAst.expected | 35 +++++++++++++++++++ .../PrintAst/PrintAstExcludeComments.expected | 35 +++++++++++++++++++ .../PrintAst/PrintAstNestedFunction.expected | 21 +++++++++++ .../go/PrintAst/PrintAstRestrictFile.expected | 34 ++++++++++++++++++ .../PrintAstRestrictFunction.expected | 21 +++++++++++ .../library-tests/semmle/go/PrintAst/go.mod | 3 +- .../library-tests/semmle/go/PrintAst/other.go | 6 +++- 7 files changed, 152 insertions(+), 3 deletions(-) diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected index 41815e473a03..0c71ba870e4a 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected +++ b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected @@ -1,3 +1,16 @@ +other.go: +# 8| [TypeParamDecl] type parameter declaration +# 8| 0: [Ident, TypeName] int +# 8| Type = int +# 8| 1: [Ident, TypeName] U +# 8| Type = U +# 17| [TypeParamDecl] type parameter declaration +# 17| 0: [TypeSetLiteralExpr] type set literal +# 17| Type = ~string +# 17| 0: [Ident, TypeName] string +# 17| Type = string +# 17| 1: [Ident, TypeName] T +# 17| Type = T go.mod: # 0| [GoModFile] go.mod # 1| 0: [GoModModuleLine] go.mod module line @@ -648,3 +661,25 @@ other.go: # 15| 2: [IntLit] 0 # 15| Type = int # 15| Value = [IntLit] 0 +# 17| 6: [TypeDecl] type declaration +# 17| 0: [TypeSpec] type declaration specifier +# 17| 0: [Ident, TypeName] myType +# 17| Type = myType +# 17| 1: [ArrayTypeExpr] array type +# 17| Type = []T +# 17| 0: [Ident, TypeName] T +# 17| Type = T +# 19| 7: [MethodDecl] function declaration +# 19| 0: [FunctionName, Ident] f +# 19| Type = func() +# 19| 1: [FuncTypeExpr] function type +# 19| 2: [ReceiverDecl] receiver declaration +# 19| 0: [GenericTypeInstantiationExpr] generic type instantiation expression +# 19| Type = myType +# 19| 0: [Ident, TypeName] myType +# 19| Type = myType +# 19| 1: [Ident, TypeName] U +# 19| Type = U +# 19| 1: [Ident, VariableName] m +# 19| Type = myType +# 19| 3: [BlockStmt] block statement diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected index 570ce08f2394..1592cc4ca751 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected +++ b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected @@ -1,3 +1,16 @@ +other.go: +# 8| [TypeParamDecl] type parameter declaration +# 8| 0: [Ident, TypeName] int +# 8| Type = int +# 8| 1: [Ident, TypeName] U +# 8| Type = U +# 17| [TypeParamDecl] type parameter declaration +# 17| 0: [TypeSetLiteralExpr] type set literal +# 17| Type = ~string +# 17| 0: [Ident, TypeName] string +# 17| Type = string +# 17| 1: [Ident, TypeName] T +# 17| Type = T go.mod: # 0| [GoModFile] go.mod # 1| 0: [GoModModuleLine] go.mod module line @@ -628,3 +641,25 @@ other.go: # 15| 2: [IntLit] 0 # 15| Type = int # 15| Value = [IntLit] 0 +# 17| 6: [TypeDecl] type declaration +# 17| 0: [TypeSpec] type declaration specifier +# 17| 0: [Ident, TypeName] myType +# 17| Type = myType +# 17| 1: [ArrayTypeExpr] array type +# 17| Type = []T +# 17| 0: [Ident, TypeName] T +# 17| Type = T +# 19| 7: [MethodDecl] function declaration +# 19| 0: [FunctionName, Ident] f +# 19| Type = func() +# 19| 1: [FuncTypeExpr] function type +# 19| 2: [ReceiverDecl] receiver declaration +# 19| 0: [GenericTypeInstantiationExpr] generic type instantiation expression +# 19| Type = myType +# 19| 0: [Ident, TypeName] myType +# 19| Type = myType +# 19| 1: [Ident, TypeName] U +# 19| Type = U +# 19| 1: [Ident, VariableName] m +# 19| Type = myType +# 19| 3: [BlockStmt] block statement diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstNestedFunction.expected b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstNestedFunction.expected index c8a01b1ba97a..36f054fbe1aa 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstNestedFunction.expected +++ b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstNestedFunction.expected @@ -1,3 +1,16 @@ +other.go: +# 8| [TypeParamDecl] type parameter declaration +# 8| 0: [Ident, TypeName] int +# 8| Type = int +# 8| 1: [Ident, TypeName] U +# 8| Type = U +# 17| [TypeParamDecl] type parameter declaration +# 17| 0: [TypeSetLiteralExpr] type set literal +# 17| Type = ~string +# 17| 0: [Ident, TypeName] string +# 17| Type = string +# 17| 1: [Ident, TypeName] T +# 17| Type = T go.mod: # 0| [GoModFile] go.mod # 1| 0: [GoModModuleLine] go.mod module line @@ -65,3 +78,11 @@ other.go: # 15| 2: [IntLit] 0 # 15| Type = int # 15| Value = [IntLit] 0 +# 17| 3: [TypeDecl] type declaration +# 17| 0: [TypeSpec] type declaration specifier +# 17| 0: [Ident, TypeName] myType +# 17| Type = myType +# 17| 1: [ArrayTypeExpr] array type +# 17| Type = []T +# 17| 0: [Ident, TypeName] T +# 17| Type = T diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFile.expected b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFile.expected index 1981fde0357e..3d313a087b48 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFile.expected +++ b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFile.expected @@ -1,4 +1,16 @@ other.go: +# 8| [TypeParamDecl] type parameter declaration +# 8| 0: [Ident, TypeName] int +# 8| Type = int +# 8| 1: [Ident, TypeName] U +# 8| Type = U +# 17| [TypeParamDecl] type parameter declaration +# 17| 0: [TypeSetLiteralExpr] type set literal +# 17| Type = ~string +# 17| 0: [Ident, TypeName] string +# 17| Type = string +# 17| 1: [Ident, TypeName] T +# 17| Type = T # 0| [GoFile] other.go # 1| package: [Ident] main # 3| 1: [FuncDecl] function declaration @@ -50,3 +62,25 @@ other.go: # 15| 2: [IntLit] 0 # 15| Type = int # 15| Value = [IntLit] 0 +# 17| 6: [TypeDecl] type declaration +# 17| 0: [TypeSpec] type declaration specifier +# 17| 0: [Ident, TypeName] myType +# 17| Type = myType +# 17| 1: [ArrayTypeExpr] array type +# 17| Type = []T +# 17| 0: [Ident, TypeName] T +# 17| Type = T +# 19| 7: [MethodDecl] function declaration +# 19| 0: [FunctionName, Ident] f +# 19| Type = func() +# 19| 1: [FuncTypeExpr] function type +# 19| 2: [ReceiverDecl] receiver declaration +# 19| 0: [GenericTypeInstantiationExpr] generic type instantiation expression +# 19| Type = myType +# 19| 0: [Ident, TypeName] myType +# 19| Type = myType +# 19| 1: [Ident, TypeName] U +# 19| Type = U +# 19| 1: [Ident, VariableName] m +# 19| Type = myType +# 19| 3: [BlockStmt] block statement diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFunction.expected b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFunction.expected index 5783960cedc2..4ba6522d3267 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFunction.expected +++ b/go/ql/test/library-tests/semmle/go/PrintAst/PrintAstRestrictFunction.expected @@ -1,3 +1,16 @@ +other.go: +# 8| [TypeParamDecl] type parameter declaration +# 8| 0: [Ident, TypeName] int +# 8| Type = int +# 8| 1: [Ident, TypeName] U +# 8| Type = U +# 17| [TypeParamDecl] type parameter declaration +# 17| 0: [TypeSetLiteralExpr] type set literal +# 17| Type = ~string +# 17| 0: [Ident, TypeName] string +# 17| Type = string +# 17| 1: [Ident, TypeName] T +# 17| Type = T go.mod: # 0| [GoModFile] go.mod # 1| 0: [GoModModuleLine] go.mod module line @@ -45,3 +58,11 @@ other.go: # 15| 2: [IntLit] 0 # 15| Type = int # 15| Value = [IntLit] 0 +# 17| 3: [TypeDecl] type declaration +# 17| 0: [TypeSpec] type declaration specifier +# 17| 0: [Ident, TypeName] myType +# 17| Type = myType +# 17| 1: [ArrayTypeExpr] array type +# 17| Type = []T +# 17| 0: [Ident, TypeName] T +# 17| Type = T diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/go.mod b/go/ql/test/library-tests/semmle/go/PrintAst/go.mod index c3149650c4c1..a443fbece394 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/go.mod +++ b/go/ql/test/library-tests/semmle/go/PrintAst/go.mod @@ -1,4 +1,3 @@ module codeql-go-tests/printast -go 1.14 - +go 1.18 diff --git a/go/ql/test/library-tests/semmle/go/PrintAst/other.go b/go/ql/test/library-tests/semmle/go/PrintAst/other.go index 9d60eff98bdc..caf66812d601 100644 --- a/go/ql/test/library-tests/semmle/go/PrintAst/other.go +++ b/go/ql/test/library-tests/semmle/go/PrintAst/other.go @@ -5,7 +5,7 @@ func main() {} func f() {} func g() {} -func hasNested() { +func hasNested[U int]() { myNested := func() int { return 1 } myNested() @@ -13,3 +13,7 @@ func hasNested() { } var x int = 0 + +type myType[T ~string] []T + +func (m myType[U]) f() {}