Files
mercury/tests/invalid/bad_end_module.m
Zoltan Somogyi 000fa27bbb Report errors for bad :- end_module declarations.
Until this diff, the compiler used to crash on such inputs, as mentioned
by Mantis bugs 41, 62 and 268.

compiler/prog_io.m:
    When reading in :- module and :- end_module items, we used to blindly
    believe what they said. We now check whether they make sense, and report
    a fatal error if they don't. Specifically,

    - if the name of the module started by a :- module declaration is
      qualified, that qualification has to match the name of the
      previously-current module, and

    - the name of the module ended by a :- end_module declaration
      has to match the name of the previously-current module.

    Simplify the code we used to use to remove the :- module/:- end_module
    wrappers around the top level module. The root of the problem used
    to be that this code used to let a malformed item list through to be
    processed by later compiler passes, which did not expect it.
    The reason WHY it let through malformed item lists seems to be
    the loosening of the checks in this code, more than a decade ago.
    This was done to account for the possibility that the final :- end_module
    in a file's item list is for a submodule of the main module, and not
    for the main module itself.

    Simplify the code for reading in the whole item list. Previously
    this was done by two mutually-recursive predicates, one of which
    read in a term for the next item and one which had the term handed
    to it by its caller. We now handle the two cases (one of which is
    needed only by the special handling required by the first item)
    in one self-recursive predicate with a maybe argument.

mdbcomp/prim_data.m:
    Add a utility predicate for use by the new code in prog_io.m.

    Remove a comment on code that duplicates the code on the declaration.

compiler/modules.m:
    Improve some code that handles lists of items.

    - Make some previously not-tail-recursive predicates tail recursive.
    - Give some predicates and variables more meaningful names.
    - Combine some checks where this allows us to reduce the number of
      traversals over the item list.

doc/reference_manual.texi:
    Fix bad punctuation, and expand the list of things
    that can be declared but not defined.

tests/invalid/bad_end_module.{m,err_exp}:
    Test the expected output.

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

tests/hard_coded/sub-module/g12_fe_bug.m:
    Fix a typo in a comment.
2014-09-02 00:13:03 +02:00

20 lines
563 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
:- module bad_end_module.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.write_line("hello world", !IO).
%---------------------------------------------------------------------------%
:- end_module bad_end_module_different_name.
%---------------------------------------------------------------------------%