Files
mercury/tests/hard_coded/bug557.m
Zoltan Somogyi e144a91c83 Fix silent failure during module qualification.
This fixes Mantis bug #557.

compiler/module_qual.qualify_items.m:
    When module qualifying checked type, inst and mode definitions,

    - qualify the checked definition as appropriate to the module section
      where the definition's body is, and

    - do not discard any error messages generated by this process in favor of
      the error messages (if any) generated by qualifying the source
      definitions the checked definition was constructed from.

    The source of the Mantis #557 bug was that in a type definition,
    an argument type was (a) uniquely qualifiable in the interface section,
    but (b) was ambiguous in the implementation section, due to an extra
    module import being visible in the implementation section. The first
    change above fixes this bug. The second change is there to ensure that
    if we set the flag that says we found a non-uniquely-module-qualifiable
    type, inst or mode name, the error message we generate when we do that
    won't be discarded. The second change also means that such errors get
    two error messages generated for them, but since we always sort
    error_specs and any remove duplicates, this is not a problem.

tests/hard_coded/bug557.{m,exp}:
tests/hard_coded/bug557_helper.m:
    The test case for this bug, with a comment explaining the bug.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2022-04-11 13:37:41 +10:00

51 lines
2.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
:- module bug557.
:- interface.
:- import_module io.
:- type record
---> record(
% This type is NOT ambiguous in the interface section
% (because the only type named "ambiguous_type" available
% in the interface is the one defined in this interface),
% but it *would* be ambiguous in the implementation section
% (because of the import of bug557_helper.ambiguous_type
% there).
%
% Mantis bug #557 was caused by the fact that
% module_qualify_type_ctor_checked_defn always module qualified
% the checked definitions of types (such as record) as if
% they were in the implementation section. This caused this
% reference to ambiguous_type to set the "we found a type
% that could not be uniquely qualified" flag. However,
% module_qualify_type_ctor_checked_defn threw away the
% error message generated for this, because it was about
% to module qualify the original type definitions from which
% the checked type definition was constructed, and it did not
% want duplicate error messages. However, the qualification
% of the original type definition (this one) did not find
% any ambiguity, and thus did not generate an error message.
% The flag caused compilation to stop without further message
% when it reached the frontend_pass predicate.
ambiguous_type :: ambiguous_type
).
:- type ambiguous_type
---> a
; b.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module bug557_helper.
main(!IO) :-
io.write_string("Successful compilation.\n", !IO).