Skip to content

Read the value of both arguments of =/2 separately - #199

Open
rmanhaeve wants to merge 1 commit into
yuce:masterfrom
rmanhaeve:fix-unifier-non-object-argument
Open

rmanhaeve wants to merge 1 commit into
yuce:masterfrom
rmanhaeve:fix-unifier-non-object-argument

Conversation

@rmanhaeve

@rmanhaeve rmanhaeve commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

A query that returns a term such as 1 = 1 raises an AttributeError:

>>> from pyswip import Prolog
>>> list(Prolog.query("X = [(1 = 1)]"))
AttributeError: 'int' object has no attribute 'value'

_unifier, the handler for =/2, reads args[0].value and args[1].value,
and falls back to the argument itself when it has no value. The fallback reads
args[0].value again, so it only recovers when the second argument has no
value. Any integer, float or string on the left of = raises in the fallback
as well.

This reads each argument on its own. Added a regression test, which fails
before the change and passes after it.

tests/test_issues.py::TestIssues::test_issue_15 fails on my machine both
before and after, so it looks unrelated.

🤖 Generated with Claude Code

The handler for =/2 reads the value of both arguments, and falls back to the
argument itself when it has none. The fallback reads the value of the first
argument again, so it only recovers when the second argument has no value.
A term such as 1 = 1 raises an AttributeError instead of being returned.

Read each argument on its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fie7FW6gwVcPBad7V9m5SM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant