Skip to content

Commit bf2fb2f

Browse files
committed
Add tests for interface implementation across aliasing
1 parent 73cc746 commit bf2fb2f

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
callTargets
2+
| test.go:38:2:38:24 | call to ImplementMe | test.go:12:1:12:72 | function declaration | ImplementMe |
3+
| test.go:38:2:38:24 | call to ImplementMe | test.go:17:1:17:67 | function declaration | ImplementMe |
4+
| test.go:38:2:38:24 | call to ImplementMe | test.go:23:1:23:54 | function declaration | ImplementMe |
5+
| test.go:38:2:38:24 | call to ImplementMe | test.go:29:1:29:61 | function declaration | ImplementMe |
6+
| test.go:38:2:38:24 | call to ImplementMe | test.go:35:1:35:74 | function declaration | ImplementMe |
7+
#select
8+
| file://:0:0:0:0 | basic interface type | file://:0:0:0:0 | basic interface type |
9+
| file://:0:0:0:0 | basic interface type | test.go:10:6:10:10 | Impl1 |
10+
| file://:0:0:0:0 | basic interface type | test.go:15:6:15:10 | Impl2 |
11+
| file://:0:0:0:0 | basic interface type | test.go:20:6:20:10 | Impl3 |
12+
| file://:0:0:0:0 | basic interface type | test.go:26:6:26:10 | Impl4 |
13+
| file://:0:0:0:0 | basic interface type | test.go:32:6:32:10 | Impl5 |
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package intfs
2+
3+
type IntAlias = int
4+
5+
type Target = interface {
6+
ImplementMe(callable func (struct { x IntAlias }))
7+
}
8+
9+
// Simple direct implementation
10+
type Impl1 struct {}
11+
12+
func (recv Impl1) ImplementMe(callable func (struct { x IntAlias })) { }
13+
14+
// Implementation via unalising
15+
type Impl2 struct {}
16+
17+
func (recv Impl2) ImplementMe(callable func (struct { x int })) { }
18+
19+
// Implementation via top-level aliasing
20+
type Impl3 struct {}
21+
22+
type Impl3Alias = func (struct { x IntAlias })
23+
func (recv Impl3) ImplementMe(callable Impl3Alias) { }
24+
25+
// Implementation via aliasing the struct
26+
type Impl4 struct {}
27+
28+
type Impl4Alias = struct { x IntAlias }
29+
func (recv Impl4) ImplementMe(callable func (Impl4Alias)) { }
30+
31+
// Implementation via aliasing the struct member
32+
type Impl5 struct {}
33+
34+
type Impl5Alias = IntAlias
35+
func (recv Impl5) ImplementMe(callable func (struct { x Impl5Alias })) { }
36+
37+
func Caller(target Target) {
38+
target.ImplementMe(nil)
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import go
2+
3+
query predicate callTargets(DataFlow::CallNode cn, FuncDef target, string targetName) {
4+
target = cn.getACallee() and targetName = target.getName()
5+
}
6+
7+
from InterfaceType i, Type impl
8+
where i.hasMethod("ImplementMe", _)
9+
and impl.implements(i)
10+
select i, impl

0 commit comments

Comments
 (0)