public BoundTernaryExpression(BoundTernaryOperator @operator, BoundExpression condition, BoundExpression trueExpression, BoundExpression falseExpression)
 {
     Operator  = @operator;
     Condition = condition;
     True      = trueExpression;
     False     = falseExpression;
 }
Example #2
0
        private BoundExpression BindTernaryExpression(ConditionalExpressionSyntax syntax)
        {
            var condition       = BindExpression(syntax.ConditionExpression);
            var trueExpression  = BindExpression(syntax.TrueExpression);
            var falseExpression = BindExpression(syntax.FalseExpression);

            if (condition.Type != TypeSymbol.Bool)
            {
                _diagnostics.ReportTypeMismatch(syntax.QuestionMarkToken.Span, condition.Type, TypeSymbol.Bool);

                return(new BoundErrorExpression());
            }

            var boundOperator = BoundTernaryOperator.Bind(syntax.Kind, condition.Type, trueExpression.Type, falseExpression.Type);

            if (boundOperator == null)
            {
                _diagnostics.ReportTypeMismatch(syntax.ColonToken.Span, trueExpression.Type, falseExpression.Type);

                return(new BoundErrorExpression());
            }

            return(new BoundTernaryExpression(boundOperator, condition, trueExpression, falseExpression));
        }