[m-rev.] for review: improve actual/expected types in diagnostics

Peter Wang novalazy at gmail.com
Sun Oct 16 12:16:22 AEDT 2022


On Sun, 16 Oct 2022 06:45:50 +1100 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> The message we generate for the same code is now
> 
> a02x.m:020: In clause for predicate `p1'/3:
> a02x.m:020:   in argument 1 of call to predicate `foldl'/4:
> a02x.m:020:   type error: type of argument does not match its expected type;
> a02x.m:020:   its inferred type is
> a02x.m:020:     pred(int, a02x.dir, int),
> a02x.m:020:   its expected types are {
> a02x.m:020:     (expected by predicate `list.foldl'/4):
> a02x.m:020:     pred(L, A, A),
> a02x.m:020:     (expected by predicate `string.foldl'/4):
> a02x.m:020:     pred(character, A, A)
> a02x.m:020:   }.

I think it would be further improved as:

a02x.m:020: In clause for predicate `p1'/3:
a02x.m:020:   in argument 1 of call to predicate `foldl'/4:
a02x.m:020:   type error: type of argument does not match its expected type;
a02x.m:020:   its inferred type is
a02x.m:020:     pred(int, a02x.dir, int)
a02x.m:020:   the type expected by predicate `list.foldl'/4 is:
a02x.m:020:     pred(L, A, A)
a02x.m:020:   the type expected by predicate `string.foldl'/4 is:
a02x.m:020:     pred(character, A, A)

> diff --git a/compiler/type_assign.m b/compiler/type_assign.m
> index 6b8d0a55a..8827b681d 100644
> --- a/compiler/type_assign.m
> +++ b/compiler/type_assign.m
> @@ -146,21 +148,49 @@
>  % The args_type_assign data structure.
>  %
>  
> +:- type args_type_assign_source
> +    --->    atas_pred(pred_id)
> +            % If the argument types come from a plain call, then their source
> +            % should be "atas_pred(PredId)" where PredId is the callee.
> +    ;       atas_higher_order_call(prog_var)
> +            % If the argument types come from a higher order call, then
> +            % their source should be "atas_higher_order_call(Var)" where Var
> +            % is the higher-order variable being called.
> +    ;       atas_cons(cons_type_info_source)
> +            % If the argument types come from a ConsId, then their source
> +            % should be "atas_cons(ConsTypeInfoSource)", where
> +            % ConsTypeInfoSource is the description of the source of ConsId.
> +            %
> +            % Note that the ConsId may refer to a pred_id when the program
> +            % (tries to) partially apply a predicate or function.
> +    ;       atas_ensure_have_a_type.
> +            % If the argument types come from the compiler try to
> +            % ensure that a variable has *a* type, then the source should be
> +            % atas_ensure_have_a_type.
> +            %
> +            % Since ensure_var_has_a_type does not impose any expectations
> +            % on the type of a variable, while atas_ensure_have_a_type
> +            % may occur in args_type_assigns, it should *not* occur
> +            % in any args_type_assigns involved in argument type errors.
> +

s/ensure_var_has_a_type/ensure_vars_has_a_type

The diff looks fine.

Peter


More information about the reviews mailing list