]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: don't panic converting a constant to aliased type parameter
authorRobert Griesemer <gri@golang.org>
Tue, 21 May 2024 21:50:10 +0000 (14:50 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 21 May 2024 22:09:36 +0000 (22:09 +0000)
For #67547.

Change-Id: I1b2118a311dce906327ae6e29e582da539c60b2b
Reviewed-on: https://go-review.googlesource.com/c/go/+/587157
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/conversions.go
src/go/types/conversions.go
src/internal/types/testdata/fixedbugs/issue67547.go [new file with mode: 0644]

index b8d8f6e1507fe77e45d5b012ddb0d1881b9339d6..05d0d37192480ec532ba9d278544249fdf9393f5 100644 (file)
@@ -56,7 +56,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                // If T's type set is empty, or if it doesn't
                // have specific types, constant x cannot be
                // converted.
-               ok = T.(*TypeParam).underIs(func(u Type) bool {
+               ok = Unalias(T).(*TypeParam).underIs(func(u Type) bool {
                        // u is nil if there are no specific type terms
                        if u == nil {
                                cause = check.sprintf("%s does not contain specific types", T)
index 98a1f9f661150c0488891f8b3c5e96f430b4fd21..f548e177de33bedf46355e7f129a2c216d1e6964 100644 (file)
@@ -59,7 +59,7 @@ func (check *Checker) conversion(x *operand, T Type) {
                // If T's type set is empty, or if it doesn't
                // have specific types, constant x cannot be
                // converted.
-               ok = T.(*TypeParam).underIs(func(u Type) bool {
+               ok = Unalias(T).(*TypeParam).underIs(func(u Type) bool {
                        // u is nil if there are no specific type terms
                        if u == nil {
                                cause = check.sprintf("%s does not contain specific types", T)
diff --git a/src/internal/types/testdata/fixedbugs/issue67547.go b/src/internal/types/testdata/fixedbugs/issue67547.go
new file mode 100644 (file)
index 0000000..cca8ba2
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2024 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 p
+
+func _[P int]() {
+       type A = P
+       _ = A(0) // don't crash with this conversion
+}