@@ -609,10 +609,17 @@ void enforceMemberNotNullOnMember(SyntaxNode? syntaxOpt, LocalState state, Metho
609609
610610 void enforceMemberNotNullWhenForPendingReturn ( PendingBranch pendingReturn , BoundReturnStatement returnStatement )
611611 {
612- if ( pendingReturn . IsConditionalState )
612+ if ( returnStatement . ExpressionOpt is BoundExpression { ConstantValue : { IsBoolean : true , BooleanValue : bool value } } )
613613 {
614- enforceMemberNotNullWhen ( returnStatement . Syntax , sense : true , pendingReturn . StateWhenTrue ) ;
615- enforceMemberNotNullWhen ( returnStatement . Syntax , sense : false , pendingReturn . StateWhenFalse ) ;
614+ if ( pendingReturn . IsConditionalState )
615+ {
616+ enforceMemberNotNullWhen ( returnStatement . Syntax , sense : true , pendingReturn . StateWhenTrue ) ;
617+ enforceMemberNotNullWhen ( returnStatement . Syntax , sense : false , pendingReturn . StateWhenFalse ) ;
618+ }
619+ else
620+ {
621+ enforceMemberNotNullWhen ( returnStatement . Syntax , sense : value , pendingReturn . State ) ;
622+ }
616623 }
617624 }
618625
@@ -763,13 +770,17 @@ void enforceNotNullWhenForPendingReturn(PendingBranch pendingReturn, BoundReturn
763770 {
764771 var parameters = this . MethodParameters ;
765772
766- if ( ! parameters . IsEmpty )
773+ if ( ! parameters . IsEmpty && returnStatement . ExpressionOpt is BoundExpression { ConstantValue : { IsBoolean : true , BooleanValue : bool value } } )
767774 {
768775 if ( pendingReturn . IsConditionalState )
769776 {
770777 enforceParameterNotNullWhen ( returnStatement . Syntax , parameters , sense : true , stateWhen : pendingReturn . StateWhenTrue ) ;
771778 enforceParameterNotNullWhen ( returnStatement . Syntax , parameters , sense : false , stateWhen : pendingReturn . StateWhenFalse ) ;
772779 }
780+ else
781+ {
782+ enforceParameterNotNullWhen ( returnStatement . Syntax , parameters , sense : value , stateWhen : pendingReturn . State ) ;
783+ }
773784 }
774785 }
775786
0 commit comments