aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-08-31 19:06:46 -0700
committerDan Scales <danscales@google.com>2021-09-01 02:51:18 +0000
commit2dd7b770defc869edfcf610b9471fc4f580c3eb2 (patch)
tree889104e1f09c5825dc6fa5e9f4ba2de96e31bb79 /test/typeparam
parent62ba72b35321bd76de18aa8874b021ee02ab8a4e (diff)
downloadgo-2dd7b770defc869edfcf610b9471fc4f580c3eb2.tar.xz
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>
Diffstat (limited to 'test/typeparam')
-rw-r--r--test/typeparam/issue48013.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/typeparam/issue48013.go b/test/typeparam/issue48013.go
new file mode 100644
index 0000000000..179d9f44e9
--- /dev/null
+++ b/test/typeparam/issue48013.go
@@ -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))
+ }
+
+}