diff options
author | Robert Griesemer <gri@golang.org> | 2022-12-05 14:09:09 -0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-12-05 22:29:44 +0000 |
commit | 0b323a3c1690050340fc8e39730a07bb01373f0a (patch) | |
tree | 7f582fe9aa29533441d609b72b9c77fcec6c10d8 | |
parent | 9e059630ad5b7f6ddd4cf4559cd111906776d5fb (diff) | |
download | go-0b323a3c1690050340fc8e39730a07bb01373f0a.tar.gz go-0b323a3c1690050340fc8e39730a07bb01373f0a.zip |
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 <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r-- | src/cmd/compile/internal/types2/infer.go | 2 | ||||
-rw-r--r-- | src/go/types/infer.go | 2 | ||||
-rw-r--r-- | 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] } |