codekingpro/portable-devtools
114k
1// run2 3// Copyright 2021 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// derived & expanded from cmd/compile/internal/types2/testdata/fixedbugs/issue44688.go28 9package main10 11type A1[T any] struct {12 val T13}14 15func (p *A1[T]) m1(val T) {16 p.val = val17}18 19type A2[T any] interface {20 m2(T)21}22 23type B1[T any] struct {24 filler int25 *A1[T]26 A2[T]27}28 29type B2[T any] interface {30 A2[T]31}32 33type ImpA2[T any] struct {34 f T35}36 37func (a2 *ImpA2[T]) m2(s T) {38 a2.f = s39}40 41type C[T any] struct {42 filler1 int43 filler2 int44 B1[T]45}46 47type D[T any] struct {48 filler1 int49 filler2 int50 filler3 int51 C[T]52}53 54func test1[T any](arg T) {55 // calling embedded methods56 var b1 B1[T]57 b1.A1 = &A1[T]{}58 b1.A2 = &ImpA2[T]{}59 60 b1.A1.m1(arg)61 b1.m1(arg)62 63 b1.A2.m2(arg)64 b1.m2(arg)65 66 var b2 B2[T]67 b2 = &ImpA2[T]{}68 b2.m2(arg)69 70 // a deeper nesting71 var d D[T]72 d.C.B1.A1 = &A1[T]{}73 d.C.B1.A2 = &ImpA2[T]{}74 d.m1(arg)75 d.m2(arg)76 77 // calling method expressions78 m1x := B1[T].m179 m1x(b1, arg)80 // TODO(khr): reenable these.81 //m2x := B2[T].m282 //m2x(b2, arg)83 84 // calling method values85 m1v := b1.m186 m1v(arg)87 m2v := b1.m288 m2v(arg)89 b2v := b2.m290 b2v(arg)91}92 93func test2() {94 // calling embedded methods95 var b1 B1[string]96 b1.A1 = &A1[string]{}97 b1.A2 = &ImpA2[string]{}98 99 b1.A1.m1("")100 b1.m1("")101 102 b1.A2.m2("")103 b1.m2("")104 105 var b2 B2[string]106 b2 = &ImpA2[string]{}107 b2.m2("")108 109 // a deeper nesting110 var d D[string]111 d.C.B1.A1 = &A1[string]{}112 d.C.B1.A2 = &ImpA2[string]{}113 d.m1("")114 d.m2("")115 116 // calling method expressions117 m1x := B1[string].m1118 m1x(b1, "")119 m2x := B2[string].m2120 m2x(b2, "")121 122 // calling method values123 m1v := b1.m1124 m1v("")125 m2v := b1.m2126 m2v("")127 b2v := b2.m2128 b2v("")129}130 131// actual test case from issue132 133type A[T any] struct{}134 135func (*A[T]) f(T) {}136 137type B[T any] struct{ A[T] }138 139func test3() {140 var b B[string]141 b.A.f("")142 b.f("")143}144 145func main() {146 test1[string]("")147 test2()148 test3()149}150 