Files
mercury/tests/hard_coded/stream_put_bug.m
Zoltan Somogyi add253af9f Fix compiler abort looking for stream.put (Mantis bug 369).
compiler/module_imports.m:
    Implicitly import stream.m if the module being compiled may call
    stream.string_writer.format.

compiler/simplify_proc.m:
    Keep stream.put around until format_call.m may need it.

compiler/pred_table.m:
    If looking for a predicate fails, generate an error message that mentions
    the module name part of the fully qualified predicate name being
    looked for.

tests/hard_coded/stream_put_bug.{m,exp}:
    New test case, based on one contributed by sebgod (the filer of
    Mantis bug 369).

tests/hard_coded/Mmakefile:
    Enable the new test case.
2014-12-16 10:12:19 +11:00

36 lines
1017 B
Mathematica

% vim: ts=4 sw=4 expandtab ft=mercury
%
% This is a regression test for Mantis bug #369.
%
% The bugs were that (a) for a module like this one, which calls
% stream.string_writer.format but does not *explicitly* import stream.m,
% the compiler did not *implicitly* import stream.m, and (b) it also
% did not protect stream.put from being deleted by dead predicate elimination.
:- module stream_put_bug.
:- interface.
:- import_module io.
:- interface.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list.
:- import_module string.
:- use_module stream.string_writer.
:- use_module string.builder.
main(!IO) :-
some [!State] (
!:State = string.builder.init,
stream.string_writer.format(string.builder.handle,
"answer to life universe everything %d\n", [i(42)], !State),
stream.string_writer.format(string.builder.handle,
"bug %s\n", [s("not present")], !State),
io.write_string(string.builder.to_string(!.State), !IO)
).