Files
mercury/tests/hard_coded/ho_solns.m
Zoltan Somogyi 80943c1142 Fix some Java/C# test case failures.
library/rtti_implementation.m:
    Return zero arity for null TypeInfo.args arrays. This fixes the
    failure of the hard_coded/pretty_printing test case in the Java grade,
    and probably in the C# grade as well.

tests/general/read_dir_regression.m:
    Fix the failure of the failure of this test case in the Java grade,
    by massaging the error message returned for an intentionally-failed
    open of a directory as a plain file. When opening ".", the error message
    (on my laptop, at least) returns the full absolute path name of the
    current directory. Since this will be different in different workspaces,
    we can't update the expected output file, but we can replace this
    changeable part of the error message with a fixed string. This diff
    does this.

tests/hard_coded/ho_solns.m:
    Add a note about the cause of the failure of this test case.

tests/hard_coded/string_code_point.exp2:
    Conform to the old switchover from the "codepoint" spelling
    to "code_point".
2025-09-04 23:44:40 +02:00

84 lines
2.3 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Test case for solutions
%
% Author: trd
%
% This test case exercises a number of features:
% - The ability to modecheck equivalence insts correctly (the
% Mercury compiler of Jan 20 1997 couldn't compile code like this;
% in fact if you made mypred == ground it still couldn't get it right).
% - Solutions of higher order predicates.
% - In non-conservative GC grades, deep_copy of closures (since solutions
% is implemented using deep copy on them).
% - Higher order syntax -- P(5, 1, X).
%
:- module ho_solns.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module int.
:- import_module list.
:- import_module solutions.
main(!IO) :-
unsorted_solutions(foo, List0),
convert_list(List0, List),
use_list(List, !IO).
:- type mypred == (pred(int, int, int)).
:- inst mypred == (pred(in, in, out) is det).
:- pred convert_list(list(T), list(mypred)).
:- mode convert_list(in, out(list_skel(mypred))) is det.
% XXX The Java implementation gets this error from the Java compiler:
% Mercury/javas/jmercury/ho_solns.java:211: error: incompatible types:
% List_1<Object> cannot be converted to List_1<Object[]>
% L = L0;
% ^
% That seems to be a problem with the test.
%
% I (zs) think it is very probable that the C# version has the same problem.
:- pragma foreign_proc("C",
convert_list(L0 :: in, L :: out(list_skel(mypred))),
[will_not_call_mercury, promise_pure],
"
L = L0;
").
:- pragma foreign_proc("C#",
convert_list(L0 :: in, L :: out(list_skel(mypred))),
[promise_pure],
"
L = L0;
").
:- pragma foreign_proc("Java",
convert_list(L0 :: in, L :: out(list_skel(mypred))),
[promise_pure],
"
L = L0;
").
:- pred use_list(list(mypred)::in(list_skel(mypred)), io::di, io::uo) is det.
use_list([], !IO).
use_list([P | Ps], !IO) :-
P(5, 1, X),
io.write_int(X, !IO),
io.write_string("\n", !IO),
use_list(Ps, !IO).
:- pred foo(mypred).
:- mode foo(out(mypred)) is multi.
foo(X) :- X = (pred(A::in, B::in, C::out) is det :- C = A + B).
foo(X) :- X = (pred(A::in, B::in, C::out) is det :- C = A * B).
foo(X) :- X = (pred(A::in, B::in, C::out) is det :- C = A - B).