Debian Codegraph @

cmd/deadcode/testdata/marker.txtar

raw
1 # Test of marker suppression functionality.
2 # Deadcode should not identify marker interface methods as unreachable
3
4 deadcode -filter= example.com
5 !want "T.isMarker"
6 want "R.isNotMarker"
7 !want "P.greet"
8 want "Q.greet"
9
10 -- go.mod --
11 module example.com
12 go 1.18
13
14 -- main.go --
15 package main
16 import "fmt"
17
18 // Marker method: implements interface, unexported, no params, no results, empty body
19 type Marker interface {
20 isMarker()
21 }
22 type T struct{}
23
24 func (t *T) isMarker() {}
25
26 // Not marker method: does not implement interface
27 type R struct {}
28 func (r *R) isNotMarker() {}
29
30 // Ensure that it still reports valid interface methods
31 // when unused
32 type Greeter interface {
33 greet()
34 }
35 type P struct {}
36 func (p *P) greet() {fmt.Println("P: hello")}
37 type Q struct {}
38 func (q *Q) greet() {fmt.Println("Q: hello")} // this method should be reported
39
40 func main () {
41 var p P
42 p.greet()
43 }