[m-rev.] for review: Include variable name in coerce type error messages.

Zoltan Somogyi zoltan.somogyi at runbox.com
Tue Jul 2 17:53:52 AEST 2024


On 2024-07-02 17:24 +10:00 AEST, "Peter Wang" <novalazy at gmail.com> wrote:
> 
> Writing
> 
>     error: cannot coerce [the term bound to] `X' from ...
> or
>     warning: type conversion of [the term bound to] `X' from ...
> 
> seems too long-winded, so I've omitted the bracketed words.
> Do the messages give the impression that variables can somehow change
> types? Suggestions welcome.

I agree that is a concern, but I also can't think of wording that would
avoid that misleading impression yet is short and direct enough.

> ----
> 
> compiler/typecheck.m:
> compiler/typecheck_errors.m:
>     As above.

What is above? Not your question, surely.

> --- a/tests/invalid/coerce_non_du.err_exp
> +++ b/tests/invalid/coerce_non_du.err_exp
> @@ -1,22 +1,22 @@
>  coerce_non_du.m:015: In clause for function `f1'/1:
> -coerce_non_du.m:015:   error: cannot coerce from `int' to `int'.
> +coerce_non_du.m:015:   error: cannot coerce `X' from `int' to `int'.
>  coerce_non_du.m:015:   You can only coerce from one discriminated union type to
>  coerce_non_du.m:015:   another, and `int' is a builtin type.

This reports the error for an int->X coercion, but leaves out the warning for the X->X coercion,
making it the elephant in the room. I would either leave out the part of the message that
reports the coerced-to type, or add an addendum about the coercion being redundant as well as
erroneous. I would prefer the latter, but can live with the former.

The diff is fine, but you may want to wait to see if Julien has any ideas about
a better answer to your question.

Zoltan.


More information about the reviews mailing list