Skip to content

parser: simplify VisitBinary - #86

Merged
rameel merged 3 commits into
mainfrom
parser/simplify-visit-binary
Nov 24, 2026
Merged

rameel merged 3 commits into
mainfrom
parser/simplify-visit-binary

Conversation

@rameel

@rameel rameel commented Nov 24, 2026

Copy link
Copy Markdown
Owner

VisitBinary resolved the operator factory before the switch, so the result was unused for ?? and the string + operator, and ResolveBinaryOperatorFactory kept an entry for ?? only for that call. The operands of && and || and the condition of ?: were converted to bool by the same three steps: ApplyImplicitConversion, a null check, and MissingImplicitConversion.

This PR resolves the factory after the switch, removes the ?? entry, and orders the remaining entries by precedence. The factory is still resolved outside the try block, so an unknown operator in a hand-built Expr.Binary keeps failing with NotSupportedException. The conversion to bool moves to ApplyBooleanConversion.

One error message changes: it now names the type of the operand after the null literal conversion. This matters only for the null literal on the left of && or || with an operand of a nullable value type on the right. null && NullBool now reports System.Nullable`1[System.Boolean] instead of System.Object, the same as NullBool && null. A test covers the new message. Expression trees and other error messages are unchanged.

VisitBinary resolved the factory before the switch, so the result was
unused for ?? and the string + operator, and ResolveBinaryOperatorFactory
kept an entry for ?? only because of that. Resolve the factory after the
switch, still outside the try block, so that an unknown operator keeps
failing with NotSupportedException, and remove the ?? entry. Order the
remaining entries by precedence. No behavior change.
The operands of && and || and the condition of ?: were converted to
bool by the same steps: ApplyImplicitConversion, a null check, and
MissingImplicitConversion. Move them to ApplyBooleanConversion.

The error now names the type of the operand after the null literal
conversion rather than before it. The two differ only for the null
literal on the left of && or || with an operand of a nullable value
type on the right, where the literal takes the type of that operand:
null && NullBool now reports 'System.Nullable`1[System.Boolean]'
instead of 'System.Object'.
@rameel
rameel merged commit bcd3780 into main Nov 24, 2026
1 check passed
@rameel
rameel deleted the parser/simplify-visit-binary branch November 24, 2026 21:09
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