private TypeSymbol GetBinaryOperationType(TypeManagerContext context, BinaryOperationSyntax syntax) { var errors = new List <ErrorDiagnostic>(); var operandType1 = this.GetTypeInfoInternal(context, syntax.LeftExpression); CollectErrors(errors, operandType1); var operandType2 = this.GetTypeInfoInternal(context, syntax.RightExpression); CollectErrors(errors, operandType2); if (errors.Any()) { return(new ErrorTypeSymbol(errors)); } // operands don't appear to have errors // let's match the operator now var operatorInfo = BinaryOperationResolver.TryMatchExact(syntax.Operator, operandType1, operandType2); if (operatorInfo != null) { // we found a match - use its return type return(operatorInfo.ReturnType); } // we do not have a match // operand types didn't match available operators return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax).BinaryOperatorInvalidType(Operators.BinaryOperatorToText[syntax.Operator], operandType1.Name, operandType2.Name))); }
public override void VisitBinaryOperationSyntax(BinaryOperationSyntax syntax) => AssignTypeWithCaching(syntax, () => { var errors = new List <ErrorDiagnostic>(); var operandType1 = VisitAndReturnType(syntax.LeftExpression); CollectErrors(errors, operandType1); var operandType2 = VisitAndReturnType(syntax.RightExpression); CollectErrors(errors, operandType2); if (errors.Any()) { return(new ErrorTypeSymbol(errors)); } // operands don't appear to have errors // let's match the operator now var operatorInfo = BinaryOperationResolver.TryMatchExact(syntax.Operator, operandType1, operandType2); if (operatorInfo != null) { // we found a match - use its return type return(operatorInfo.ReturnType); } // we do not have a match // operand types didn't match available operators return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax).BinaryOperatorInvalidType(Operators.BinaryOperatorToText[syntax.Operator], operandType1.Name, operandType2.Name))); });