diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.DebugVerifier.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.DebugVerifier.cs index 67720dbc0d04e..5f6f6ee8fa580 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.DebugVerifier.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.DebugVerifier.cs @@ -147,6 +147,18 @@ private void VerifyExpression(BoundExpression expression, bool overrideSkippedEx return null; } + public override BoundNode? VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node) + { + Visit(node.Expression); + + if (node.Conversion is BoundConversion conversion) + { + Visit(conversion); + } + + return null; + } + public override BoundNode? VisitDeconstructionAssignmentOperator(BoundDeconstructionAssignmentOperator node) { // https://github.com/dotnet/roslyn/issues/35010: handle diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/CollectionExpressionTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/CollectionExpressionTests.cs index 75076aa452010..bbf72a68dc844 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/CollectionExpressionTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/CollectionExpressionTests.cs @@ -47326,5 +47326,38 @@ .locals init (int V_0, //i Assert.Contains(libraryRef, usedRefs); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81552")] + public void VisitedNodes_CollectionExpression() + { + var source = """ + #nullable enable + using System; + using System.Collections; + using System.Collections.Generic; + using System.Runtime.CompilerServices; + + Merge([.. D.P]); + + static void Merge(params ReadOnlySpan cs) { } + + [CollectionBuilder(typeof(C), methodName: nameof(Create))] + class C : IEnumerable + { + public static C Create(ReadOnlySpan span) => new(); + + public IEnumerator GetEnumerator() => throw new NotImplementedException(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } + + class D + { + public static IEnumerable P => [1]; + } + """; + + CompileAndVerify(CreateCompilationWithSpan([source, CollectionBuilderAttributeDefinition]), expectedOutput: "").VerifyDiagnostics(); + } } }