Skip to content

fix(python): avoid name collisions in nested tuple matches - #5027

Merged
dbrattli merged 1 commit into
mainfrom
fix/python-nested-match-names
Sep 30, 2026
Merged

dbrattli merged 1 commit into
mainfrom
fix/python-nested-match-names

Conversation

@dbrattli

Copy link
Copy Markdown
Collaborator

Why

Nested tuple matches can reuse an outer match's Python match_value binding, causing union-field access to read from the inner scrutinee and raise AttributeError. The same collision affects captured fields in closures and user bindings named match_value.

Fixes #5026.

How

Convert generated identifiers to Python naming before checking and reserving unique names. Add three regression tests covering nested matches, closures, and user bindings, including fallback branches and repeated closure calls.

Validation

  • All three regressions fail with the original compiler and pass with the fix.
  • ./build.sh test python --force-fable-library --type-check: 2,395 .NET tests and 2,485 Python tests passed with a freshly generated runtime.
  • Pyright diagnostics match unchanged main: 34 existing errors and 45 warnings, with no added errors and no errors in the regression file.
  • Release compiler build, compiler-source Fantomas check, and git diff --check passed.

@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli
dbrattli marked this pull request as ready for review September 30, 2026 17:50
@dbrattli
dbrattli merged commit ff71a8c into main Sep 30, 2026
44 checks passed
@dbrattli
dbrattli deleted the fix/python-nested-match-names branch September 30, 2026 17:50
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.

[Python] Nested match reuses the name match_value, so an outer case field is read from the inner value

1 participant