mirror of
https://github.com/golang/go
synced 2024-11-22 21:10:03 -07:00
cmd/compile: fix missing case for shape double-check function
Missing case types.TUNSAFEPTR in parameterizedBy(). Also realized there was the same missing case in the type substituter (*Tsubster).Typ(). Fixes #48103 Change-Id: If71f1a6ef80932f0e2120d4c18b39a30189fd8fe Reviewed-on: https://go-review.googlesource.com/c/go/+/346669 Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
62ba72b353
commit
2dd7b770de
@ -1917,7 +1917,7 @@ func parameterizedBy1(t *types.Type, params []*types.Type, visited map[*types.Ty
|
||||
|
||||
case types.TINT, types.TINT8, types.TINT16, types.TINT32, types.TINT64,
|
||||
types.TUINT, types.TUINT8, types.TUINT16, types.TUINT32, types.TUINT64,
|
||||
types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128:
|
||||
types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128, types.TUNSAFEPTR:
|
||||
return true
|
||||
|
||||
case types.TUNION:
|
||||
|
@ -1189,7 +1189,7 @@ func (ts *Tsubster) typ1(t *types.Type) *types.Type {
|
||||
}
|
||||
case types.TINT, types.TINT8, types.TINT16, types.TINT32, types.TINT64,
|
||||
types.TUINT, types.TUINT8, types.TUINT16, types.TUINT32, types.TUINT64,
|
||||
types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128:
|
||||
types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128, types.TUNSAFEPTR:
|
||||
newt = t.Underlying()
|
||||
case types.TUNION:
|
||||
nt := t.NumTerms()
|
||||
|
39
test/typeparam/issue48013.go
Normal file
39
test/typeparam/issue48013.go
Normal file
@ -0,0 +1,39 @@
|
||||
// run -gcflags=-G=3
|
||||
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type S[T any] struct {
|
||||
val T
|
||||
}
|
||||
|
||||
// Test type substitution where base type is unsafe.Pointer
|
||||
type U[T any] unsafe.Pointer
|
||||
|
||||
func test[T any]() T {
|
||||
var q U[T]
|
||||
var v struct {
|
||||
// Test derived type that contains an unsafe.Pointer
|
||||
p unsafe.Pointer
|
||||
val T
|
||||
}
|
||||
_ = q
|
||||
return v.val
|
||||
}
|
||||
|
||||
func main() {
|
||||
want := 0
|
||||
got := test[int]()
|
||||
if got != want {
|
||||
panic(fmt.Sprintf("got %f, want %f", got, want))
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user