Skip to content
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

Report missing diagnostic for typeless expression in binary operation #69727

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Aug 25, 2023

Fixes #69579

For context, see the other location that uses IsTypelessExpressionAllowedInBinaryOperator (in BinaryOperatorOverloadResolution) and the comments in IsTypelessExpressionAllowedInBinaryOperator.
I'm not exactly sure why we chose this behavior and it seems odd, but I chose to keep the existing behavior (described in comment) and just fix our error reporting.

@jcouv jcouv self-assigned this Aug 25, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 25, 2023
@jcouv jcouv marked this pull request as ready for review August 28, 2023 17:08
@jcouv jcouv requested a review from a team as a code owner August 28, 2023 17:08
{
if (((SyntaxKind)node.OperatorToken.RawKind == SyntaxKind.PlusEqualsToken || (SyntaxKind)node.OperatorToken.RawKind == SyntaxKind.MinusEqualsToken) &&
if (IsTypelessExpressionAllowedInBinaryOperator(kind, left, right) &&
Copy link
Member

@jjonescz jjonescz Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like IsTypelessExpressionAllowedInBinaryOperator returns false if the expression is a kind of typeless expression which is disallowed in binary operator and true if it's allowed or not typeless at all, right? The name confused me as it sounds like it would return true only if the expression is typeless. Should it perhaps be renamed to

  • IsDisallowedTypelessExpressionInBinaryOperator and its semantics negated, or
  • IsExpressionAllowedInBinaryOperator (with semantics unchanged)?

Also, what happened when this check wasn't here? The GenerateImplicitConversionError failed? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current name is appropriate, looking at its usage in BinaryOperatorOverloadResolution:

        private BinaryOperatorAnalysisResult BinaryOperatorOverloadResolution(...)
        {
            if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right))
            {
                resultKind = LookupResultKind.OverloadResolutionFailure;
                originalUserDefinedOperators = default;
                return default(BinaryOperatorAnalysisResult);
            }
            ...

Also, what happened when this check wasn't here?

In DEBUG, the program would assert below (Debug.Assert(!conversion.IsImplicit);).
In RETAIL, the program would fail to report an error and would crash during emit phase. I didn't investigate in details, but I think it's just that GenerateImplicitConversionError doesn't handle the case and so didn't report an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at its usage in BinaryOperatorOverloadResolution

Yeah, I guess there it makes more sense since it's negated.

Co-authored-by: Fred Silberberg <[email protected]>
@jcouv jcouv requested a review from jjonescz August 29, 2023 23:13
@jcouv jcouv merged commit 2788650 into dotnet:main Aug 30, 2023
@jcouv jcouv deleted the binary-error branch August 30, 2023 17:26
@ghost ghost added this to the Next milestone Aug 30, 2023
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSC : error CS7038: Failed to emit module '_': Unable to determine specific cause of the failure.
4 participants