Repository navigation
Description
Summary
Patterns and joins treat a keyword constant as equal to a ref to the entity it names (:bob ≡ #uuid "<uuid5 of :bob>"). The comparison expressions = and != don't, so the same question gets different answers depending on how the query is written. The wrong answer comes back silently.
Repro
Verified on main (v2.0.10 line, origin/main) and on v3 (0f7c66c0), with the same answers on both:
(transact [[:alice :ref/friend #uuid "<uuid5 of :bob>"] ; a ref to :bob's entity
[:carol :kw/friend :bob]]) ; a keyword value
(query [:find ?x :where [?x :ref/friend :bob]]) ; 1 row (pattern constant: equal)
(query [:find ?x :where [?y :ref/friend ?g] [?x :kw/friend ?g]]) ; 1 row (join on ?g: equal)
(query [:find ?x :where [?x :ref/friend ?g] [(= ?g :bob)]]) ; 0 rows (expression: not equal)
(query [:find ?x :where [?x :ref/friend ?g] [(!= ?g :bob)]]) ; 1 row (expression: not equal)The last two should give 1 and 0 rows, matching the pattern and the join.
Cause
The engine's JoinKey (query/engine/join.rs) makes a keyword equal to a ref to the entity it names, for scans, joins, not bodies (#546) and or branches (#637). Expression evaluation (eval_expr, BinOp::Eq/Neq) compares the two Values directly, and Value::Keyword ≠ Value::Ref.
A related gap: an expression can't take a #uuid literal at all ([(= ?g #uuid "...")] is PRS-070), so in query text the keyword is the only way to compare a ref value to a constant. A prepared query can bind Val(Ref) (#181).
Fix direction
Make = and != compare as joins do: a keyword equals a ref to the entity it names. Whether </> on a keyword and a ref should stay a type mismatch needs deciding. A v2.x backport follows the support policy (data-integrity fixes are backported).
Found in passing while testing #181.
🤖 Generated with Claude Code
Activity
fix(query): expression = / != equate a keyword with a ref to its enti…
test(query): #744 in or branches, UUID keywords, set elements; test c…
fix(query): expression = / != equate a keyword with a ref to its enti…
fix(query): expression = / != equate a keyword with a ref to its enti…
test(query): #744 in or branches, UUID keywords, set elements; test c…
Merge pull request #748 from project-minigraf/fix/744-expr-keyword-ref
release: v2.0.11
adityamukho commentedon Oct 26, 2026
Fixed in v2.0.11, now published: https://github.com/project-minigraf/minigraf/releases/tag/v2.0.11. The v2.x fix shipped in #749; v3.0.0 is also fixed in #748. Updated the pinned known-issues list (#421).