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

Unified Diff: sdk/lib/math/math.dart

Issue 24918003: Revert "Revert "Reinstate type checks in Math.min and Math.max"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | « runtime/vm/intermediate_language.h ('k') | tests/lib/math/min_max_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/math/math.dart
diff --git a/sdk/lib/math/math.dart b/sdk/lib/math/math.dart
index 93ec4164426ef8c668b0cf057b9539afe07efa05..4cffa8f59455e0caced02d788e7a7bee9d439dd3 100644
--- a/sdk/lib/math/math.dart
+++ b/sdk/lib/math/math.dart
@@ -61,6 +61,12 @@ const double SQRT2 = 1.4142135623730951;
* is returned.
*/
num min(num a, num b) {
+ // These partially redundant type checks improve code quality for dart2js.
+ // Most of the improvement is at call sites from the inferred non-null num
+ // return type.
+ if (a is! num) throw new ArgumentError(a);
+ if (b is! num) throw new ArgumentError(b);
+
if (a > b) return b;
if (a < b) return a;
if (b is double) {
@@ -90,6 +96,12 @@ num min(num a, num b) {
* then it is unspecified which of the two arguments is returned.
*/
num max(num a, num b) {
+ // These partially redundant type checks improve code quality for dart2js.
+ // Most of the improvement is at call sites from the inferred non-null num
+ // return type.
+ if (a is! num) throw new ArgumentError(a);
+ if (b is! num) throw new ArgumentError(b);
+
if (a > b) return a;
if (a < b) return b;
if (b is double) {
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | tests/lib/math/min_max_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698