diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 053c9035d8cce..1337c580d1f01 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -5614,8 +5614,8 @@ private TypeWithState ConvertConditionalOperandOrSwitchExpressionArmResult( LocalState state, bool isReachable) { - var savedState = this.State; - this.State = state; + var savedState = PossiblyConditionalState.Create(this); + this.SetState(state); bool previousDisabledDiagnostics = _disableDiagnostics; // If the node is not reachable, then we're only visiting to get @@ -5644,7 +5644,7 @@ private TypeWithState ConvertConditionalOperandOrSwitchExpressionArmResult( resultType = default; _disableDiagnostics = previousDisabledDiagnostics; } - this.State = savedState; + this.SetPossiblyConditionalState(in savedState); return resultType; } @@ -8457,8 +8457,7 @@ private TypeWithState VisitUserDefinedConversion( bool reportRemainingWarnings, Location diagnosticLocation) { - // Uncomment when https://github.com/dotnet/roslyn/issues/67153 is fixed - // Debug.Assert(!IsConditionalState); + Debug.Assert(!IsConditionalState); Debug.Assert(conversionOperand != null); Debug.Assert(targetTypeWithNullability.HasType); Debug.Assert(diagnosticLocation != null); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 73d4f82dc5b40..f72cf1ee35a60 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -53054,6 +53054,27 @@ static void M1(bool b, C c, D d) comp.VerifyDiagnostics(); } + [Fact, WorkItem(67153, "https://github.com/dotnet/roslyn/issues/67153")] + public void ConditionalOperator_WithUserDefinedConversion_BoolOperand() + { + var source = """ + struct C + { + public static implicit operator C(bool b) => throw null!; + } + class D + { + static void M(bool b) + { + _ = (b ? false : default(C)) /*T:C*/; + } + } + """; + var comp = CreateCompilation(source, options: WithNullableEnable()); + comp.VerifyTypes(); + comp.VerifyDiagnostics(); + } + [Fact] [WorkItem(33664, "https://github.com/dotnet/roslyn/issues/33664")] public void ConditionalOperator_Ref_NestedNullabilityMismatch()