diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
index 24273987d3d96..9aaf4199c44be 100644
--- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
@@ -244,7 +244,7 @@ internal string GetDebuggerDisplay()
///
/// Map from a target-typed expression (such as a target-typed conditional, switch or new) to the delegate
/// that completes analysis once the target type is known.
- /// The delegate is invoked by .
+ /// The delegate is invoked by .
///
private PooledDictionary> TargetTypedAnalysisCompletion
=> _targetTypedAnalysisCompletionOpt ??= PooledDictionary>.GetInstance();
@@ -8703,6 +8703,7 @@ private TypeWithState VisitConversion(
ParameterSymbol? parameterOpt = null,
bool reportTopLevelWarnings = true,
bool reportRemainingWarnings = true,
+ bool isSuppressed = false,
bool extensionMethodThisArgument = false,
Optional stateForLambda = default,
bool trackMembers = false,
@@ -8742,9 +8743,8 @@ private TypeWithState VisitConversion(
NullableFlowState resultState = NullableFlowState.NotNull;
bool canConvertNestedNullability = true;
- bool isSuppressed = false;
- if (conversionOperand.IsSuppressed == true)
+ if (isSuppressed || conversionOperand.IsSuppressed)
{
reportTopLevelWarnings = false;
reportRemainingWarnings = false;
@@ -11056,6 +11056,7 @@ public override void VisitForEachIterationVariables(BoundForEachStatement node)
AssignmentKind.ForEachIterationVariable,
reportTopLevelWarnings: true,
reportRemainingWarnings: true,
+ isSuppressed: node.Expression is BoundConversion { Operand.IsSuppressed: true },
diagnosticLocation: variableLocation);
}
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
index e2a7bc8b97f0d..600b2098f4800 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
@@ -90888,7 +90888,7 @@ static class Extensions
comp.VerifyDiagnostics();
}
- [Fact]
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75430")]
public void Foreach_NullableElementType_Suppression()
{
var source = """
@@ -90896,7 +90896,7 @@ public void Foreach_NullableElementType_Suppression()
class C
{
void M1(object?[] a) { foreach (object item in a) { } }
- void M2(object[] a) { foreach (object item in a!) { } }
+ void M2(object?[] a) { foreach (object item in a!) { } }
}
""";
CreateCompilation(source).VerifyDiagnostics(