-
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.
Add test for aliasing interface method definitions
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
go/ql/test/library-tests/semmle/go/aliases/MethodDefs/methods.go
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,16 @@ | ||
package aliases | ||
|
||
type IntAlias = int | ||
|
||
type S1 = struct{ x int } | ||
type S2 = struct{ x IntAlias } | ||
|
||
type I1 = interface{ F(int) } | ||
type I2 = interface{ F(IntAlias) } | ||
type I3 = interface{ F(S1) } | ||
type I4 = interface{ F(S2) } | ||
|
||
func Test1(param1 I1, param2 I3, arg int) { | ||
param1.F(arg) | ||
param2.F(S1{arg}) | ||
} |
20 changes: 20 additions & 0 deletions
20
go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
distinctDefinedFs | ||
| 2 | | ||
declaredEntities | ||
| methods.go:3:6:3:13 | IntAlias (1 declaration sites) | | ||
| methods.go:5:6:5:7 | S1 (1 declaration sites) | | ||
| methods.go:5:19:5:19 | x (2 declaration sites) | | ||
| methods.go:6:6:6:7 | S2 (1 declaration sites) | | ||
| methods.go:6:19:6:19 | x (2 declaration sites) | | ||
| methods.go:8:6:8:7 | I1 (1 declaration sites) | | ||
| methods.go:8:22:8:22 | F (2 declaration sites) | | ||
| methods.go:9:6:9:7 | I2 (1 declaration sites) | | ||
| methods.go:9:22:9:22 | F (2 declaration sites) | | ||
| methods.go:10:6:10:7 | I3 (1 declaration sites) | | ||
| methods.go:10:22:10:22 | F (2 declaration sites) | | ||
| methods.go:11:6:11:7 | I4 (1 declaration sites) | | ||
| methods.go:11:22:11:22 | F (2 declaration sites) | | ||
| methods.go:13:6:13:10 | Test1 (1 declaration sites) | | ||
| methods.go:13:12:13:17 | param1 (1 declaration sites) | | ||
| methods.go:13:23:13:28 | param2 (1 declaration sites) | | ||
| methods.go:13:34:13:36 | arg (1 declaration sites) | |
24 changes: 24 additions & 0 deletions
24
go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.ql
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,24 @@ | ||
import go | ||
|
||
newtype TEntityWithDeclInfo = | ||
MkEntityWithDeclInfo(Entity e, int nDecls) { nDecls = count(e.getDeclaration()) and nDecls > 0 } | ||
|
||
class EntityWithDeclInfo extends TEntityWithDeclInfo { | ||
string toString() { | ||
exists(Entity e, int nDecls | this = MkEntityWithDeclInfo(e, nDecls) | | ||
result = e.toString() + " (" + nDecls + " declaration sites)" | ||
) | ||
} | ||
|
||
predicate hasLocationInfo( | ||
string filepath, int startline, int startcolumn, int endline, int endcolumn | ||
) { | ||
exists(Entity e | this = MkEntityWithDeclInfo(e, _) | | ||
e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | ||
) | ||
} | ||
} | ||
|
||
query predicate distinctDefinedFs(int ct) { ct = count(DeclaredFunction e | e.toString() = "F") } | ||
|
||
query predicate declaredEntities(EntityWithDeclInfo e) { any() } |