fix: resolve case-insensitive lookups of keys holding false - #368
Merged
Conversation
`case_insensitive_scan/2` was built on `Enum.find_value/3`, which treats a
falsy callback return as "no match". A key that matched case-insensitively
but held `false` therefore fell through to the `{:not_found, _}` sentinel
and evaluated to `nil`.
Wrapping matches in an `{:ok, value}` tuple keeps the callback's return
truthy regardless of the value, so `false` now resolves correctly.
Note that this affects exact-case lookups too, not just mismatched ones:
the parser lowercases variable names in the AST, so every attribute lookup
reaches this scan rather than the `Map.fetch/2` fast path.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Santiago <santiagocardo80@gmail.com>
smn
approved these changes
Jul 31, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Looking up a context key whose value is
falsereturnednil:case_insensitive_scan/2was built onEnum.find_value/3, which treats a falsycallback return as "no match". When the matching key held
false, the scan keptgoing, found nothing else, and returned the
{:not_found, _}sentinel — whichhandle_not_found/1then converted tonil.This is not limited to case-mismatched lookups. The parser lowercases variable
names in the AST, so every attribute lookup reaches this scan rather than the
Map.fetch/2fast path —@parsed.isActivewas equally broken.Fix
Wrap matches in an
{:ok, value}tuple so the callback's return is truthyregardless of the value, then unwrap.
Scope
falseis the only value affected in practice.0,[], and""are truthy inElixir and always worked.
nilhits the same path internally, but isindistinguishable from a missing key through the public API since both yield
nil.Tests
Four tests added to
test/expression_test.exs. Reverting the fix fails them.false, asserted across three casingsfalsefalseused downstream (==,evaluate_as_boolean!,IF, string output)🤖 Generated with Claude Code