-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: error message for misuse of < in generic refers confusingly to comparable #63524
Comments
I think we should mention about the invalid operator instead. Something like:
|
looks like the error is defined in src/cmd/compile/internal/types2/expr.go and src/go/types/expr.go From a quick look, it seems that the phrase "is not comparable" is a common phrase for go errors, although I completely agree that the error message can be a bit confusing |
For the error message to be helpful, it has to make reference to
|
There could be any kind of operators here, so not sure it's feasible (or worth) to report it. |
IMO the key distinction that users need to be aware of is the one mentioned by the spec about comparable vs. ordered. Therefore it could be enough to parametrize the
where The term "orderable" would fit in that sentence structure but has the disadvantage of being informal (probably not even grammatical English, not sure about that). The spec use the term "ordered". So an alternative would be to allow the error messages to diverge. For example, a logic like this: switch op {
case syntax.Eql, syntax.Neq:
cause = check.sprintf("type parameter %s is not comparable with %s", errOp.typ, op)
case syntax.Lss, syntax.Leq, syntax.Gtr, syntax.Geq:
cause = check.sprintf("type parameter %s can not be ordered with %s", errOp.typ, op)
} |
Change https://go.dev/cl/613756 mentions this issue: |
Extracted from #63523. Compiling this program
produces
It is somewhat confusing that the error message says that "T is not comparable" when the constraint for
T
iscomparable
. Not a major issue, but we should use better wording here.The text was updated successfully, but these errors were encountered: