...

Source file src/internal/types/testdata/fixedbugs/issue44688.go

Documentation: internal/types/testdata/fixedbugs

     1  // Copyright 2021 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  type A1[T any] struct{}
     8  
     9  func (*A1[T]) m1(T) {}
    10  
    11  type A2[T any] interface {
    12  	m2(T)
    13  }
    14  
    15  type B1[T any] struct {
    16  	filler int
    17  	*A1[T]
    18  	A2[T]
    19  }
    20  
    21  type B2[T any] interface {
    22  	A2[T]
    23  }
    24  
    25  type C[T any] struct {
    26  	filler1 int
    27  	filler2 int
    28  	B1[T]
    29  }
    30  
    31  type D[T any] struct {
    32  	filler1 int
    33  	filler2 int
    34  	filler3 int
    35  	C[T]
    36  }
    37  
    38  func _() {
    39  	// calling embedded methods
    40  	var b1 B1[string]
    41  
    42  	b1.A1.m1("")
    43  	b1.m1("")
    44  
    45  	b1.A2.m2("")
    46  	b1.m2("")
    47  
    48  	var b2 B2[string]
    49  	b2.m2("")
    50  
    51  	// a deeper nesting
    52  	var d D[string]
    53  	d.m1("")
    54  	d.m2("")
    55  
    56  	// calling method expressions
    57  	m1x := B1[string].m1
    58  	m1x(b1, "")
    59  	m2x := B2[string].m2
    60  	m2x(b2, "")
    61  
    62  	// calling method values
    63  	m1v := b1.m1
    64  	m1v("")
    65  	m2v := b1.m2
    66  	m2v("")
    67  	b2v := b2.m2
    68  	b2v("")
    69  }
    70  
    71  // actual test case from issue
    72  
    73  type A[T any] struct{}
    74  
    75  func (*A[T]) f(T) {}
    76  
    77  type B[T any] struct{ A[T] }
    78  
    79  func _() {
    80  	var b B[string]
    81  	b.A.f("")
    82  	b.f("")
    83  }
    84  

View as plain text