From 814e72f2ef280da54d1af8088b9a732fda9f217b Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 21 May 2024 14:50:10 -0700 Subject: [PATCH] go/types, types2: don't panic converting a constant to aliased type parameter For #67547. Change-Id: I1b2118a311dce906327ae6e29e582da539c60b2b Reviewed-on: https://go-review.googlesource.com/c/go/+/587157 Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/conversions.go | 2 +- src/go/types/conversions.go | 2 +- src/internal/types/testdata/fixedbugs/issue67547.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/internal/types/testdata/fixedbugs/issue67547.go diff --git a/src/cmd/compile/internal/types2/conversions.go b/src/cmd/compile/internal/types2/conversions.go index b8d8f6e150..05d0d37192 100644 --- a/src/cmd/compile/internal/types2/conversions.go +++ b/src/cmd/compile/internal/types2/conversions.go @@ -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) diff --git a/src/go/types/conversions.go b/src/go/types/conversions.go index 98a1f9f661..f548e177de 100644 --- a/src/go/types/conversions.go +++ b/src/go/types/conversions.go @@ -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 index 0000000000..cca8ba2367 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue67547.go @@ -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 +} -- 2.48.1