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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 977613002: Make int and double nullable by default (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: actually upload changes Created 5 years, 10 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 | « lib/config.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index ab8d555d827b05ef5f41e18a4824d46e2e50037d..cadeb9090c0f1e429e6bb906ea58913be5bbd7f2 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1047,9 +1047,56 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
bool unaryOperationIsPrimitive(DartType t) => typeIsPrimitiveInJS(t);
+ bool _isNonNullableExpression(Expression expr) {
+ // TODO(vsm): Revisit whether we really need this when we get
+ // better non-nullability in the type system.
+
+ if (expr is Literal && expr is! NullLiteral) {
+ return true;
+ }
+ if (expr is ParenthesizedExpression) {
+ return _isNonNullableExpression(expr.expression);
+ }
+ DartType type = null;
+ if (expr is BinaryExpression) {
+ type = rules.getStaticType(expr.leftOperand);
+ } else if (expr is PrefixExpression) {
+ type = rules.getStaticType(expr.operand);
+ } else if (expr is PostfixExpression) {
+ type = rules.getStaticType(expr.operand);
+ }
+ if (type != null && typeIsPrimitiveInJS(type)) {
+ return true;
+ }
+ if (expr is MethodInvocation) {
+ // TODO(vsm): This logic overlaps with the resolver.
+ // Where is the best place to put this?
+ var e = expr.methodName.staticElement;
+ if (e is FunctionElement &&
Jennifer Messerly 2015/03/03 20:05:01 at some point I wonder if we want a helper for thi
+ e.library.name == '_foreign_helper' &&
+ e.name == 'JS') {
+ // Fix types for JS builtin calls.
+ //
+ // This code was taken from analyzer. It's not super sophisticated:
+ // only looks for the type name in dart:core, so we just copy it here.
+ //
+ // TODO(jmesserly): we'll likely need something that can handle a wider
+ // variety of types, especially when we get to JS interop.
+ var args = expr.argumentList.arguments;
+ if (args.isNotEmpty && args.first is SimpleStringLiteral) {
+ var types = args.first.stringValue;
+ if (!types.split('|').contains('Null')) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
JS.Expression notNull(Expression expr) {
var type = rules.getStaticType(expr);
- if (rules.isNonNullableType(type)) {
+ if (rules.isNonNullableType(type) || _isNonNullableExpression(expr)) {
return _visit(expr);
} else {
return js.call('dart.notNull(#)', _visit(expr));
« no previous file with comments | « lib/config.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698