1
0
mirror of https://github.com/golang/go synced 2024-11-18 01:14:48 -07:00

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>
This commit is contained in:
Robert Griesemer 2022-12-05 14:09:09 -08:00 committed by Gopher Robot
parent 9e059630ad
commit 0b323a3c16
3 changed files with 4 additions and 4 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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]
}