Fix #2725 by calling load_context/1 in the unspecified branch of strip_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.
This commit is contained in:
Emilie Burgun
2025-01-01 17:27:40 +01:00
parent 1ed4fe6555
commit b76bdd75e4
9 changed files with 88 additions and 14 deletions

View File

@@ -0,0 +1,6 @@
module_resolution
module_resolution
module_resolution
module_resolution
user
user

View File

@@ -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"
]

View File

@@ -33,3 +33,13 @@ fn call_qualification() {
fn load_context_unreachable() {
load_module_test("tests-pl/load-context-unreachable.pl", "");
}
// Issue #2725: A dcg of the form `id(X) --> X.` would previously trigger an instantiation
// error, as it would call `strip_module(X, M, P)` and later `call(M:P)`,
// but `strip_module` left `M` uninstanciated if the `module:` prefix was unspecified.
#[serial]
#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn issue2725_dcg_without_module() {
load_module_test("tests-pl/issue2725.pl", "");
}