diff --git a/library/term_io.m b/library/term_io.m index 420fd6656..15fa9b4f1 100644 --- a/library/term_io.m +++ b/library/term_io.m @@ -2,7 +2,7 @@ % vim: ft=mercury ts=4 sw=4 et %---------------------------------------------------------------------------% % Copyright (C) 1994-2006, 2009, 2011-2012 The University of Melbourne. -% Copyright (C) 2014-2025 The Mercury team. +% Copyright (C) 2014-2026 The Mercury team. % This file is distributed under the terms specified in COPYING.LIB. %---------------------------------------------------------------------------% % @@ -494,7 +494,7 @@ write_term_nl(OutStream, VarSet, Term, !IO) :- format_term_nl(Stream, VarSet, Term, !State) :- OpTable = init_mercury_op_table, - format_term_with_op_table(Stream, OpTable, VarSet, Term, !State). + format_term_nl_with_op_table(Stream, OpTable, VarSet, Term, !State). %---------------------% diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile index 7de674c8b..34ae53c32 100644 --- a/tests/hard_coded/Mmakefile +++ b/tests/hard_coded/Mmakefile @@ -170,6 +170,7 @@ ORDINARY_PROGS = \ foreign_type_1 \ foreign_type_2 \ foreign_type_3 \ + format_term_nl \ frameopt_pragma_redirect \ free_free_mode \ from_ground_term_bug \ diff --git a/tests/hard_coded/format_term_nl.exp b/tests/hard_coded/format_term_nl.exp new file mode 100644 index 000000000..53cdf1e93 --- /dev/null +++ b/tests/hard_coded/format_term_nl.exp @@ -0,0 +1 @@ +PASSED diff --git a/tests/hard_coded/format_term_nl.m b/tests/hard_coded/format_term_nl.m new file mode 100644 index 000000000..17f08d177 --- /dev/null +++ b/tests/hard_coded/format_term_nl.m @@ -0,0 +1,56 @@ +%---------------------------------------------------------------------------% +% vim: ft=mercury ts=4 sw=4 et +%---------------------------------------------------------------------------% +% Regression test for bug with term_io.format_term_nl/5 in rotd-2026-02-19 +% and before where the terminating ".\n" was not being appended to the term. +%---------------------------------------------------------------------------% + +:- module format_term_nl. +:- interface. + +:- import_module io. + +:- pred main(io::di, io::uo) is det. + +%---------------------------------------------------------------------------% +%---------------------------------------------------------------------------% + +:- implementation. + +:- import_module bool. +:- import_module integer. +:- import_module list. +:- import_module string. +:- import_module string.builder. +:- import_module term. +:- import_module term_context. +:- import_module term_int. +:- import_module term_io. +:- import_module varset. + +%---------------------------------------------------------------------------% + +main(!IO) :- + varset.init(VarSet : varset(generic)), + Args = [ + term.functor(term.atom("bar"), [], dummy_context), + term_int.int_to_decimal_term(42, dummy_context) + ], + Term = term.functor(term.atom("foo"), Args, dummy_context), + + State0 = string.builder.init, + term_io.format_term_nl(string.builder.handle, VarSet, Term, + State0, State), + String = string.builder.to_string(State), + + ( if string.suffix(String, ".\n") then + io.print_line("PASSED", !IO) + else + io.print_line("FAILED", !IO), + io.print_line(String, !IO), + io.nl(!IO) + ). + +%---------------------------------------------------------------------------% +:- end_module format_term_nl. +%---------------------------------------------------------------------------%