diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.expected b/go/ql/test/library-tests/semmle/go/Types/Aliases.expected new file mode 100644 index 0000000000000..2c09dd790a565 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.expected @@ -0,0 +1,20 @@ +entities +| aliases.go | aliases.go:3:6:3:13 | aliasesX | 1 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:4:6:4:13 | aliasesY | 1 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:6:6:6:14 | aliasesS1 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:6:26:6:26 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:8:6:8:14 | aliasesS2 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:8:26:8:26 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:10:6:10:6 | F | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:10:8:10:11 | Afs1 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:14:6:14:6 | G | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:14:8:14:11 | Afs2 | 1 | file://:0:0:0:0 | struct type | +| aliases.go | aliases.go:19:6:19:7 | S3 | 1 | aliases.go:19:6:19:7 | S3 | +| aliases.go | aliases.go:19:17:19:17 | x | 3 | file://:0:0:0:0 | int | +| aliases.go | aliases.go:22:6:22:6 | T | 1 | aliases.go:19:6:19:7 | S3 | +| aliases.go | aliases.go:25:6:25:6 | H | 1 | file://:0:0:0:0 | signature type | +| aliases.go | aliases.go:25:8:25:11 | Afs3 | 1 | aliases.go:19:6:19:7 | S3 | +#select +| F | func(struct { x int }) int | +| G | func(struct { x int }) int | +| H | func(S3) int | diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql new file mode 100644 index 0000000000000..8e234e7a381e9 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql @@ -0,0 +1,23 @@ +import go + +int countDecls(Entity e) { + result = count(Ident decl | decl = e.getDeclaration()) +} + +query predicate entities(string fp, Entity e, int c, Type ty) { + c = countDecls(e) and + ty = e.getType() and + exists(DbLocation loc | + loc = e.getDeclaration().getLocation() and + fp = loc.getFile().getBaseName() and + fp = "aliases.go" + ) +} + +from string fp, FuncDecl decl, SignatureType sig +where + decl.hasLocationInfo(fp, _, _, _, _) and + decl.getName() = ["F", "G", "H"] and + sig = decl.getType() and + fp.matches("%aliases.go%") +select decl.getName(), sig.pp() diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected b/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected index e635a046b23a3..758199c635235 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | +| aliases.go:8:26:8:26 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | +| aliases.go:19:17:19:17 | x | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:4:3:4:3 | s | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:8:3:8:3 | u | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | | cyclic.go:9:2:9:2 | f | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected index 2ac146f266aa9..4c69f36880be4 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | +| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | +| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | x | | cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | s | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t | u | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected index acdddfe867ea2..4fe8aee19f4ca 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected @@ -1,3 +1,6 @@ +| aliases.go:6:26:6:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | +| aliases.go:8:26:8:26 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | +| aliases.go:19:17:19:17 | x | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | S3 | x | | cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | s | s | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | t | u | | cyclic.go:8:3:8:3 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected b/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected index 3f170370284ce..bedfbc5fa00a6 100644 --- a/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected +++ b/go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected @@ -1,3 +1,4 @@ +| aliases.go:19:6:19:7 | S3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.S3 | | cyclic.go:3:6:3:6 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | | cyclic.go:7:6:7:6 | t | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.t | | cyclic.go:12:6:12:6 | u | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.u | diff --git a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected index 843020b9a955e..6742adf837fd2 100644 --- a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected +++ b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected @@ -1,3 +1,6 @@ +| aliases.go:10:1:12:1 | function declaration | 1 | +| aliases.go:14:1:16:1 | function declaration | 1 | +| aliases.go:25:1:27:1 | function declaration | 1 | | depth.go:22:1:25:1 | function declaration | 0 | | generic.go:70:1:72:1 | function declaration | 1 | | generic.go:74:1:80:1 | function declaration | 1 | diff --git a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected index 9072be74806cf..c6b20f5483067 100644 --- a/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected +++ b/go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected @@ -1,3 +1,6 @@ +| aliases.go:10:1:12:1 | function declaration | 1 | +| aliases.go:14:1:16:1 | function declaration | 1 | +| aliases.go:25:1:27:1 | function declaration | 1 | | depth.go:22:1:25:1 | function declaration | 0 | | generic.go:70:1:72:1 | function declaration | 1 | | generic.go:74:1:80:1 | function declaration | 0 | diff --git a/go/ql/test/library-tests/semmle/go/Types/StructFields.expected b/go/ql/test/library-tests/semmle/go/Types/StructFields.expected index 1db8f36d2511b..5bce8e1d7df11 100644 --- a/go/ql/test/library-tests/semmle/go/Types/StructFields.expected +++ b/go/ql/test/library-tests/semmle/go/Types/StructFields.expected @@ -1,3 +1,6 @@ +| aliases.go:19:6:19:7 | S3 | aliases.go:6:18:6:37 | struct type | x | int | +| aliases.go:19:6:19:7 | S3 | aliases.go:8:18:8:37 | struct type | x | int | +| aliases.go:19:6:19:7 | S3 | aliases.go:19:9:19:23 | struct type | x | int | | cyclic.go:3:6:3:6 | s | cyclic.go:3:8:5:1 | struct type | s | * s | | cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | f | int | | cyclic.go:7:6:7:6 | t | cyclic.go:7:8:10:1 | struct type | t | t | diff --git a/go/ql/test/library-tests/semmle/go/Types/Types.expected b/go/ql/test/library-tests/semmle/go/Types/Types.expected index b4a05a8858d10..3801769db02d3 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Types.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Types.expected @@ -1,3 +1,4 @@ +| aliases.go:19:6:19:7 | S3 | S3 | | cyclic.go:3:6:3:6 | s | s | | cyclic.go:7:6:7:6 | t | t | | cyclic.go:12:6:12:6 | u | u | diff --git a/go/ql/test/library-tests/semmle/go/Types/aliases.go b/go/ql/test/library-tests/semmle/go/Types/aliases.go new file mode 100644 index 0000000000000..49f8465873280 --- /dev/null +++ b/go/ql/test/library-tests/semmle/go/Types/aliases.go @@ -0,0 +1,27 @@ +package main + +type aliasesX = int +type aliasesY = int + +type aliasesS1 = struct{ x aliasesX } + +type aliasesS2 = struct{ x aliasesY } + +func F(Afs1 aliasesS1) int { + return G(Afs1) + Afs1.x +} + +func G(Afs2 aliasesS2) int { + return Afs2.x +} + +// This is a named type, not an alias +type S3 struct{ x int } + +// This is a type alias +type T = S3 + +// We expect `Afs3` to be of type `S3` here, not `struct{ x int }` +func H(Afs3 T) int { + return Afs3.x +}