scryer-prolog
scryer-prolog copied to clipboard
Fix: Handle empty list in term_expansion/2 to remove terms without warnings
Problem
When term_expansion/2 returns an empty list [], Scryer was treating it as a term to compile, resulting in discontiguous warnings:
Warning: overwriting []/0 because the clauses are discontiguous
Example
term_expansion((:- start_debug), []).
:- start_debug. % This would cause a warning
foo(1).
:- start_debug. % Another warning here
foo(2).
Solution
Modified src/loader.pl to handle empty list specially:
-
In
expand_term/2: Explicitly check for[]and pass it through without recursion -
In
compile_term/2: Skip compilation whenTerms == [](do nothing)
New Semantics
-
term_expansion(Term, [])→ remove the term completely (no compilation) -
term_expansion(Term, [NewTerm])→ replace with single term -
term_expansion(Term, [T1, T2, ...])→ replace with multiple terms
This allows term_expansion/2 to act as a filter that can completely remove terms from compilation, which is a common and useful metaprogramming pattern.
Tests
Following the three-layer testing approach:
-
Layer 2 (Prolog Integration):
src/tests/term_expansion_empty_list.pl- 5 comprehensive tests -
Layer 3 (CLI):
tests/scryer/cli/src_tests/term_expansion_empty_list.toml- End-to-end test
All tests pass:
- ✅ 71 Rust unit tests
- ✅ 5 new Prolog integration tests
- ✅ New CLI test
- ✅ No regressions
Related Issues
Fixes #2623
Awesome catch, thank you a lot!
@hurufu, I would greatly appreciate if you could take a look at this, thank you a lot!