Skip to content

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Oct 1, 2025

Relates to test plan #76130
Closes #79440

Also added a section on using static directives for extensions: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-14.0/extensions.md#using-static-directives

@jcouv jcouv self-assigned this Oct 1, 2025
@jcouv jcouv added Area-Compilers Feature - Extension Everything The extension everything feature labels Oct 1, 2025
{
Debug.Assert(extensions.Count == 0);

// Tracked by https://github.com/dotnet/roslyn/issues/79440 : using directives, test this flag (see TestUnusedExtensionMarksImportsAsUsed)
Copy link
Member Author

@jcouv jcouv Oct 1, 2025

Choose a reason for hiding this comment

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

📝 Added TestUnusedExtensionMarksImportsAsUsed_02

});
}

// Tracked by https://github.com/dotnet/roslyn/issues/78957 : public API, Ensure we are not messing up relative order of events for extension members (with relation to events for enclosing types, etc.)
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 Already covered by AnalyzerActions_ tests

return synthesizedGlobalMethod.ContainingPrivateImplementationDetailsType;
}

// Tracked by https://github.com/dotnet/roslyn/issues/78827 : code quality, share logic with Cci.ITypeMemberReference.GetContainingType implementation?
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 removed a few similar comments, as I don't think the suggestion is necessary or that it would improve the code.

)
// Method begins at RVA 0x20fa
// Method begins at RVA 0x20e2
// Code size 1 (0x1)
Copy link
Member Author

@jcouv jcouv Oct 1, 2025

Choose a reason for hiding this comment

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

📝 Added a dedicated test for GetTypeByMetadataName #Resolved

Copy link
Member

@jjonescz jjonescz Oct 3, 2025

Choose a reason for hiding this comment

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

📝 Added a dedicated test for GetTypeByMetadataName

Did you mean to make this comment on line 44444 which removed this snippet?

        // Tracked by https://github.com/dotnet/roslyn/issues/78968 : we should find the unspeakable nested type
        Assert.Null(comp.GetTypeByMetadataName("E+<G>$BA41CFE2B5EDAEB8C1B9062F59ED4D69"));

And was it actually fixed? The comment seems to indicate that GetTypeByMetadataName should not return null, but the new test still has Assert.Null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the comment about GetTypeByMetadataName got misplaced.
Decided not to support it following conversation with Aleksey. Here for context:
image

@jcouv jcouv force-pushed the extensions-misc branch 4 times, most recently from 450cf7d to bb5c1bc Compare October 1, 2025 22:16
@jcouv jcouv marked this pull request as ready for review October 2, 2025 08:49
@jcouv jcouv requested a review from a team as a code owner October 2, 2025 08:49
@jcouv jcouv requested review from AlekseyTs and jjonescz October 3, 2025 09:23
)
// Method begins at RVA 0x20fa
// Method begins at RVA 0x20e2
// Code size 1 (0x1)
Copy link
Member

@jjonescz jjonescz Oct 3, 2025

Choose a reason for hiding this comment

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

📝 Added a dedicated test for GetTypeByMetadataName

Did you mean to make this comment on line 44444 which removed this snippet?

        // Tracked by https://github.com/dotnet/roslyn/issues/78968 : we should find the unspeakable nested type
        Assert.Null(comp.GetTypeByMetadataName("E+<G>$BA41CFE2B5EDAEB8C1B9062F59ED4D69"));

And was it actually fixed? The comment seems to indicate that GetTypeByMetadataName should not return null, but the new test still has Assert.Null.

}
}

private bool HasValidate(TreeType node)
Copy link
Member

@jjonescz jjonescz Oct 3, 2025

Choose a reason for hiding this comment

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

Seems like this could be static. #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.

[Responding to other comment here due to technical difficulties]
Yes, the comment about GetTypeByMetadataName got misplaced.
Decided not to support it following conversation with Aleksey. Here for context:
image


#nullable disable

using System.Diagnostics;
Copy link
Member

@jjonescz jjonescz Oct 3, 2025

Choose a reason for hiding this comment

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

This added using seems unnecessary. #Resolved

Julien Couvreur added 2 commits October 3, 2025 05:05
@jcouv jcouv requested a review from jjonescz October 3, 2025 12:13
var syntax = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().Single().Expression;

//This is the crux of the test.
//Without this line, with or without the fix, the model never gets pushed to evaluate extension method candidates
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

with or without the fix

It is not clear what fix we are referring to. It looks like addition of this test corresponds to a removal of a comment in implementation. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced this with a more compact/focused test (LookupSymbols_UsedImports)

//and therefore never marked ClassLibrary2 as a used import in consoleApplication.
//Without the fix, this call used to result in ClassLibrary2 getting marked as used, after the fix, this call does not
//result in changing ClassLibrary2's used status.
model.GetMemberGroup(syntax);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

model.GetMemberGroup(syntax);

Does the set include a method from ClassLibrary2? Consider asserting the fact to strengthen the test and to make it clearer. #Closed

{
if (Type is null && Identifier.IsKind(SyntaxKind.None))
{
throw new System.NotSupportedException(CSharpResources.ParameterRequiresTypeOrIdentifier);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

NotSupportedException

It feels like this should be a flavor of an "invalid argument" exception. #Closed

</PropertyComment>
</Field>
<Field Name="Type" Type="TypeSyntax" Optional="true" Override="true"/>
<Field Name="Type" Type="TypeSyntax" Optional="true" RequiredForTest="true" Override="true"/>
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

RequiredForTest="true"

What effect does this have? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

The generated tests generate nodes. The basic logic is to use null or default for all optional nodes. That means GenerateParameter() produces a node without type or identifier and the generated tests hit the added validation.
This flag says that even though the type is optional, for purpose of test we treat it as non-optional.

{
if (Type is null && Identifier.IsKind(SyntaxKind.None))
{
throw new System.NotSupportedException(CSharpResources.ParameterRequiresTypeOrIdentifier);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

throw new System.NotSupportedException(CSharpResources.ParameterRequiresTypeOrIdentifier);

Is there any factory method that will always end-up here no matter what? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we either get rid of those, or not enforce the condition?

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 reviewed the usages and the only one that always ends up in this situation has been dealt with. It was the internal GenerateParameter() in generated syntax tests.
The other usages are in SyntaxFactory (one overload takes an identifier but no type) and SyntaxGenerator (takes both a type and an identifier).

AssertEx.Equal(groupingName, extension.ExtensionGroupingName);
AssertEx.Equal(markerName, extension.ExtensionMarkerName);
Assert.Null(comp.GetTypeByMetadataName($"E+{groupingName}"));
Assert.Null(comp.GetTypeByMetadataName($"E+{groupingName}+{markerName}"));
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 3, 2025

Choose a reason for hiding this comment

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

Assert.Null(comp.GetTypeByMetadataName($"E+{groupingName}+{markerName}"));

Consider also testing the following for completeness:

Assert.Null(comp.GetTypeByMetadataName($"E+{markerName}"));
``` #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 3, 2025

Done with review pass (commit 4) #Closed

@jcouv jcouv requested a review from AlekseyTs October 3, 2025 22:08
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 6)

@jcouv jcouv merged commit ff59510 into dotnet:main Oct 6, 2025
28 checks passed
@jcouv jcouv deleted the extensions-misc branch October 6, 2025 22:00
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 6, 2025
333fred added a commit to 333fred/roslyn that referenced this pull request Oct 6, 2025
* upstream/main:
  Extensions: Close some tracked follow-ups (dotnet#80527)
  Fix outdated 17.15 to 18.0 (dotnet#80570)
  Update dependencies from https://github.com/dotnet/dotnet build 285582 (dotnet#80551)
  Fix all-in-one tests
  [main] Update dependencies from dotnet/arcade (dotnet#80559)
  Improve error recovery when object initializer uses ':' instead of '=' (dotnet#80553)
  Support `field` keyword in EE. (dotnet#80515)
  Log a debug message for ContentModified exceptions. (dotnet#80549)
  Update dependencies from https://github.com/dotnet/arcade build 20251002.2 (dotnet#80550)
333fred added a commit to 333fred/roslyn that referenced this pull request Oct 7, 2025
* upstream/main: (252 commits)
  Move Watch EA to a separate assembly Microsoft.CodeAnalysis.ExternalAccess.HotReload (dotnet#80556)
  Enable long paths for Windows DartLab CI (dotnet#80581)
  Ensure that CS8659 is reported on partial properties (dotnet#80573)
  Fix a wrong relative link in a doc (dotnet#80567)
  [main] Source code updates from dotnet/dotnet (dotnet#80578)
  Update dependencies from https://github.com/dotnet/arcade build 20251006.2 (dotnet#80577)
  Update main configs after VS snap (dotnet#80523)
  Add followup async public apis (dotnet#80455)
  Reduce allocations in CSharpSyntaxNode.GetStructure (dotnet#80562)
  Extensions: Close some tracked follow-ups (dotnet#80527)
  Fix outdated 17.15 to 18.0 (dotnet#80570)
  Update dependencies from https://github.com/dotnet/dotnet build 285582 (dotnet#80551)
  Fix all-in-one tests
  [main] Update dependencies from dotnet/arcade (dotnet#80559)
  Improve error recovery when object initializer uses ':' instead of '=' (dotnet#80553)
  Support `field` keyword in EE. (dotnet#80515)
  Log a debug message for ContentModified exceptions. (dotnet#80549)
  Update dependencies from https://github.com/dotnet/arcade build 20251002.2 (dotnet#80550)
  Fix
  Simplify and add additional asserts
  ...
@jcouv jcouv changed the title Extensions: Close some tracked follow-ups Extensions: Close some tracked follow-ups (using static directives) Nov 15, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extensions: follow-ups related to using directives

3 participants