From 0b323a3c1690050340fc8e39730a07bb01373f0a Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 5 Dec 2022 14:09:09 -0800 Subject: [PATCH] go/types, types2: better error message for failing constraint type inference We know the type argument against which constraint type inference fails: print the type argument instead of the corresponding type parameter. Fixes #57096. Change-Id: Ia1da9c87fac6f8062e4d534b82e895fa4617fddc Reviewed-on: https://go-review.googlesource.com/c/go/+/455278 Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/infer.go | 2 +- src/go/types/infer.go | 2 +- src/internal/types/testdata/fixedbugs/issue45985.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 717f7dde28..1075457aca 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -537,7 +537,7 @@ func (check *Checker) inferB(pos syntax.Pos, tparams []*TypeParam, targs []Type) if core.tilde { tilde = "~" } - check.errorf(pos, InvalidTypeArg, "%s does not match %s%s", tpar, tilde, core.typ) + check.errorf(pos, InvalidTypeArg, "%s does not match %s%s", tx, tilde, core.typ) return nil, 0 } diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 5a762a78ab..1c1d4e03fc 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -534,7 +534,7 @@ func (check *Checker) inferB(posn positioner, tparams []*TypeParam, targs []Type if core.tilde { tilde = "~" } - check.errorf(posn, InvalidTypeArg, "%s does not match %s%s", tpar, tilde, core.typ) + check.errorf(posn, InvalidTypeArg, "%s does not match %s%s", tx, tilde, core.typ) return nil, 0 } diff --git a/src/internal/types/testdata/fixedbugs/issue45985.go b/src/internal/types/testdata/fixedbugs/issue45985.go index 9a0f5e3697..ae04ce2715 100644 --- a/src/internal/types/testdata/fixedbugs/issue45985.go +++ b/src/internal/types/testdata/fixedbugs/issue45985.go @@ -5,9 +5,9 @@ package issue45985 func app[S interface{ ~[]T }, T any](s S, e T) S { - return append(s, e) + return append(s, e) } func _() { - _ = app/* ERROR "S does not match" */[int] + _ = app /* ERROR "int does not match" */ [int] }