[m-rev.] for post-commit review: warn about bad coerce arities

Peter Wang novalazy at gmail.com
Tue May 28 12:56:28 AEST 2024


On Mon, 27 May 2024 23:54:42 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by Peter.
> 
> Zoltan.

> Warn about arity mismatches with coerce.
> 
> compiler/typecheck_error_undef.m:
>     As above.
> 
> tests/invalid/coerce_syntax.err_exp:
>     Expect updated diagnostics.

> diff --git a/compiler/typecheck_error_undef.m b/compiler/typecheck_error_undef.m
> index f845a95f1..666a4d61e 100644
> --- a/compiler/typecheck_error_undef.m
> +++ b/compiler/typecheck_error_undef.m
...
> +    else if
> +        Functor = cons(FunctorSymName, FunctorArity, _),
> +        FunctorSymName = unqualified("coerce")
> +    then
> +        FunctorPieces = [words("error: the")] ++
> +            color_as_subject([words("coerce")]) ++
> +            [words("operator expects")] ++
> +            color_as_correct([words("one")]) ++
> +            [words("argument, got")] ++
> +            color_as_incorrect([int_name(FunctorArity), suffix(".")]),
> +        FunctorComps = [always(FunctorPieces)],
> +        QualSuggestionMsgs = []
>      else
>          UndefSymbolPieces = [words("error:")] ++
>              color_as_incorrect([words("undefined")]) ++

Technically, the user is allowed to name things 'coerce'.
It's only 'coerce(Expr)' that is parsed as a type conversion expression.

Can we change this error into a suggestion such as:

    A type conversion expression must be written as `coerce(Expr)'.

Peter


More information about the reviews mailing list