Source file test/typeparam/issue48253.go

     1  // run
     2  
     3  // Copyright 2021 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import (
    10  	"reflect"
    11  )
    12  
    13  type A[T any] struct {
    14  	B[int]
    15  }
    16  
    17  type B[T any] struct {
    18  }
    19  
    20  func (b B[T]) Bat() {
    21  	t := new(T)
    22  	if tt := reflect.TypeOf(t); tt.Kind() != reflect.Pointer || tt.Elem().Kind() != reflect.Int {
    23  		panic("unexpected type, want: *int, got: "+tt.String())
    24  	}
    25  }
    26  
    27  type Foo struct {
    28  	A[string]
    29  }
    30  func main() {
    31  	Foo{}.A.Bat()
    32  	Foo{}.A.B.Bat()
    33  	Foo{}.Bat()
    34  }
    35  

View as plain text