Skip to content

Commit cbd129f

Browse files
committed
Add test for aliasing interface method definitions
1 parent 6ed0a37 commit cbd129f

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package aliases
2+
3+
type IntAlias = int
4+
5+
type S1 = struct{ x int }
6+
type S2 = struct{ x IntAlias }
7+
8+
type I1 = interface{ F(int) }
9+
type I2 = interface{ F(IntAlias) }
10+
type I3 = interface{ F(S1) }
11+
type I4 = interface{ F(S2) }
12+
13+
func Test1(param1 I1, param2 I3, arg int) {
14+
param1.F(arg)
15+
param2.F(S1{arg})
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
distinctDefinedFs
2+
| 2 |
3+
declaredEntities
4+
| methods.go:3:6:3:13 | IntAlias (1 declaration sites) |
5+
| methods.go:5:6:5:7 | S1 (1 declaration sites) |
6+
| methods.go:5:19:5:19 | x (2 declaration sites) |
7+
| methods.go:6:6:6:7 | S2 (1 declaration sites) |
8+
| methods.go:6:19:6:19 | x (2 declaration sites) |
9+
| methods.go:8:6:8:7 | I1 (1 declaration sites) |
10+
| methods.go:8:22:8:22 | F (2 declaration sites) |
11+
| methods.go:9:6:9:7 | I2 (1 declaration sites) |
12+
| methods.go:9:22:9:22 | F (2 declaration sites) |
13+
| methods.go:10:6:10:7 | I3 (1 declaration sites) |
14+
| methods.go:10:22:10:22 | F (2 declaration sites) |
15+
| methods.go:11:6:11:7 | I4 (1 declaration sites) |
16+
| methods.go:11:22:11:22 | F (2 declaration sites) |
17+
| methods.go:13:6:13:10 | Test1 (1 declaration sites) |
18+
| methods.go:13:12:13:17 | param1 (1 declaration sites) |
19+
| methods.go:13:23:13:28 | param2 (1 declaration sites) |
20+
| methods.go:13:34:13:36 | arg (1 declaration sites) |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import go
2+
3+
newtype TEntityWithDeclInfo =
4+
MkEntityWithDeclInfo(Entity e, int nDecls) { nDecls = count(e.getDeclaration()) and nDecls > 0 }
5+
6+
class EntityWithDeclInfo extends TEntityWithDeclInfo {
7+
string toString() {
8+
exists(Entity e, int nDecls | this = MkEntityWithDeclInfo(e, nDecls) |
9+
result = e.toString() + " (" + nDecls + " declaration sites)"
10+
)
11+
}
12+
13+
predicate hasLocationInfo(
14+
string filepath, int startline, int startcolumn, int endline, int endcolumn
15+
) {
16+
exists(Entity e | this = MkEntityWithDeclInfo(e, _) |
17+
e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
18+
)
19+
}
20+
}
21+
22+
query predicate distinctDefinedFs(int ct) { ct = count(DeclaredFunction e | e.toString() = "F") }
23+
24+
query predicate declaredEntities(EntityWithDeclInfo e) { any() }

0 commit comments

Comments
 (0)