mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Report an error if the first argument of a `some' goal
Estimated hours taken: 0.75 Report an error if the first argument of a `some' goal is not a list of variables. compiler/prog_io.m: compiler/prog_io_util.m: Move `parse_list_of_vars' from prog_io.m to prog_io_util.m. compiler/prog_io_goal.m: Check to make sure that the first argument to a some goal is a list of variables. (If not, we don't report an error here -- the error will be reported by typecheck.m.) compiler/typecheck.m: Report an proper error message if there is a call to an undefined predicate `some/2'. Also add `some/2' and `all/2' to the list of language builtins for which we report a special error message if they occur as undefined function symbols. tests/invalid/Mmakefile: tests/invalid/some.m: tests/invalid/some.err_exp: Regression test for the above change.
This commit is contained in:
@@ -42,6 +42,14 @@
|
||||
:- pred add_context(maybe1(item), term__context, maybe_item_and_context).
|
||||
:- mode add_context(in, in, out) is det.
|
||||
|
||||
%
|
||||
% Various predicates to parse small bits of syntax.
|
||||
% These predicates simply fail if they encounter a syntax error.
|
||||
%
|
||||
|
||||
:- pred parse_list_of_vars(term, list(var)).
|
||||
:- mode parse_list_of_vars(in, out) is semidet.
|
||||
|
||||
:- pred convert_mode_list(list(term), list(mode)).
|
||||
:- mode convert_mode_list(in, out) is semidet.
|
||||
|
||||
@@ -51,9 +59,6 @@
|
||||
:- pred convert_inst_list(list(term), list(inst)).
|
||||
:- mode convert_inst_list(in, out) is semidet.
|
||||
|
||||
% Parse an inst.
|
||||
% Fails on syntax errors.
|
||||
%
|
||||
:- pred convert_inst(term, inst).
|
||||
:- mode convert_inst(in, out) is semidet.
|
||||
|
||||
@@ -102,6 +107,11 @@
|
||||
add_context(error(M, T), _, error(M, T)).
|
||||
add_context(ok(Item), Context, ok(Item, Context)).
|
||||
|
||||
parse_list_of_vars(term__functor(term__atom("[]"), [], _), []).
|
||||
parse_list_of_vars(term__functor(term__atom("."), [Head, Tail], _), [V|Vs]) :-
|
||||
Head = term__variable(V),
|
||||
parse_list_of_vars(Tail, Vs).
|
||||
|
||||
convert_mode_list([], []).
|
||||
convert_mode_list([H0|T0], [H|T]) :-
|
||||
convert_mode(H0, H),
|
||||
|
||||
Reference in New Issue
Block a user