Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: lib/src/checker/resolver.dart

Issue 1253903004: add special case for min/max, fixes #281 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: small tweak for clarity Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/dart_sdk.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/checker/resolver.dart
diff --git a/lib/src/checker/resolver.dart b/lib/src/checker/resolver.dart
index df7e144243d09491ecdcb574da097ac63f48fe33..c83513bf068ae9c64f83911d2af636c947ebfee0 100644
--- a/lib/src/checker/resolver.dart
+++ b/lib/src/checker/resolver.dart
@@ -637,6 +637,29 @@ class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer {
}
}
}
+
+ // Pretend dart:math's min and max are generic:
+ //
+ // T min<T extends num>(T x, T y);
+ //
+ // and infer T. In practice, this just means if the type of x and y are
+ // both double or both int, we treat that as the return type.
+ //
+ // The Dart spec has similar treatment for binary operations on numbers.
+ //
+ // TODO(jmesserly): remove this when we have a fix for
+ // https://github.com/dart-lang/dev_compiler/issues/28
+ if (isDartMathMinMax(e)) {
+ var args = node.argumentList.arguments;
+ if (args.length == 2) {
+ var tx = args[0].staticType;
+ var ty = args[1].staticType;
+ if (tx == ty &&
+ (tx == _typeProvider.intType || tx == _typeProvider.doubleType)) {
+ node.staticType = tx;
+ }
+ }
+ }
}
void _inferObjectAccess(
« no previous file with comments | « no previous file | lib/src/dart_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698