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

CS8625 code fix fails when declaration to fix is in another file #74121

Open
jroessel opened this issue Jun 24, 2024 · 0 comments
Open

CS8625 code fix fails when declaration to fix is in another file #74121

jroessel opened this issue Jun 24, 2024 · 0 comments
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jroessel
Copy link

jroessel commented Jun 24, 2024

Version Used: .NET 8.0.302

Steps to Reproduce:

  1. Have code where code in one file sets a field/property in another file to null , e.g.

Parent.cs

public class Parent
{
    public void M(Child c)
    {
        c.next = null;
        c.Next = null;
    }
}

Child.cs

public sealed class Child
{
    internal Child next;
    public Child Next { get => next; set => next = value; }
}
  1. Place the cursor on either of the null literals where CS8625 is raised.
  2. Apply the suggested "Declare as nullable" code fix

Diagnostic Id: CS8625: Cannot convert null literal to non-nullable reference type.

Expected Behavior:

The code fix should append a ? to the field/property type in the other file.

Actual Behavior:

System.ArgumentException : The node is not part of the tree.
Parameter name: node
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.CheckNodeInOriginalTree(SyntaxNode node)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.ReplaceNode(SyntaxNode node,SyntaxNode newNode)
   at async Microsoft.CodeAnalysis.CSharp.CodeFixes.DeclareAsNullable.CSharpDeclareAsNullableCodeFixProvider.FixAllAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass16_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)

Reproducible in both VS Code and Visual Studio 2022.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

1 participant