Source file test/typeparam/issue48013.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  	"fmt"
    11  	"unsafe"
    12  )
    13  
    14  type S[T any] struct {
    15  	val T
    16  }
    17  
    18  // Test type substitution where base type is unsafe.Pointer
    19  type U[T any] unsafe.Pointer
    20  
    21  func test[T any]() T {
    22  	var q U[T]
    23  	var v struct {
    24  		// Test derived type that contains an unsafe.Pointer
    25  		p   unsafe.Pointer
    26  		val T
    27  	}
    28  	_ = q
    29  	return v.val
    30  }
    31  
    32  func main() {
    33  	want := 0
    34  	got := test[int]()
    35  	if got != want {
    36  		panic(fmt.Sprintf("got %f, want %f", got, want))
    37  	}
    38  
    39  }
    40  

View as plain text