Extensions: Close some tracked follow-ups (using static directives)#80527
Extensions: Close some tracked follow-ups (using static directives)#80527jcouv merged 6 commits intodotnet:mainfrom
Conversation
| { | ||
| Debug.Assert(extensions.Count == 0); | ||
|
|
||
| // Tracked by https://github.com/dotnet/roslyn/issues/79440 : using directives, test this flag (see TestUnusedExtensionMarksImportsAsUsed) |
There was a problem hiding this comment.
📝 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.) |
There was a problem hiding this comment.
📝 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? |
There was a problem hiding this comment.
📝 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) |
There was a problem hiding this comment.
📝 Added a dedicated test for GetTypeByMetadataName #Resolved
There was a problem hiding this comment.
📝 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.
450cf7d to
bb5c1bc
Compare
| ) | ||
| // Method begins at RVA 0x20fa | ||
| // Method begins at RVA 0x20e2 | ||
| // Code size 1 (0x1) |
There was a problem hiding this comment.
📝 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) |
There was a problem hiding this comment.
Seems like this could be static. #Resolved
|
|
||
| #nullable disable | ||
|
|
||
| using System.Diagnostics; |
There was a problem hiding this comment.
This added using seems unnecessary. #Resolved
| 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 |
There was a problem hiding this comment.
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); |
| { | ||
| if (Type is null && Identifier.IsKind(SyntaxKind.None)) | ||
| { | ||
| throw new System.NotSupportedException(CSharpResources.ParameterRequiresTypeOrIdentifier); |
| </PropertyComment> | ||
| </Field> | ||
| <Field Name="Type" Type="TypeSyntax" Optional="true" Override="true"/> | ||
| <Field Name="Type" Type="TypeSyntax" Optional="true" RequiredForTest="true" Override="true"/> |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Should we either get rid of those, or not enforce the condition?
There was a problem hiding this comment.
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}")); |
|
Done with review pass (commit 4) #Closed |
* 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)
* 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 ...

Relates to test plan #76130
Closes #79440
Also added a section on
using staticdirectives for extensions: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-14.0/extensions.md#using-static-directives