Skip to content

Fix nested named-field patterns that use no inner field - #138

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/nested-named-field-pattern
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/nested-named-field-pattern

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

The README documents (;x=p) as "matches values with field x matching pattern p", and patterns nest. A named-field pattern nested inside another threw UndefVarError on every input when the inner pattern used none of the inner value's fields:

@match (a = (b = 5,),) begin
    (; a=(; b=_)) => 1      # ERROR: UndefVarError: `##input_value.a#287` not defined
    _ => 2
end

The same happens with an unused binding ((; a=(; b)) => 1), in @ismatch, and in @match pattern = value.

What changed

A named-field pattern first checks hasfield(typeof(input), :x). That check named the input temporary in its source but did not list it among the expression's inputs (its assignments). simplify, which removes fetches whose results are unused, therefore dropped the fetch of the nested value, and the check read a temporary that was never assigned. The check now lists input, so the fetch is kept. The decision automaton for the example above gains the missing FETCH «input_value.a» node.

No issue was filed. I found this with a differential test harness for @match (a small reference interpreter written from the README, compared on random patterns and values).

Verification

  • The new tests (first commit) throw UndefVarError on main and pass with the fix.
  • Pkg.test() on Julia 1.12.6: 1060 passed, 5 broken (main: 1057 passed, the same 5 broken).
  • All five fixes from this bug hunt applied together also pass on Julia 1.10.11 and 1.14.0-alpha2 (1090 passed each).
  • CI: every job passes except Julia 1.9 and 1.10.2, which stop before running tests on the current Ubuntu runner (libopenlibm.so: cannot enable executable stack). PR Fix @match on 32-bit Julia (hash seeds typed as UInt64) #134 shows the same failure; this PR does not touch CI.

Review notes

  • This is the only pattern that builds a guard expression around a temporary instead of a pattern variable. Every other temporary a test reads is either the test's input or listed in assignments.
  • Identical hasfield checks on the same value are still shared between cases, and the existing node-count tests are unchanged.

🤖 Generated with Claude Code

quinnj and others added 2 commits November 19, 2026 06:09
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hasfield guard for (; x=p) named the input temp directly in its
source without listing it in the guard's assignments. simplify therefore
dropped the fetch that computes a nested input when nothing else used it,
and (; a=(; b=_)) threw UndefVarError on every input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (f26639b) to head (8d0ffbd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #138   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files          12       12           
  Lines        1132     1133    +1     
=======================================
+ Hits         1125     1126    +1     
  Misses          7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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