diff --git a/pl/control.yap b/pl/control.yap index d2708b234..f753cdaec 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -66,9 +66,21 @@ setup_call_cleanup(Setup, Goal, Cleanup) :- setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup) :- yap_hacks:disable_interrupts, + '$check_goal_for_setup_call_cleanup'(Setup, setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup)), '$do_setup'(Setup), + '$check_goal_for_setup_call_cleanup'(Cleanup, setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup)), '$safe_call_cleanup'(Goal,Cleanup,Catcher,Exception). +'$check_goal_for_setup_call_cleanup'(Goal, G) :- + strip_module(Goal, _, MG), + ( + var(MG) + -> + '$do_error'(instantiation_error,G) + ; + true + ). + % this is simple, do nothing '$do_setup'(A:true) :- atom(A), !. % this is tricky: please don't forget that interrupts are disabled at this point