Files
mercury/tests/valid/constrained_poly_bound_arg.m
Zoltan Somogyi e64210c2b0 Add more diagnostics to inst_mode_type_prop.m.
compiler/inst_mode_type_prop.m:
    This module used to check for only one kind of error:
    an inst name that was declared as being for a given type_ctor
    being applied to a value of a type whose principal type_ctor
    is not the declared one. Add tests for other incompatibilities
    between the inst and the type it is applied to:

    - a cons_id in a bound inst having a module qualifier that is
      incompatible with the module qualification of the type_ctor;

    - a cons_id in a bound inst not being a data constructor
      in the type_ctor;

    - a higher order inst being applied to a non-higher-order type, and

    - a higher order inst being applied to a higher-order type of the
      wrong arity.

    To make it possible to generate well-formatted error messages, especially
    for the last two kinds of errors, pass around the traversals not just
    the module_info, but also the type- and inst-varsets that specify the
    names of the type and inst vars in the types and insts. To do this
    without excessive argument passing, group all three into a single
    structure, and make this structure the fourth type in the main typeclass
    of this module.

compiler/types_into_modes.m:
    Conform to the changes in inst_mode_type_prop.m.

compiler/error_msg_inst.m:
    To make possible the proper formatting of one of the new diagnostics
    in inst_mode_type_prop.m, add an extra parameter to the error_msg_inst
    function (and to its error_msg_inst_name cousin): the prefix to use when
    choosing to format an inst to fit all on one line. For all previous
    callers of this function, there was no prefix required, but now there is.

compiler/add_mutable_aux_preds.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_inst_table.m:
compiler/mode_errors.m:
    Conform to the change in error_msg_inst.m.

tests/hard_coded/curry.m:
tests/hard_coded/ho_solns.m:
tests/valid/constrained_poly_bound_arg.m:
tests/valid/constrained_poly_insts.m:
    Fix code that has been broken all along, we just lacked the diagnostics
    to report it :-(

tests/invalid/type_prop_into_inst.{m,err_exp}:
    Add a new test case, containing the old, incorrect code in the above
    test cases, to test the new diagnostics.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
    Expect one of the new diagnostics in addition to the existing ones.

tests/invalid/qualified_cons_id2.err_exp:
    Expect one of the new diagnostics in addition to some of existing ones.
    Do not expect two old diagnostics. One reported the same problem that
    the new diagnostic reports, but in a very confusing way: it reported
    that yes(ground) cannot be unified with yes(_), which is nonsense;
    the new diagnostic reports the actual problem, which is that the code
    tried to apply an inst that specified qualified_cons_id2.yes(...) to
    a term of type maybe.yes(...) (i.e. the bug was a disagreement over
    module qualification.) The other old diagnostics we don't get anyone
    is a consequence of the fact that we now report the bug earlier, and
    this makes the compiler stop before determinism analysis.
2024-05-01 20:12:42 +10:00

39 lines
949 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module constrained_poly_bound_arg.
:- interface.
:- type val_closure(X1)
---> val_closure(pred(X1)).
:- type closure_list(X2)
---> nil
; list(X2, val_closure(closure_list(X2))).
:- inst val_closure(X3) ==
bound(constrained_poly_bound_arg.val_closure(pred(out(X3)) is det)).
:- inst closure_list(X4) ==
bound(
constrained_poly_bound_arg.nil
;
constrained_poly_bound_arg.list(X4, val_closure(closure_list(X4)))
).
:- implementation.
:- pred eval(X5, X5).
:- mode eval(in(X6 =< ground), out(X6 =< ground)) is det.
eval(X, X).
:- pred m(closure_list(X8), closure_list(X8)).
:- mode m(in(closure_list(X9 =< ground)), out(closure_list(X9 =< ground)))
is det.
m(CCL, RCL) :-
eval(CCL, RCL).