Skip to content

Conversation

@AlekseyTs
Copy link
Contributor

@AlekseyTs AlekseyTs commented May 7, 2025

Relates to test plan #76130

@AlekseyTs AlekseyTs requested review from jcouv and jjonescz May 7, 2025 22:31
@AlekseyTs AlekseyTs requested a review from a team as a code owner May 7, 2025 22:31
@AlekseyTs AlekseyTs added Area-Compilers Feature - Extension Everything The extension everything feature labels May 7, 2025
@ghost ghost added the untriaged Issues and PRs which have not yet been triaged by a lead label May 7, 2025
@jcouv jcouv self-assigned this May 7, 2025
@AlekseyTs
Copy link
Contributor Author

@jcouv, @jjonescz, @dotnet/roslyn-compiler Please review

resultKind = LookupResultKind.Empty;
originalUserDefinedOperators = [];

if (operand.IsLiteralDefault() || // Reported not being able to target-type `default` elsewhere, so we can doing more work
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

nit: Do we need this line? (seems the second condition subsumes that) #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReportUnaryOperatorError checks for this, and I do not think we we want to do any work in this case as well.

}
}

diagnostics.Add(node, useSiteInfo);
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

Do we have a test for this? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a test for this?

No. And I didn't plan to add one.

static void getDeclaredUserDefinedUnaryOperators(ArrayBuilder<NamedTypeSymbol> extensionDeclarationsInSingleScope, UnaryOperatorKind kind, string name, ArrayBuilder<UnaryOperatorSignature> operators)
{
foreach (NamedTypeSymbol extensionDeclaration in extensionDeclarationsInSingleScope)
{
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

nit: consider asserting extensionDeclaration.IsExtension #Resolved

{
Debug.Assert(operand.Type.IsNullableType());

if (!candidate.Method.ContainingType.ExtensionParameter.Type.IsValidNullableTypeArgument())
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

Do we have a test where this check matters? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a test where this check matters?

No we don't, but we generally do not call MakeNullable if this check fails.

resultKind = LookupResultKind.Empty;
originalUserDefinedOperators = [];

if (operand.IsLiteralDefault() || // Reported not being able to target-type `default` elsewhere, so we can doing more work
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

doing

typo: doing => do? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually "avoid" is missing

// _ = +s1;
Diagnostic(ErrorCode.ERR_BadUnaryOp, "+s1").WithArguments("+", "object").WithLocation(17, 13)
);
}
Copy link
Member

@jcouv jcouv May 8, 2025

Choose a reason for hiding this comment

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

Consider testing consumption of operator defined in metadata image (I think I only saw compilation references) #Resolved

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 3)

@AlekseyTs
Copy link
Contributor Author

@jjonescz, @dotnet/roslyn-compiler For the second review

}
""";
var comp3 = CreateCompilation(src3, references: [comp1Ref], options: TestOptions.DebugExe);
CompileAndVerify(comp3, expectedOutput: "operator1").VerifyDiagnostics();
Copy link
Member

@jjonescz jjonescz May 9, 2025

Choose a reason for hiding this comment

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

Consider testing this with LangVersion=13 as well. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider testing this with LangVersion=13 as well.

I do not expect language version to have any effect on this code, and the scenario doesn't go through the modified/new code paths. One might say it wouldn't hurt, but the same could be said for every scenario we ever test. We have to draw a line somewhere.

UnaryOperatorKind kind,
bool isChecked,
string name1,
string name2Opt,
Copy link
Member

@jjonescz jjonescz May 9, 2025

Choose a reason for hiding this comment

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

Consider adding nullable annotations to new code. #Resolved


if (isApplicableToReceiver(inferredCandidate, operand, ref useSiteInfo))
{
operators[i] = inferredCandidate;
Copy link
Member

@jjonescz jjonescz May 9, 2025

Choose a reason for hiding this comment

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

Nit: the method is called removeInapplicableToReceiverType but it's also replacing candidates which might be unexpected when reading the call site. Consider renaming the method. #Resolved

@AlekseyTs AlekseyTs enabled auto-merge (squash) May 9, 2025 15:18
@AlekseyTs AlekseyTs merged commit 6b83c96 into dotnet:features/extensions May 9, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Extension Everything The extension everything feature 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.

3 participants