-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2725 by calling load_context/1 in the unspecified branch of stri…
…p_module/3 This fixes #2725, by making it so that `strip_module(Pred, M, P), call(M:P)` doesn't throw an `instanciation_error` when `Pred` isn't in the form `module:predicate`. Now, `strip_module(hello, M, P)` will call `load_context(M)`, which unifies `M` with the topmost module (or `user`). Two new test cases are added: issue2725.pl, which tests the minimal case id(X) --> X. and the strip_module(P, M, _), call(M:P) scenario, and module_resolution, which tests the behavior of strip_module in a few scenarios.
- Loading branch information
Showing
9 changed files
with
96 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
:- module(module_resolution, [get_module/2]). | ||
|
||
get_module(P, M) :- strip_module(P, M, _). | ||
|
||
:- initialization((strip_module(hello, M, _), write(M), write('\n'))). | ||
:- initialization((loader:strip_module(hello, M, _), write(M), write('\n'))). | ||
:- initialization((get_module(hello, M), write(M), write('\n'))). | ||
:- initialization((module_resolution:get_module(hello, M), write(M), write('\n'))). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
:- module(issue2725, []). | ||
:- use_module(library(dcgs)). | ||
|
||
% Tests that the id/3 dcg can be called. | ||
% library(dcgs) currently expands it to id(X, Y, Z) :- phrase(X, Y, Z). | ||
id(X) --> X. | ||
call_id :- | ||
id("Hello", X, []), | ||
X = "Hello". | ||
:- initialization(call_id). | ||
|
||
test_default_strip_module :- | ||
strip_module(hello, M, P), | ||
nonvar(M), | ||
M = issue2725, | ||
nonvar(P), | ||
P = hello, | ||
strip_module(hello, issue2725, _), | ||
strip_module(hello, M, P). | ||
:- initialization(test_default_strip_module). | ||
|
||
% Tests that strip_module followed by call works with or without the module: prefix. | ||
strip_module_call(Pred) :- | ||
loader:strip_module(Pred, M, Pred0), | ||
call(M:Pred0). | ||
|
||
my_true. | ||
|
||
test_strip_module_call :- | ||
strip_module_call(my_true), | ||
strip_module_call(issue2725:my_true). | ||
:- initialization(test_strip_module_call). | ||
|
||
% :- initialization(loader:prolog_load_context(module, M), write(M), write('\n')). | ||
% :- initialization(loader:load_context(user)). |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module_resolution | ||
module_resolution | ||
module_resolution | ||
module_resolution | ||
user | ||
user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
args = [ | ||
"-f", | ||
"--no-add-history", | ||
"src/tests/module_resolution.pl", | ||
"-f", | ||
"-g", "use_module(library(module_resolution))", | ||
"-g", "get_module(some_predicate, M), write(M), write('\\n')", | ||
"-g", "module_resolution:get_module(some_predicate, M), write(M), write('\\n')", | ||
"-g", "halt" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters