From 58c28ba286dd0e98fe4cca80f5d64bbcb824a685 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 12 Dec 2023 15:40:16 -0800 Subject: go/types, types2: avoid confusing error message "have m(T), want m(T)" This is a partial fix for situations where a method lookup leads to an error due to non-matching signatures, but where the signatures print exactly the same. This can happen if both signatures contain type parameters (after instantiation) and the type parameters have the same name (such as "T"). For now, rather than printing a confusing error message in this case, leave away the confusing part of the error message (at the cost of providing slightly less information). In the long run, we need to find a better solution for this problem; but this seems better than what we had before. For #61685. Change-Id: I259183f08b9db400ffc8e1cf447967c640a0f444 Reviewed-on: https://go-review.googlesource.com/c/go/+/549296 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer --- src/internal/types/testdata/fixedbugs/issue61685.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/internal/types/testdata/fixedbugs/issue61685.go (limited to 'src/internal') diff --git a/src/internal/types/testdata/fixedbugs/issue61685.go b/src/internal/types/testdata/fixedbugs/issue61685.go new file mode 100644 index 0000000000..b88b222eb9 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue61685.go @@ -0,0 +1,15 @@ +// Copyright 2023 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 _[T any](x any) { + f /* ERROR "T (type I[T]) does not satisfy I[T] (wrong type for method m)" */ (x.(I[T])) +} + +func f[T I[T]](T) {} + +type I[T any] interface { + m(T) +} -- cgit v1.3