diff --git a/src/cmd/compile/internal/types2/conversions.go b/src/cmd/compile/internal/types2/conversions.go index 47f9ac0a5a..253868cf93 100644 --- a/src/cmd/compile/internal/types2/conversions.go +++ b/src/cmd/compile/internal/types2/conversions.go @@ -233,6 +233,9 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool { } x.typ = V.typ return Tp.is(func(T *term) bool { + if T == nil { + return false // no specific types + } if !x.convertibleTo(check, T.typ, cause) { errorf("cannot convert %s (in %s) to %s (in %s)", V.typ, Vp, T.typ, Tp) return false diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49864.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49864.go2 new file mode 100644 index 0000000000..0437e74a64 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49864.go2 @@ -0,0 +1,9 @@ +// 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 p + +func _[P ~int, Q any](p P) { + _ = Q(p /* ERROR cannot convert */ ) +} diff --git a/src/go/types/conversions.go b/src/go/types/conversions.go index 5995d5920f..fb3771635d 100644 --- a/src/go/types/conversions.go +++ b/src/go/types/conversions.go @@ -224,6 +224,9 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool { } x.typ = V.typ return Tp.is(func(T *term) bool { + if T == nil { + return false // no specific types + } if !x.convertibleTo(check, T.typ, cause) { errorf("cannot convert %s (in %s) to %s (in %s)", V.typ, Vp, T.typ, Tp) return false diff --git a/src/go/types/testdata/fixedbugs/issue49864.go2 b/src/go/types/testdata/fixedbugs/issue49864.go2 new file mode 100644 index 0000000000..0437e74a64 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue49864.go2 @@ -0,0 +1,9 @@ +// 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 p + +func _[P ~int, Q any](p P) { + _ = Q(p /* ERROR cannot convert */ ) +}