-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go: Add test for
AliasType
extraction
- Loading branch information
Showing
11 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/Field_getPackage.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName2.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/Field_hasQualifiedName3.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumParameter.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/SignatureType_getNumResult.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/Types/StructFields.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |