mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 21:03:53 +00:00
Estimated hours taken: 8 Clean up the handling of unbound type variables. Fix a bug with unbound type variables in lambda expressions. Run purity analysis, modechecking etc. even if there were type errors. compiler/mercury_compile.m: Run purity analysis, modechecking etc. even if there were type errors. This fixes a bug (inconsistency between the code and the comments) that seems to have been introduced in stayl's change to mercury_compile.m (revision 1.25) to add intermodule unused argument elimination: the comment said "continue, even if type checking found errors", but the code did not continue. This change was needed to ensure that we still report a warning message about unused type variables for tests/invalid/error2.m; without it, we stop after type checking and don't do purity analysis, and so don't report the warning. compiler/typecheck.m: compiler/purity.m: Move the code for checking for unbound type variables from typecheck.m to purity.m. It needs to be done *after* type inference has been completed, so it can't be done in the ordinary type checking/inference passes. Add code to purity.m to bind the unbound type variables to the builtin type `void'. compiler/polymorphism.m: Comment out old code to bind unbound type variables to `void'; the old code was incomplete, and this is now done in purity.m. compiler/notes/compiler_design.html: Document the above changes. tests/valid/Mmakefile: tests/valid/unbound_tvar_in_lambda.m: Regression test for the above-mentioned bug with unbound type variables in lambda expressions. tests/warnings/singleton_test.exp: tests/invalid/errors2.err_exp: Change the expected warning message for unbound type variables. The error context is not as precise as it used to be, I'm afraid: we only know which function/predicate the error occurred in, not which clause. Also it now comes out in a different order relative to the other error messages. tests/invalid/errors2.err_exp: tests/invalid/funcs_as_preds.err_exp: Add some new error/warning messages that are output now that we run mode and determinism analysis even if there are type errors.
41 lines
1.1 KiB
Mathematica
41 lines
1.1 KiB
Mathematica
:- module unbound_tvar_in_lambda.
|
|
:- interface.
|
|
:- import_module io.
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
:- implementation.
|
|
:- import_module list, int, std_util, require.
|
|
|
|
%--------------------------------------------------------%
|
|
|
|
:- type node(S, T)
|
|
---> append(list(S), list(S), list(S)).
|
|
|
|
:- type proof(N)
|
|
---> node(N, proof(N))
|
|
; assumed.
|
|
|
|
:- type proof(S, T) == proof(node(S, T)).
|
|
|
|
%--------------------------------------------------------%
|
|
|
|
% Simple polymorphic examples
|
|
|
|
:- pred append_w(list(S), list(S), list(S), proof(S, T)).
|
|
:- mode append_w(in, in, out, out) is det.
|
|
:- mode append_w(out, out, in, out) is multi.
|
|
|
|
append_w([], Bs, Bs, node(append([], Bs, Bs), assumed)).
|
|
append_w([A|As], Bs, [A|Cs], node(append([A|As], Bs, [A|Cs]), Proof)) :-
|
|
append_w(As, Bs, Cs, Proof).
|
|
|
|
|
|
%--------------------------------------------------------%
|
|
|
|
main -->
|
|
write_string("--- Start Proofs ---\n\n"),
|
|
{ Pred = (pred(P1::out) is nondet :-
|
|
append_w([1,2,3,4], [5,6,7], _, P1)) },
|
|
io__write(Pred),
|
|
write_string("--- End Proofs ---\n\n").
|
|
|