mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +00:00
compiler/state_var.m:
When replacing the argument terms !.X or !:X with a reference to
the relevant instance of the state var, make the updated form of
the argument inherit its context from the original form.
The dummy context we used to use would lead to a misleading context
in any error message about that argument.
compiler/superhomogeneous.m:
Fix an unrelated problem I came across while tracking down the above bug.
The problem was that we used to tell people that lambda expressions
had to have the form "<lambda head> :- <lambda body>", even if the
malformed lambda expression had "-->" as its top functor, i.e. if it
used DCG syntax.
Simplify a comment.
tests/invalid/bad_statevar_bad_context.{m,err_exp}:
A new test case for the state var bug above.
tests/invalid/Mmakefile:
Enable the new test case.
37 lines
1.0 KiB
Mathematica
37 lines
1.0 KiB
Mathematica
|
|
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module bad_statevar_bad_context.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred test_pred(int::in, int::in, io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module float.
|
|
:- import_module int.
|
|
|
|
:- type t
|
|
---> f(int, int, float).
|
|
|
|
test_pred(A, !.B, !IO) :-
|
|
q(!B),
|
|
% The !.A is a reference to a nonexistent state variable.
|
|
% The bug we are testing for is that this used to cause state_var.m
|
|
% to leave the context of the second arg of f initialized to the
|
|
% dummy context, which typecheck.m then replaced with the context
|
|
% of the clause as a whole, which is the context of the clause head.
|
|
% The type error in the unification with T was thus reported
|
|
% with the context of the clause head, which is quite confusing.
|
|
T = f(!.B, A, !.A),
|
|
io.write_line(T, !IO).
|
|
|
|
:- pred q(int::in, int::out) is det.
|
|
|
|
q(A, A).
|