AIGEN: Fix #988: Forbid underscore-prefixed variable values#1076
Open
AIGEN: Fix #988: Forbid underscore-prefixed variable values#1076
Conversation
Underscore-prefixed variables in overlapping patterns cause segfaults and incorrect results due to a binding collision in match lowering. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The ? operator desugars to a match expression that binds the inner value to a temporary variable. This variable was named `__x` which starts with underscore. Rename to `!x` to follow the compiler temp variable convention and avoid triggering the underscore-prefixed variable restriction. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When pattern matching on fields with underscore prefix (e.g., _value_name), use explicit binding syntax `_value_name => value_name` to bind the value to a non-underscore variable name. This allows the value to be used while avoiding the underscore-prefixed variable restriction. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Don't bind underscore-prefixed variables (_x, _y, etc.) in pattern matching. They are still allowed in patterns but act as wildcards, so reading their value triggers the existing "You cannot use a variable that starts with _" error. This fixes issue #988 where overlapping patterns with _x-style variables caused binding collisions in the lowering phase, resulting in segfaults or incorrect results. Changes: - check_locals_pattern: Skip binding for is_wildcard_name variables - bind_pattern_name: Use startsWith("_") for duplicate checking - Enable the repro test from tests/todo/ in tests/syntax/invalid/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Defense in depth: when lowering match expressions, treat any binding whose name starts with _ as an underscore binding (not just exact "_"). This prevents creating bindings for _x-style variables during match lowering, complementing the fix in skipNaming.sk. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
_no longer bind in patterns (they act as wildcards)_-prefixed variable value produces a clear error message_field => var) if you need the valueTest plan
tests/syntax/invalid/under_ident_3make STAGE=1Fixes #988
🤖 Generated with Claude Code