| Index: pkg/analyzer/lib/src/generated/type_system.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
|
| index 526d067050019423bc75cbd3b3776501636d082f..426bd4c2c1d035b26b45b9d4bd99553d21a86d13 100644
|
| --- a/pkg/analyzer/lib/src/generated/type_system.dart
|
| +++ b/pkg/analyzer/lib/src/generated/type_system.dart
|
| @@ -7,6 +7,7 @@ library analyzer.src.generated.type_system;
|
| import 'dart:collection';
|
| import 'dart:math' as math;
|
|
|
| +import 'package:analyzer/dart/ast/token.dart' show TokenType;
|
| import 'package:analyzer/dart/element/element.dart';
|
| import 'package:analyzer/dart/element/type.dart';
|
| import 'package:analyzer/src/dart/element/element.dart';
|
| @@ -942,6 +943,50 @@ abstract class TypeSystem {
|
| }
|
|
|
| /**
|
| + * Attempts to make a better guess for the type of a binary with the given
|
| + * [operator], given that resolution has so far produced the [currentType].
|
| + */
|
| + DartType refineBinaryExpressionType(
|
| + TypeProvider typeProvider,
|
| + DartType leftType,
|
| + TokenType operator,
|
| + DartType rightType,
|
| + DartType currentType) {
|
| + // bool
|
| + if (operator == TokenType.AMPERSAND_AMPERSAND ||
|
| + operator == TokenType.BAR_BAR ||
|
| + operator == TokenType.EQ_EQ ||
|
| + operator == TokenType.BANG_EQ) {
|
| + return typeProvider.boolType;
|
| + }
|
| + DartType intType = typeProvider.intType;
|
| + if (leftType == intType) {
|
| + // int op double
|
| + if (operator == TokenType.MINUS ||
|
| + operator == TokenType.PERCENT ||
|
| + operator == TokenType.PLUS ||
|
| + operator == TokenType.STAR) {
|
| + DartType doubleType = typeProvider.doubleType;
|
| + if (rightType == doubleType) {
|
| + return doubleType;
|
| + }
|
| + }
|
| + // int op int
|
| + if (operator == TokenType.MINUS ||
|
| + operator == TokenType.PERCENT ||
|
| + operator == TokenType.PLUS ||
|
| + operator == TokenType.STAR ||
|
| + operator == TokenType.TILDE_SLASH) {
|
| + if (rightType == intType) {
|
| + return intType;
|
| + }
|
| + }
|
| + }
|
| + // default
|
| + return currentType;
|
| + }
|
| +
|
| + /**
|
| * Given a [DartType] type, return the [TypeParameterElement]s corresponding
|
| * to its formal type parameters (if any).
|
| *
|
|
|