github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/types/testdata/fixedbugs/issue6977.go (about) 1 // Copyright 2019 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 package p 6 7 import "io" 8 9 // Alan's initial report. 10 11 type I interface { f(); String() string } 12 type J interface { g(); String() string } 13 14 type IJ1 = interface { I; J } 15 type IJ2 = interface { f(); g(); String() string } 16 17 var _ = (*IJ1)(nil) == (*IJ2)(nil) // static assert that IJ1 and IJ2 are identical types 18 19 // The canonical example. 20 21 type ReadWriteCloser interface { io.ReadCloser; io.WriteCloser } 22 23 // Some more cases. 24 25 type M interface { m() } 26 type M32 interface { m() int32 } 27 type M64 interface { m() int64 } 28 29 type U1 interface { m() } 30 type U2 interface { m(); M } 31 type U3 interface { M; m() } 32 type U4 interface { M; M; M } 33 type U5 interface { U1; U2; U3; U4 } 34 35 type U6 interface { m(); m /* ERROR "duplicate method" */ () } 36 type U7 interface { M32 /* ERROR "duplicate method" */ ; m() } 37 type U8 interface { m(); M32 /* ERROR "duplicate method" */ } 38 type U9 interface { M32; M64 /* ERROR "duplicate method" */ } 39 40 // Verify that repeated embedding of the same interface(s) 41 // eliminates duplicate methods early (rather than at the 42 // end) to prevent exponential memory and time use. 43 // Without early elimination, computing T29 may take dozens 44 // of minutes. 45 type ( 46 T0 interface { m() } 47 T1 interface { T0; T0 } 48 T2 interface { T1; T1 } 49 T3 interface { T2; T2 } 50 T4 interface { T3; T3 } 51 T5 interface { T4; T4 } 52 T6 interface { T5; T5 } 53 T7 interface { T6; T6 } 54 T8 interface { T7; T7 } 55 T9 interface { T8; T8 } 56 57 T10 interface { T9; T9 } 58 T11 interface { T10; T10 } 59 T12 interface { T11; T11 } 60 T13 interface { T12; T12 } 61 T14 interface { T13; T13 } 62 T15 interface { T14; T14 } 63 T16 interface { T15; T15 } 64 T17 interface { T16; T16 } 65 T18 interface { T17; T17 } 66 T19 interface { T18; T18 } 67 68 T20 interface { T19; T19 } 69 T21 interface { T20; T20 } 70 T22 interface { T21; T21 } 71 T23 interface { T22; T22 } 72 T24 interface { T23; T23 } 73 T25 interface { T24; T24 } 74 T26 interface { T25; T25 } 75 T27 interface { T26; T26 } 76 T28 interface { T27; T27 } 77 T29 interface { T28; T28 } 78 ) 79 80 // Verify that m is present. 81 var x T29 82 var _ = x.m