]> Repositorios git - scryer-prolog.git/commitdiff
improve goal expansion and (',') interpretation error handling
authorMark <[email protected]>
Thu, 20 Jul 2023 20:27:10 +0000 (14:27 -0600)
committerMark <[email protected]>
Thu, 20 Jul 2023 20:27:10 +0000 (14:27 -0600)
src/lib/builtins.pl
src/loader.pl

index 983503cbd3120b73beaa78e14d6ba40714ec2fda..81f63dddf1e6e50efa7bcf76e6942390f1eb1742 100644 (file)
@@ -334,6 +334,9 @@ dispatch_prep(Gs, B, [Cont|Conts]) :-
        ;  Gs0 == ! ->
           Cont = '$call'(builtins:set_cp(B)),
           Conts = []
+       ;  nonvar(Gs0),
+          \+ callable(Gs0) ->
+          throw(dispatch_prep_error)
        ;  Cont = Gs,
           Conts = []
        )
index 1eafedb0195d0c21ee28031d9c61c109d651ab32..441852eed3a431fb88dbd5bc47011bdec0091caa 100644 (file)
@@ -274,6 +274,13 @@ module_expanded_head_variables(Head, HeadVars) :-
     ).
 
 
+print_goal_expansion_warning(Pred) :-
+    nl,
+    write('Warning: clause body goal expansion failed because '),
+    writeq(Pred),
+    write(' is not callable.'),
+    nl.
+
 expand_term_goals(Terms0, Terms) :-
     (  Terms0 = (Head1 :- Body0) ->
        (  var(Head1) ->
@@ -282,13 +289,21 @@ expand_term_goals(Terms0, Terms) :-
           (  atom(Module) ->
              prolog_load_context(module, Target),
              module_expanded_head_variables(Head2, HeadVars),
-             expand_goal(Body0, Target, Body1, HeadVars),
+             catch(expand_goal(Body0, Target, Body1, HeadVars),
+                   error(type_error(callable, Pred), _),
+                   (  loader:print_goal_expansion_warning(Pred),
+                      builtins:(Body1 = Body0)
+                   )),
              Terms = (Module:Head2 :- Body1)
           ;  type_error(atom, Module, load/1)
           )
        ;  module_expanded_head_variables(Head1, HeadVars),
           prolog_load_context(module, Target),
-          expand_goal(Body0, Target, Body1, HeadVars),
+          catch(expand_goal(Body0, Target, Body1, HeadVars),
+                error(type_error(callable, Pred), _),
+                (  loader:print_goal_expansion_warning(Pred),
+                   builtins:(Body1 = Body0)
+                )),
           Terms = (Head1 :- Body1)
        )
     ;  Terms = Terms0
@@ -688,7 +703,10 @@ expand_subgoal(UnexpandedGoals, MS, M, ExpandedGoals, HeadVars) :-
 
 expand_module_name(ESG0, MS, M, ESG) :-
     (  var(ESG0) ->
-       ESG = M:ESG0
+       (  M == user ->
+          ESG = ESG0
+       ;  ESG = M:ESG0
+       )
     ;  ESG0 = _:_ ->
        ESG = ESG0
     ;  functor(ESG0, F, A0),
@@ -753,7 +771,6 @@ expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars) :-
     ).
 
 
-
 :- non_counted_backtracking expand_goal/3.
 
 expand_goal(UnexpandedGoals, Module, ExpandedGoals) :-