[m-dev.] bad error message

Mark Brown mark at cs.mu.OZ.AU
Wed Aug 3 21:23:14 AEST 2005


On 03-Aug-2005, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> Probably a known flaw, but you guys asked for complaints about
> bad compiler error messages....

Thanks for reporting this.

> 
> I got this error message:
> 
>     Error: expected type in instance declaration to be a functor with
>     variables as args: _1.
> 
> from this declaration:
> 
>     :- instance ground_watchable(dvar(T),T).
> 
> Firstly, note there is no line number in this error message, so the
> only way I know that's the code that caused the error is that I've
> only got 2 instance declarations, and I get 2 identical error
> messages.  If I had more, it'd be difficult to find the problem.
> Secondly, I infer that the _1 means the first argument is the one with
> the error, but that one *is* a functor with variables as arguments.

`_1' is actually a variable, in this case a type variable.  At the point
where the error is reported the compiler doesn't know the variable's
name, hence it is anonymous.  The `1' is the variable's number, that is, it
was the first variable parsed in that declaration.

> Thirdly, the message doesn't make it clear you can never have type
> variables in instance declarations, just that it didn't expect it in
> that context.

I've just posted a diff to address this issue.  The new message will read
something like:

bad_instance.m:011: Error: types in instance declarations must be functors
with distinct variables as arguments: ground_watchable(dvar(_1), _1).

It still isn't perfect, but it does address two of your points and it
should be a little more obvious that `_1' is a type variable.

Cheers,
Mark.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list