diff --git a/src/loader.pl b/src/loader.pl index 44926aba9..54a03e919 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -844,6 +844,12 @@ UnexpandedGoals = ExpandedGoals), !. +module_instantiated(M, EM) :- + ( var(M) -> + EM = user + ; M = EM + ). + :- non_counted_backtracking expand_goal/5. expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars, TGs) :- @@ -856,9 +862,10 @@ ), ( expand_goal_cases(Goals, Module, ExpandedGoals, HeadVars, TGs) -> true - ; predicate_property(Module:Goals, meta_predicate(MetaSpecs0)), + ; module_instantiated(Module, InstantiatedModule), + predicate_property(InstantiatedModule:Goals, meta_predicate(MetaSpecs0)), MetaSpecs0 =.. [_ | MetaSpecs] -> - expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars, TGs) + expand_module_names(Goals, MetaSpecs, InstantiatedModule, ExpandedGoals, HeadVars, TGs) ; thread_goals(Goals, ExpandedGoals, (',')) ; Goals = ExpandedGoals ) @@ -886,14 +893,16 @@ UnexpandedGoals = ExpandedGoals ; goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1), ( Module \== user -> - goal_expansion(UnexpandedGoals1, user, Goals), - ( predicate_property(Module:Goals, meta_predicate(MetaSpecs0)), - MetaSpecs0 =.. [_ | MetaSpecs] -> - expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, [], []) - ; ExpandedGoals = Goals - ) - ; ExpandedGoals = UnexpandedGoals1 + goal_expansion(UnexpandedGoals1, user, Goals) + ; Goals = UnexpandedGoals1 + ), + module_instantiated(Module, InstantiatedModule), + ( predicate_property(InstantiatedModule:Goals, meta_predicate(MetaSpecs0)), + MetaSpecs0 =.. [_ | MetaSpecs] -> + expand_module_names(Goals, MetaSpecs, InstantiatedModule, ExpandedGoals, [], []) + ; ExpandedGoals = Goals ) + ; ExpandedGoals = UnexpandedGoals1 ). :- non_counted_backtracking transitive_goal/3.