Files
mercury/tests/invalid/bug410.m
Zoltan Somogyi d584cbb893 Prevent a syntax error from causing a compiler abort.
This fixes mantis bug #410.

compiler/modes.m:
    The reason why the old compiler used to get a compiler abort was that
    while doing mode inference on one procedure of a predicate (e.g. proc_id 0
    of make_titles in bug410.m below), we could add a new mode (procedure)
    to that predicate (proc_id 1 of make_titles), but when we finished
    the mode inference on the original procedure (proc_id 0), we updated
    its proc_info in the OLD pred_info, the one that did not have proc_id 1
    added to it yet. This effectively undid the addition of proc_id 1.
    However, the request to modecheck proc_id 1 was left unaffected.
    When the compiler came around to act on it, its lookup of proc_id 1
    aborted the compiler.

    The fix is to put the updated proc_info back into a version of the
    pred_info that we look up fresh, so we get all the updates done to it.

compiler/unify_proc.m:
    Fix a comment.

tests/invalid/bug410.{m,err_exp}:
    The regression test for the bug.

tests/invalid/Mmakefile:
    Enable the regression test case.
2017-06-17 02:55:30 +02:00

68 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
%
% This program causes the compiler (rotd-2016-06-09) to abort with the
% following:
%
% Uncaught Mercury exception:
% Software Error: map.lookup: key not found
% Key Type: int
% Key Value: 1
% Value Type: hlds.hlds_pred.proc_info
%
%---------------------------------------------------------------------------%
:- module bug410.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module bool.
:- import_module char.
:- import_module int.
:- import_module list.
:- import_module maybe.
:- import_module random.
:- import_module solutions.
:- import_module string.
:- import_module time.
%---------------------------------------------------------------------------%
main(!IO) :-
Gen = gen(0),
make_titles(Gen, [], _ : list(string)).
%---------------------------------------------------------------------------%
:- type generator == pred(maybe(string), list(string), list(string)).
:- inst generator == (pred(out, in, out) is det).
% There is a closing parenthesis missing here.
% -------------------------------------+
% v
:- pred make_titles(generator::in(generator,
list(string)::in, list(string)::out) is det.
make_titles(GenPred, !Used) :-
GenPred(_MaybeTitle, !Used),
make_titles(GenPred, !Used).
:- pred gen(int::in, bool::out, list(string)::in, list(string)::out) is det.
gen(_, MaybeTitle, !Used) :-
MaybeTitle = yes.
%---------------------------------------------------------------------------%
:- end_module bug410.
%---------------------------------------------------------------------------%