-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Report an error for dynamic evaluation of &&/|| when left operand is statically typed as an interface
#80962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: AlekseyTs <[email protected]>
Co-authored-by: AlekseyTs <[email protected]>
Co-authored-by: AlekseyTs <[email protected]>
| { | ||
| // Operators defined on interfaces cannot be used with dynamic binding at runtime, | ||
| // so we don't consider them as applicable. | ||
| if (op.ContainingType.IsInterface) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please combine interface check with condition in if (type.Kind != SymbolKind.NamedType) on line 1580 instead. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 3cf6ed6. The interface check is now combined with the SymbolKind.NamedType check at line 1580, and the redundant check inside hasApplicableBooleanOperator has been removed.
| } | ||
| }"; | ||
| CreateCompilation(source, targetFramework: TargetFramework.Net70).VerifyDiagnostics( | ||
| // (21,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'I1' must define operator 'false'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expression must be implicitly convertible to Boolean or its type 'I1' must define operator 'false'.
@copilot Please adjust corresponding resource string so that wording for this error message would be: "Expression must be implicitly convertible to Boolean or its type 'I1' must not be an interface and must define operator 'false'." #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit ee63d62. The error message now reads: "Expression must be implicitly convertible to Boolean or its type '{0}' must not be an interface and must define operator '{1}'." All test comments have been updated accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit ee63d62. The error message now reads: "Expression must be implicitly convertible to Boolean or its type '{0}' must not be an interface and must define operator '{1}'." All test comments have been updated accordingly.
@copilot Please adjust the following test comments in a similar way:
src\Compilers\CSharp\Test\Emit3\Semantics\ExtensionOperatorsTests.cs(15848):// (26,13): error CS7083: Expression must be implicitly convertible to Boolean or its type 'object' must define operator 'false'.
src\Compilers\CSharp\Test\IOperation\IOperation\IOperationTests_IBinaryOperatorExpression.cs(6353):// file.cs(6,18): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C' must define operator 'false'.
src\Compilers\CSharp\Test\IOperation\IOperation\IOperationTests_IBinaryOperatorExpression.cs(6865):// file.cs(6,18): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C?' must define operator 'false'.
src\Compilers\CSharp\Test\IOperation\IOperation\IOperationTests_IBinaryOperatorExpression.cs(7586):// file.cs(6,18): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C?' must define operator 'false'.
src\Compilers\CSharp\Test\IOperation\IOperation\IOperationTests_IBinaryOperatorExpression.cs(7695):// file.cs(6,18): error CS7083: Expression must be implicitly convertible to Boolean or its type 'C?' must define operator 'false'.
src\Compilers\CSharp\Test\IOperation\IOperation\IOperationTests_IBinaryOperatorExpression.cs(8017):// file.cs(6,18): error CS7083: Expression must be implicitly convertible to Boolean or its type 'bool?' must define operator 'false'.
src\Compilers\CSharp\Test\Semantic\Semantics\OperatorTests.cs(9274):// (27,37): error CS7083: Expression must be implicitly convertible to Boolean or its type 'S1?' must define operator 'false'.
src\Compilers\CSharp\Test\Semantic\Semantics\OperatorTests.cs(9319):// (27,37): error CS7083: Expression must be implicitly convertible to Boolean or its type 'S1?' must define operator 'false'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 92e9427. Updated all 8 test comment occurrences across 3 files (ExtensionOperatorsTests.cs, IOperationTests_IBinaryOperatorExpression.cs, and OperatorTests.cs) to include "must not be an interface and" in the error message.
Co-authored-by: AlekseyTs <[email protected]>
Co-authored-by: AlekseyTs <[email protected]>
|
@copilot Please document the breaking change at the end of "roslyn\docs\compilers\CSharp\Compiler Breaking Changes - DotNet 11.md" file |
Co-authored-by: AlekseyTs <[email protected]>
Done in commit fb27b79. The breaking change has been documented at the end of "Compiler Breaking Changes - DotNet 11.md" with a description of the issue, example code showing the error, a workaround, and a link to the GitHub issue. #Closed |
Co-authored-by: AlekseyTs <[email protected]>
&&/|| when left operand is statically typed as an interface
|
@dotnet/roslyn-compiler Please review. |
|
@dotnet/roslyn-compiler Please review |
Plan for fixing interface operator with dynamic bug
Original prompt
&&/||when left operand is statically typed as an interface withtrue/falseoperator. #80954💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.