private TypeSymbol GetTernaryOperationType(TypeManagerContext context, TernaryOperationSyntax syntax) { var errors = new List <ErrorDiagnostic>(); // ternary operator requires the condition to be of bool type var conditionType = this.GetTypeInfoInternal(context, syntax.ConditionExpression); CollectErrors(errors, conditionType); var trueType = this.GetTypeInfoInternal(context, syntax.TrueExpression); CollectErrors(errors, trueType); var falseType = this.GetTypeInfoInternal(context, syntax.FalseExpression); CollectErrors(errors, falseType); if (errors.Any()) { return(new ErrorTypeSymbol(errors)); } var expectedConditionType = LanguageConstants.Bool; if (TypeValidator.AreTypesAssignable(conditionType, expectedConditionType) != true) { return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.ConditionExpression).ValueTypeMismatch(expectedConditionType.Name))); } // the return type is the union of true and false expression types return(UnionType.Create(trueType, falseType)); }
public override void VisitTernaryOperationSyntax(TernaryOperationSyntax syntax) => AssignTypeWithCaching(syntax, () => { var errors = new List <ErrorDiagnostic>(); // ternary operator requires the condition to be of bool type var conditionType = VisitAndReturnType(syntax.ConditionExpression); CollectErrors(errors, conditionType); var trueType = VisitAndReturnType(syntax.TrueExpression); CollectErrors(errors, trueType); var falseType = VisitAndReturnType(syntax.FalseExpression); CollectErrors(errors, falseType); if (errors.Any()) { return(new ErrorTypeSymbol(errors)); } var expectedConditionType = LanguageConstants.Bool; if (TypeValidator.AreTypesAssignable(conditionType, expectedConditionType) != true) { return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.ConditionExpression).ValueTypeMismatch(expectedConditionType.Name))); } // the return type is the union of true and false expression types return(UnionType.Create(trueType, falseType)); });
public override void VisitTernaryOperationSyntax(TernaryOperationSyntax syntax) => this.BuildWithSpread(() => base.VisitTernaryOperationSyntax(syntax));
public override void VisitTernaryOperationSyntax(TernaryOperationSyntax syntax) { this.AppendError(syntax); }
public override void VisitTernaryOperationSyntax(TernaryOperationSyntax syntax) { this.buffer.Append('('); base.VisitTernaryOperationSyntax(syntax); this.buffer.Append(')'); }