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

Add test: AddParameters_NoLastWhitespaceTrivia #53089

Closed
wants to merge 1 commit into from

Conversation

Youssef1313
Copy link
Member

Expecting this test to fail in debug due to an assertion failure deep in the compiler layer. The root cause here is that the given ConstructorDeclarationSyntax doesn't have a whitespace leading trivia. Causing the value of lastWhiteSpaceTrivia to remain the default literal:

SyntaxTrivia lastWhiteSpaceTrivia = default;

When it's passed to SyntaxGenerator.DocumentationCommentTrivia:

var extraDocComments = Generator.DocumentationCommentTrivia(
extraNodeList,
node.GetTrailingTrivia(),
lastWhiteSpaceTrivia,
document.Project.Solution.Options.GetOption(FormattingOptions.NewLine, document.Project.Language));

The following assertion fails:

Debug.Assert(node is object);

Will see what also happens in Release.

@Youssef1313
Copy link
Member Author

This causes a NRE on Release. I'll get that fixed in #53052

StackTrace for reference:

  Failed Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ChangeSignature.ChangeSignatureTests.AddParameters_NoLastWhitespaceTrivia [15 ms]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.CodeAnalysis.GreenNode.AdjustFlagsAndWidth(GreenNode node) in /_/src/Compilers/Core/Portable/Syntax/GreenNode.cs:line 109
   at Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.WithTwoChildren..ctor(GreenNode child0, GreenNode child1) in /_/src/Compilers/Core/Portable/Syntax/InternalSyntax/SyntaxList.WithTwoChildren.cs:line 28
   at Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList.List(GreenNode child0, GreenNode child1) in /_/src/Compilers/Core/Portable/Syntax/InternalSyntax/SyntaxList.cs:line 42
   at Microsoft.CodeAnalysis.GreenNode.CreateList[TFrom](IReadOnlyList`1 list, Func`2 select) in /_/src/Compilers/Core/Portable/Syntax/GreenNode.cs:line 954
   at Microsoft.CodeAnalysis.GreenNode.CreateList[TFrom](IEnumerable`1 enumerable, Func`2 select) in /_/src/Compilers/Core/Portable/Syntax/GreenNode.cs:line 919
   at Microsoft.CodeAnalysis.SyntaxToken.WithTrailingTrivia(IEnumerable`1 trivia) in /_/src/Compilers/Core/Portable/Syntax/SyntaxToken.cs:line 507
   at Microsoft.CodeAnalysis.SyntaxNodeExtensions.WithTrailingTrivia[TSyntax](TSyntax node, IEnumerable`1 trivia) in /_/src/Compilers/Core/Portable/Syntax/SyntaxNodeExtensions.cs:line 406
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.DocumentationCommentTrivia(IEnumerable`1 nodes, SyntaxTriviaList trailingTrivia, SyntaxTrivia lastWhitespaceTrivia, String endOfLineString) in /_/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs:line 85
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.GetPermutedDocCommentTrivia(Document document, SyntaxNode node, ImmutableArray`1 permutedParamNodes) in /_/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs:line 999
   at Microsoft.CodeAnalysis.CSharp.ChangeSignature.CSharpChangeSignatureService.UpdateParamTagsInLeadingTrivia(Document document, CSharpSyntaxNode node, ISymbol declarationSymbol, SignatureChange updatedSignature) in /_/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs:line 745
   at Microsoft.CodeAnalysis.CSharp.ChangeSignature.CSharpChangeSignatureService.<ChangeSignatureAsync>d__15.MoveNext() in /_/src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs:line 267
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs:line 56
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.<>c__DisplayClass20_1.<CreateUpdatedSolutionAsync>b__1(SyntaxNode originalNode, SyntaxNode potentiallyUpdatedNode) in /_/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs:line 378
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node) in /_/src/Compilers/CSharp/Portable/Syntax/SyntaxReplacer.cs:line 193
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 168
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList`1 list) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 145
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitClassDeclaration(ClassDeclarationSyntax node) in /_/src/Compilers/CSharp/Portable/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs:line 1873
   at Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor) in /_/src/Compilers/CSharp/Portable/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs:line 9773
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 41
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node) in /_/src/Compilers/CSharp/Portable/Syntax/SyntaxReplacer.cs:line 184
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 168
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList`1 list) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 145
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitCompilationUnit(CompilationUnitSyntax node) in /_/src/Compilers/CSharp/Portable/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs:line 1837
   at Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor) in /_/src/Compilers/CSharp/Portable/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs:line 8853
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxRewriter.cs:line 41
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replacer`1.Visit(SyntaxNode node) in /_/src/Compilers/CSharp/Portable/Syntax/SyntaxReplacer.cs:line 184
   at Microsoft.CodeAnalysis.CSharp.Syntax.SyntaxReplacer.Replace[TNode](SyntaxNode root, IEnumerable`1 nodes, Func`3 computeReplacementNode, IEnumerable`1 tokens, Func`3 computeReplacementToken, IEnumerable`1 trivia, Func`3 computeReplacementTrivia) in /_/src/Compilers/CSharp/Portable/Syntax/SyntaxReplacer.cs:line 34
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode.ReplaceCore[TNode](IEnumerable`1 nodes, Func`3 computeReplacementNode, IEnumerable`1 tokens, Func`3 computeReplacementToken, IEnumerable`1 trivia, Func`3 computeReplacementTrivia) in /_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxNode.cs:line 488
   at Microsoft.CodeAnalysis.SyntaxNodeExtensions.ReplaceNodes[TRoot,TNode](TRoot root, IEnumerable`1 nodes, Func`3 computeReplacementNode) in /_/src/Compilers/Core/Portable/Syntax/SyntaxNodeExtensions.cs:line 60
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.<CreateUpdatedSolutionAsync>d__20.MoveNext() in /_/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs:line 368
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.<<ChangeSignatureWithContextAsync>g__GetChangeSignatureResultAsync|17_0>d.MoveNext() in /_/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs:line 190
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.<ChangeSignatureWithContextAsync>d__17.MoveNext() in /_/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs:line 176
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature.ChangeSignatureTestState.<ChangeSignatureAsync>d__16.MoveNext() in /_/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/ChangeSignatureTestState.cs:line 84
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature.AbstractChangeSignatureTests.<TestChangeSignatureViaCommandAsync>d__5.MoveNext() in /_/src/EditorFeatures/DiagnosticsTestUtilities/ChangeSignature/AbstractChangeSignatureTests.cs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ChangeSignature.ChangeSignatureTests.<AddParameters_NoLastWhitespaceTrivia>d__45.MoveNext() in /_/src/EditorFeatures/CSharpTest/ChangeSignature/AddParameterTests.cs:line 1303
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Results File: C:\h\w\A7B50967\w\AF10094D\e\Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests.dll.6_net472_x64_test_results.xml

Failed!  - Failed:     1, Passed:   912, Skipped:     0, Total:   913, Duration: 40 s - Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests.dll (net472)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant