mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
This fixes mantis bug 402.
compiler/prog_item.m:
Change the representation of require_complete_switch and
require_switch_arms_{det,semi,...} goals so that the switch variable
does not have to be a plain variable, but can also be the current value
of a state variable. (You can't switch on the future value.)
compiler/prog_io_goal.m:
When parsing the switched-on variable in these kinds of scopes,
allow the variable in the singleton list to be !.SV as well as a plain
variable.
compiler/goal_expr_to_goal.m:
Expand out the !.SV in these scopes if the switched-on variable
is of that form.
compiler/prog_io_util.m:
Change the return value of the predicate that parses both plain and
state vars to make the meaning of its return value more self-describing.
compiler/parse_tree_out_clause.m:
compiler/prog_util.m:
Conform to the change in prog_item.m.
tests/valid/bug402.m:
New regression test for the bug.
tests/valid/Mmakefile:
Enable the new test.
44 lines
875 B
Mathematica
44 lines
875 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et tw=0 wm=0 ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module bug402.
|
|
:- interface.
|
|
|
|
:- type foo
|
|
---> foo
|
|
; bar
|
|
; baaz.
|
|
|
|
:- pred convert_1(foo::in, foo::out) is semidet.
|
|
:- pred convert_2(foo::in, foo::out) is semidet.
|
|
|
|
:- implementation.
|
|
|
|
convert_1(!Value) :-
|
|
convert_2(!.Value, !:Value),
|
|
require_complete_switch [!.Value]
|
|
(
|
|
!.Value = foo,
|
|
!:Value = bar
|
|
;
|
|
!.Value = bar,
|
|
false
|
|
;
|
|
!.Value = baaz,
|
|
!:Value = foo
|
|
).
|
|
|
|
convert_2(!Value) :-
|
|
require_switch_arms_semidet [!.Value]
|
|
(
|
|
!.Value = foo,
|
|
!:Value = bar
|
|
;
|
|
!.Value = bar,
|
|
false
|
|
;
|
|
!.Value = baaz,
|
|
!:Value = foo
|
|
).
|