@@ -579,23 +579,15 @@ protected virtual SqlExpression VisitCase(CaseExpression caseExpression, bool al
579
579
}
580
580
581
581
// optimize expressions such as expr != null ? expr : null and expr == null ? null : expr
582
- if ( testIsCondition && whenClauses is [ var clause ] && ( elseResult == null || IsNull ( clause . Result ) ) )
582
+ if ( testIsCondition && whenClauses is [ var clause ] && ( elseResult is null || IsNull ( clause . Result ) ) )
583
583
{
584
584
HashSet < SqlExpression > nullPropagatedOperands = [ ] ;
585
- SqlExpression test , expr ;
586
585
587
- if ( elseResult == null )
588
- {
589
- expr = clause . Result ;
590
- test = clause . Test ;
591
- }
592
- else
593
- {
594
- expr = elseResult ;
595
- test = _sqlExpressionFactory . Not ( clause . Test ) ;
596
- }
586
+ var ( test , expr ) = elseResult is null
587
+ ? ( clause . Test , clause . Result )
588
+ : ( _sqlExpressionFactory . Not ( clause . Test ) , elseResult ) ;
597
589
598
- NullPropagatedOperands ( expr , nullPropagatedOperands ) ;
590
+ DetectNullPropagatingNodes ( expr , nullPropagatedOperands ) ;
599
591
test = DropNotNullChecks ( test , nullPropagatedOperands ) ;
600
592
601
593
if ( IsTrue ( test ) )
@@ -632,38 +624,38 @@ when nullPropagatedOperands.Contains(isNotNull.Operand)
632
624
} ;
633
625
634
626
// FIXME: unify nullability computations
635
- static void NullPropagatedOperands ( SqlExpression expression , HashSet < SqlExpression > operands )
627
+ static void DetectNullPropagatingNodes ( SqlExpression expression , HashSet < SqlExpression > operands )
636
628
{
637
629
operands . Add ( expression ) ;
638
630
639
- if ( expression is SqlUnaryExpression unary
640
- && unary . OperatorType is ExpressionType . Not or ExpressionType . Negate or ExpressionType . Convert )
631
+ switch ( expression )
641
632
{
642
- NullPropagatedOperands ( unary . Operand , operands ) ;
643
- }
644
- else if ( expression is SqlBinaryExpression binary
645
- && binary . OperatorType is not ( ExpressionType . AndAlso or ExpressionType . OrElse ) )
646
- {
647
- NullPropagatedOperands ( binary . Left , operands ) ;
648
- NullPropagatedOperands ( binary . Right , operands ) ;
649
- }
650
- else if ( expression is SqlFunctionExpression { IsNullable : true } func )
651
- {
652
- if ( func . InstancePropagatesNullability == true )
653
- {
654
- NullPropagatedOperands ( func . Instance ! , operands ) ;
655
- }
633
+ case SqlUnaryExpression { OperatorType : not ( ExpressionType . Equal or ExpressionType . NotEqual ) } unary :
634
+ DetectNullPropagatingNodes ( unary . Operand , operands ) ;
635
+ break ;
656
636
657
- if ( ! func . IsNiladic )
658
- {
659
- for ( var i = 0 ; i < func . ArgumentsPropagateNullability . Count ; i ++ )
637
+ case SqlBinaryExpression { OperatorType : not ( ExpressionType . AndAlso or ExpressionType . OrElse ) } binary :
638
+ DetectNullPropagatingNodes ( binary . Left , operands ) ;
639
+ DetectNullPropagatingNodes ( binary . Right , operands ) ;
640
+ break ;
641
+
642
+ case SqlFunctionExpression { IsNullable : true } func :
643
+ if ( func . InstancePropagatesNullability is true )
660
644
{
661
- if ( func . ArgumentsPropagateNullability [ i ] )
645
+ DetectNullPropagatingNodes ( func . Instance ! , operands ) ;
646
+ }
647
+
648
+ if ( ! func . IsNiladic )
649
+ {
650
+ for ( var i = 0 ; i < func . ArgumentsPropagateNullability . Count ; i ++ )
662
651
{
663
- NullPropagatedOperands ( func . Arguments [ i ] , operands ) ;
652
+ if ( func . ArgumentsPropagateNullability [ i ] )
653
+ {
654
+ DetectNullPropagatingNodes ( func . Arguments [ i ] , operands ) ;
655
+ }
664
656
}
665
657
}
666
- }
658
+ break ;
667
659
}
668
660
}
669
661
}
0 commit comments