This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree 4 files changed +26
-4
lines changed 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,13 @@ var dart;
86
86
}
87
87
dart . equals = equals ;
88
88
89
+ /** Checks that `x` is not null or undefined. */
90
+ function notNull ( x ) {
91
+ if ( x == null ) throw 'expected not-null value' ;
92
+ return x ;
93
+ }
94
+ dart . notNull = notNull ;
95
+
89
96
/**
90
97
* Defines a lazy property.
91
98
* After initial get or set, it will replace itself with a value property.
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ abstract class TypeRules {
25
25
bool isBoolType (DartType t) => t == provider.boolType;
26
26
bool isDoubleType (DartType t) => t == provider.doubleType;
27
27
bool isIntType (DartType t) => t == provider.intType;
28
- bool isNumType (DartType t) => t.name == "num" ;
28
+ bool isNumType (DartType t) => t == provider.intType.superclass ;
29
29
30
30
StaticInfo checkAssignment (Expression expr, DartType t);
31
31
Original file line number Diff line number Diff line change @@ -95,6 +95,21 @@ var $_libraryName;
95
95
/// Conversions that we don't handle end up here.
96
96
@override
97
97
void visitConversion (Conversion node) {
98
+ var from = node.baseType, to = node.convertedType;
99
+
100
+ // num to int or num to double is just a null check.
101
+ if (rules.isNumType (from) &&
102
+ (rules.isIntType (to) || rules.isDoubleType (to))) {
103
+ // TODO(jmesserly): a lot of these checks are meaningless, as people use
104
+ // `num` to mean "any kind of number" rather than "could be null".
105
+ // The core libraries especially suffer from this problem, with many of
106
+ // the `num` methods returning `num`.
107
+ out.write ('dart.notNull(' );
108
+ node.expression.accept (this );
109
+ out.write (')' );
110
+ return ;
111
+ }
112
+
98
113
out.write ('/* Unimplemented: ' );
99
114
out.write ('${node .description }' );
100
115
out.write (' */ ' );
Original file line number Diff line number Diff line change @@ -367,9 +367,9 @@ var core;
367
367
/* Unimplemented FunctionDeclarationStatement: String sixDigits(int n) {if (n >= 100000) return "$n"; if (n >= 10000) return "0$n"; if (n >= 1000) return "00$n"; if (n >= 100) return "000$n"; if (n >= 10) return "0000$n"; return "00000$n";} */ /* Unimplemented FunctionDeclarationStatement: String twoDigits(int n) {if (n >= 10) return "$n"; return "0$n";} */ if ( this . inMicroseconds < 0 ) {
368
368
return "-" + ( /* Unimplemented postfix operator: -this */ ) + "" ;
369
369
}
370
- let twoDigitMinutes = twoDigits ( /* Unimplemented: DownCast: num to int */ this . inMinutes . remainder ( MINUTES_PER_HOUR ) ) ;
371
- let twoDigitSeconds = twoDigits ( /* Unimplemented: DownCast: num to int */ this . inSeconds . remainder ( SECONDS_PER_MINUTE ) ) ;
372
- let sixDigitUs = sixDigits ( /* Unimplemented: DownCast: num to int */ this . inMicroseconds . remainder ( MICROSECONDS_PER_SECOND ) ) ;
370
+ let twoDigitMinutes = twoDigits ( dart . notNull ( this . inMinutes . remainder ( MINUTES_PER_HOUR ) ) ) ;
371
+ let twoDigitSeconds = twoDigits ( dart . notNull ( this . inSeconds . remainder ( SECONDS_PER_MINUTE ) ) ) ;
372
+ let sixDigitUs = sixDigits ( dart . notNull ( this . inMicroseconds . remainder ( MICROSECONDS_PER_SECOND ) ) ) ;
373
373
return "" + ( this . inHours ) + ":" + ( twoDigitMinutes ) + ":" + ( twoDigitSeconds ) + "." + ( sixDigitUs ) + "" ;
374
374
}
375
375
get isNegative ( ) { return this . _duration < 0 ; }
You can’t perform that action at this time.
0 commit comments