• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Test that a method of a reachable type is not necessarily
6// live even if it matches an interface method, as long as
7// the type is never converted to an interface.
8
9package main
10
11type I interface{ M() }
12
13type T int
14
15func (T) M() { println("XXX") }
16
17var p *T
18var e interface{}
19
20func main() {
21	p = new(T) // used T, but never converted to interface in any reachable code
22	e.(I).M()  // used I and I.M
23}
24
25func Unused() { // convert T to interface, but this function is not reachable
26	var i I = T(0)
27	i.M()
28}
29
30var Unused2 interface{} = T(1) // convert T to interface, in an unreachable global initializer
31