dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

SyntaxGenerator.TypeExpression generates different SyntaxNode than parser #43950

Open AArnott opened 4 years ago

AArnott commented 4 years ago

Version Used: Microsoft.CodeAnalysis 3.5.0

Steps to Reproduce:

SyntaxGenerator generator;
SyntaxNode completedTaskExpression = generator.MemberAccessExpression(
   generator.TypeExpression(systemThreadingTasksTask),
   generator.IdentifierName(nameof(Task.CompletedTask)));

Expected Behavior:

completedTaskExpression is a syntax tree made up of nested SimpleMemberAccessExpression instances as the parser would produce.

Actual Behavior:

The syntax tree is instead made up of QualifiedName nodes. This causes code fix test failures when the test framework from roslyn-sdk compares the code fix syntax tree to the parsed syntax tree.

The bug appears in both C# and VB syntax generators.

jinujoseph commented 4 years ago

cc @mavasani @333fred

mavasani commented 4 years ago

Also tagging @CyrusNajmabadi if he is aware of this issue in syntax generators.

AArnott commented 4 years ago

FYI internally to roslyn-analyzers there's already a workaround for this bug:

https://github.com/dotnet/roslyn-analyzers/blob/f24a5b42c85be6ee572f3a93bef223767fbefd75/src/Utilities/Workspaces/SyntaxGeneratorExtensions.cs#L68-L74

CyrusNajmabadi commented 4 years ago

Yes, it's a known issue.