[m-rev.] for post-commit review: fix Mantis bug 488

Julien Fischer jfischer at opturion.com
Mon Oct 28 11:40:07 AEDT 2019


Hi Zoltan,

On Mon, 28 Oct 2019, Zoltan Somogyi wrote:

> Diagnose variables as pred/func names in more contexts.
> 
> compiler/parse_item.m:
>     Expand the set of situations in which we look for predicate and function
>     name that is a variable. We now look in:
>
>     - type declarations of predicates and functions, with and without
>       attached mode and/or determinism information,
>     - mode declarations of predicates and functions,
>     - clause heads.

There's another situation: predicate / function method declarations in type classes.

With this change:

     :- typeclass foo(T) where [
        pred MyMethod(T::in, int::out) is semidet
     ].

produces the message:

    foo.m:005: Error: you cannot declare a predicate whose name is a variable such
    foo.m:005:   as `MyMethod'

The one change I would make there is that in the above case the error message
should say "predicate method" rather than just "predicate".

For type classes there's another problem:

    :- typeclass MyClass(T) where [].

compiles *without* complaint.  (Attempting to define an instance for MyClass
result *will* result in an error message, albeit a misleading one.)

> compiler/make_hlds_passes.m:
>     Delete the old test for variables as predicate or function names in
>     clauses. It is best for consistency if parse_item.m handles
>     all occurrences of this test.
> 
> tests/invalid/var_as_pred_name.{m,err_exp}:
>     Test for the handling of variables as both predicate and function names in
>
>     - a plain type declaration,
>     - a mode type declaration without determinism,
>     - a mode type declaration with determinism,
>     - a combined type and mode declaration without determinism,
>     - a combined type and mode declaration with determinism,
>     - a clause.

I would extend this teszt to cover type class method declarations since
this change has affected them too  (They share pretty much the same
code.)

The diff looks fine otherwise.

Julien.


More information about the reviews mailing list