Skip to content

parser: look up implicit operators for the target type - #27

Merged
rameel merged 1 commit into
mainfrom
parser/implicit-operator-target-type
Nov 18, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/implicit-operator-target-type

Conversation

@rameel

@rameel rameel commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The implicit conversion used by the ?? operator and by the branches of the conditional operator looked for a user-defined operator that returns bool instead of the target type. As a result, s ?? w for a string s and a type with only implicit operator string was rejected, and for a type that also had implicit operator bool it failed with The operands for operator 'Convert' do not match the parameters of method 'op_Implicit'.

This PR looks up an operator that returns the target type. The conversions to bool for &&, ||, and the condition of the conditional operator are not affected.

The implicit conversion used by the '??' operator and by the branches
of the conditional operator looked for a user-defined operator that
returns bool instead of the target type. As a result, 's ?? w' for a
string s and a type with only 'implicit operator string' was rejected,
and for a type that also had 'implicit operator bool' it failed with
"The operands for operator 'Convert' do not match the parameters of
method 'op_Implicit'".

Look up an operator that returns the target type.
@rameel
rameel merged commit 14b482f into main Nov 18, 2026
1 check passed
@rameel
rameel deleted the parser/implicit-operator-target-type branch November 18, 2026 11:35
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