]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix missing case for shape double-check function
authorDan Scales <danscales@google.com>
Wed, 1 Sep 2021 02:06:46 +0000 (19:06 -0700)
committerDan Scales <danscales@google.com>
Wed, 1 Sep 2021 02:51:18 +0000 (02:51 +0000)
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>

src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/typecheck/subr.go
test/typeparam/issue48013.go [new file with mode: 0644]

index cf3894e0967652ae54c00d99c17d8f462e9ba687..17173179250b6b85e262eb87f15655f68816cb72 100644 (file)
@@ -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:
index 3ec2cc5d5625d1139adbf2b8b3afbc1fe9d4574e..541e1907c03a71f557c07e30bf53a561dcace979 100644 (file)
@@ -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()
diff --git a/test/typeparam/issue48013.go b/test/typeparam/issue48013.go
new file mode 100644 (file)
index 0000000..179d9f4
--- /dev/null
@@ -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))
+       }
+
+}