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 // TODO(gri) Enable this longer test once we have found a solution 58 // for the incorrect optimization in the validType check 59 // (see TODO in validtype.go). 60 // T10 interface { T9; T9 } 61 // T11 interface { T10; T10 } 62 // T12 interface { T11; T11 } 63 // T13 interface { T12; T12 } 64 // T14 interface { T13; T13 } 65 // T15 interface { T14; T14 } 66 // T16 interface { T15; T15 } 67 // T17 interface { T16; T16 } 68 // T18 interface { T17; T17 } 69 // T19 interface { T18; T18 } 70 71 // T20 interface { T19; T19 } 72 // T21 interface { T20; T20 } 73 // T22 interface { T21; T21 } 74 // T23 interface { T22; T22 } 75 // T24 interface { T23; T23 } 76 // T25 interface { T24; T24 } 77 // T26 interface { T25; T25 } 78 // T27 interface { T26; T26 } 79 // T28 interface { T27; T27 } 80 // T29 interface { T28; T28 } 81 ) 82 83 // Verify that m is present. 84 var x T9 // T29 85 var _ = x.m 86