[m-rev.] for review: help diagnose non-fully-qualified references to use_module'd modules

Julien Fischer jfischer at opturion.com
Mon Apr 26 16:20:43 AEST 2021


Hi Zoltan,

On Mon, 26 Apr 2021, Zoltan Somogyi wrote:

> This should help users in Sean's position.
>
> For review by anyone.
>
> I intend to put the contents of the modules affected by this change
> into a more logical order, but will do that after review, in order
> to keep irrelevant changes out of the diff.

> Diagnose names with non-full qualifications.

...

> @@ -263,6 +281,39 @@ sym_name_to_qualifier_list_and_name(qualified(Module, Name),
>
>  %---------------------------------------------------------------------------%
> 
> +list_to_sym_name(Names, SymName) :-
> +    list.reverse(Names, RevNames),
> +    list_to_sym_name_loop(RevNames, SymName).
> +
> +det_list_to_sym_name(Names, SymName) :-
> +    list.reverse(Names, RevNames),
> +    ( if list_to_sym_name_loop(RevNames, SymNamePrime) then
> +        SymName = SymNamePrime
> +    else
> +        unexpected($pred, "the list of names is empty")
> +    ).
> +
> +:- pred list_to_sym_name_loop(list(string)::in, sym_name::out) is semidet.
> +
> +list_to_sym_name_loop(RevNames, SymName) :-
> +    (
> +        RevNames = [],
> +        fail
> +    ;
> +        RevNames = [Name],
> +        SymName = unqualified(Name)
> +    ;
> +        RevNames = [LastName | PrevNames],
> +        PrevNames = [_ | _],
> +        list_to_sym_name_loop(PrevNames, ModuleQualifier),
> +        SymName = qualified(ModuleQualifier, LastName)
> +    ).
> +
> +% ZZZ a.b.c
> +% qualified(qualified(unqualified(a), b), c)

What's that comment in aid of?

> +%---------------------------------------------------------------------------%
> +
>  is_submodule(SymName, SymName).
>  is_submodule(qualified(SymNameA, _), SymNameB) :-
>      is_submodule(SymNameA, SymNameB).

...

> diff --git a/tests/invalid/errors2.err_exp b/tests/invalid/errors2.err_exp
> index 77fc4b7c1..02005e076 100644
> --- a/tests/invalid/errors2.err_exp
> +++ b/tests/invalid/errors2.err_exp
> @@ -120,9 +120,13 @@ errors2.m:074:     B_4: int
>  errors2.m:074:     C_5: string
>  errors2.m:080: In clause for predicate `type_error_8'/0:
>  errors2.m:080:   error: undefined predicate `from_char_list'/2.
> +errors2.m:080:   That predicate is defined in module `string', which does not
> +errors2.m:080:   have an `:- import_module' declaration.
>  errors2.m:080: In clause for predicate `type_error_8'/0:
>  errors2.m:080:   in argument 1 of call to predicate `from_char_list'/2:
>  errors2.m:080:   error: undefined symbol `[]'/0.
> +errors2.m:080:   That symbol is defined in module `list', which does not have
> +errors2.m:080:   an `:- import_module' declaration.
>  errors2.m:087: In clause for predicate `type_error_9'/0:
>  errors2.m:087:   type error in unification of variable `X'
>  errors2.m:087:   and variable `Y'.
> diff --git a/tests/invalid/type_error_use_module.err_exp b/tests/invalid/type_error_use_module.err_exp
> index e69de29bb..71d3b9bda 100644
> --- a/tests/invalid/type_error_use_module.err_exp
> +++ b/tests/invalid/type_error_use_module.err_exp
> @@ -0,0 +1,12 @@
> +type_error_use_module.m:018: In clause for predicate `main'/2:
> +type_error_use_module.m:018:   in argument 1 of call to predicate
> +type_error_use_module.m:018:   `io.write_line'/3:
> +type_error_use_module.m:018:   error: undefined symbol `init'/0.
> +type_error_use_module.m:018:   That symbol is defined in modules `map' and
> +type_error_use_module.m:018:   `type_error_use_module_2', none of which have
> +type_error_use_module.m:018:   `:- import_module' declarations.
> +type_error_use_module.m:019: In clause for predicate `main'/2:
> +type_error_use_module.m:019:   error: undefined predicate `do_main'/2.
> +type_error_use_module.m:019:   That predicate is defined in module
> +type_error_use_module.m:019:   `type_error_use_module_2', which does not have
> +type_error_use_module.m:019:   an `:- import_module' declaration.

I think the error messages could be further improved by having a verbose component
along the lines of:

     These modules are imported by a `:- use_module' declaration; symbols
     from such modules *must* be fully qualified.

The diff is fine otherwise.

Julien.


More information about the reviews mailing list