Files
mercury/tests/invalid/merge_inst_error.m
Zoltan Somogyi f17f5635a3 Improve messages for inst merge errors.
compiler/mode_errors.m:
    Improve the error messages we generate when we find mismatches between
    a variable's insts in different branches.

    The first improvement is to replace clumsy wording such

        X has the non-ground instantiadness `free'

    with the shorter and simpler

        X is free

    when applicable.

    The second is to delete the text

        It has non-ground instantiation states in the following branches.

    when we print information about just one branch (because all the others
    ground the variable).

tests/invalid/merge_inst_error.m:
    Change the code to trigger the conditions for the second improvement.
    (The code already had the conditions for the first.)

tests/invalid/merge_inst_error.err_exp:
    Expect the updated error messages.
2018-10-17 13:16:25 +11:00

130 lines
2.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module merge_inst_error.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module list.
:- import_module string.
:- type t
---> ta
; tb
; tc
; td
; te(int)
; tf(int).
main(!IO) :-
test1(ta, !IO),
test2(tb, !IO),
test3(tf(10), !IO).
%---------------------------------------------------------------------------%
:- pred test1(t::in, io::di, io::uo) is det.
test1(T, !IO) :-
switch1(T, S),
io.write(T, !IO),
io.format(": %s\n", [s(S)], !IO).
:- pred switch1(t::in, string::out) is det.
switch1(T, S) :-
(
T = ta,
S = "ta"
;
T = tb
% S = "tb"
;
T = tc,
S = "tc"
;
T = td
% S = "td"
;
T = te(N),
S = "te" ++ string.int_to_string(N)
;
T = tf(N),
S = "tf" ++ string.int_to_string(N)
).
%---------------------------------------------------------------------------%
:- pred test2(t::in, io::di, io::uo) is det.
test2(T, !IO) :-
switch2(T, S),
io.write(T, !IO),
io.format(": %s\n", [s(S)], !IO).
:- pred switch2(t::in, string::out) is det.
switch2(T, S) :-
(
( T = ta, S = "ta"
; T = tb
)
% S = "tab"
;
T = tc,
S = "tc"
;
(
T = td,
S = "td"
;
T = te(N),
S = "te" ++ string.int_to_string(N)
)
;
T = tf(N),
S = "tf" ++ string.int_to_string(N)
).
%---------------------------------------------------------------------------%
:- pred test3(t::in, io::di, io::uo) is det.
test3(T, !IO) :-
switch3(T, S),
io.write(T, !IO),
io.format(": %s\n", [s(S)], !IO).
:- pred switch3(t::in, string::out) is det.
switch3(T, S) :-
(
( T = ta
; T = tb
),
S = "tab"
;
T = tc,
S = "tc"
;
(
T = td
% S = "td"
;
T = te(_N)
% S = "te" ++ string.int_to_string(N)
;
T = tf(_N)
% S = "tf" ++ string.int_to_string(N)
)
).
%---------------------------------------------------------------------------%