Conversation
Assigning through a ref-conditional, (cond ? ref a : ref b) = value, was emitted without the parentheses, so it re-parsed as cond ? ref a : (ref b = value) and failed to compile (CS8156 / CS0201). The target was only parenthesized above assignment precedence, but a conditional binds tighter than assignment, so the check let it through. Require the assignment target to have precedence above the conditional operator. Ordinary lvalues (locals, fields, indexers) are primary expressions and are unaffected; the postfix ++ form already parenthesized correctly via unary precedence. Covers plain and compound assignments alike. Assisted-by: Claude:claude-opus-4-8:Claude Code
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.
Assigning through a ref-conditional was emitted without parentheses:
Without them the statement re-parses as
c ? ref a : (ref b = 3), which is neither a valid expression statement nor a legal assignment to a ref-returning conditional branch.VisitAssignmentExpressioninInsertParenthesesVisitorparenthesized the target only above assignment precedence, on the grounds that assignment is right-associative. A conditional binds tighter than assignment, so a ref-conditional target cleared that bar and lost its parentheses. The target now has to have precedence above the conditional operator.Ordinary lvalues are unaffected: locals, fields, array accesses and indexers are primary expressions, well above
?:. The postfix++form already came out right, becauseUnaryOperatorExpressionparenthesizes its operand at unary precedence.TestCases/Pretty/RefLocalsAndReturns.cscovers plain assignment, compound assignment and the postfix increment:Full
ICSharpCode.Decompiler.Testsrun: 3546 passed, 0 failed, 45 skipped.🤖 Generated with Claude Code