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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 3003943002: restore FutureOr cast failure ignore (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 ' if (o === true || o === false || o == null) return o;' 1117 ' if (o === true || o === false || o == null) return o;'
1118 ' return #.as(o, #, true);' 1118 ' return #.as(o, #, true);'
1119 '}', 1119 '}',
1120 [className, _runtimeModule, className])); 1120 [className, _runtimeModule, className]));
1121 return null; 1121 return null;
1122 } 1122 }
1123 } 1123 }
1124 if (classElem.library.isDartAsync) { 1124 if (classElem.library.isDartAsync) {
1125 if (classElem == types.futureOrType.element) { 1125 if (classElem == types.futureOrType.element) {
1126 var typeParamT = classElem.typeParameters[0].type; 1126 var typeParamT = classElem.typeParameters[0].type;
1127 var tOrFutureOfT = js.call('#.is(o) || #.is(o)', [ 1127 var typeT = _emitType(typeParamT);
1128 _emitType(typeParamT), 1128 var futureOrT = _emitType(types.futureType.instantiate([typeParamT]));
1129 _emitType(types.futureType.instantiate([typeParamT]))
1130 ]);
1131 body.add(js.statement(''' 1129 body.add(js.statement('''
1132 #.is = function is_FutureOr(o) { 1130 #.is = function is_FutureOr(o) {
1133 return #; 1131 return #.is(o) || #.is(o);
1134 } 1132 }
1135 ''', [className, tOrFutureOfT])); 1133 ''', [className, typeT, futureOrT]));
1134 // TODO(jmesserly): remove the fallback to `dart.as`. It's only for the
1135 // _ignoreTypeFailure logic.
1136 body.add(js.statement(''' 1136 body.add(js.statement('''
1137 #.as = function as_FutureOr(o) { 1137 #.as = function as_FutureOr(o) {
1138 if (o == null || #) return o; 1138 if (o == null || #.is(o) || #.is(o)) return o;
1139 return #.castError(o, this, false); 1139 return #.as(o, this, false);
1140 } 1140 }
1141 ''', [className, tOrFutureOfT, _runtimeModule])); 1141 ''', [className, typeT, futureOrT, _runtimeModule]));
1142 body.add(js.statement(''' 1142 body.add(js.statement('''
1143 #._check = function check_FutureOr(o) { 1143 #._check = function check_FutureOr(o) {
1144 if (o == null || #) return o; 1144 if (o == null || #.is(o) || #.is(o)) return o;
1145 return #.castError(o, this, true); 1145 return #.as(o, this, true);
1146 } 1146 }
1147 ''', [className, tOrFutureOfT, _runtimeModule])); 1147 ''', [className, typeT, futureOrT, _runtimeModule]));
1148 return null; 1148 return null;
1149 } 1149 }
1150 } 1150 }
1151 1151
1152 body.add(_callHelperStatement('addTypeTests(#);', [className])); 1152 body.add(_callHelperStatement('addTypeTests(#);', [className]));
1153 1153
1154 if (classElem.typeParameters.isEmpty) return null; 1154 if (classElem.typeParameters.isEmpty) return null;
1155 1155
1156 // For generics, testing against the default instantiation is common, 1156 // For generics, testing against the default instantiation is common,
1157 // so optimize that. 1157 // so optimize that.
(...skipping 4907 matching lines...) Expand 10 before | Expand all | Expand 10 after
6065 // The library the prefix is referring to must come from a deferred import. 6065 // The library the prefix is referring to must come from a deferred import.
6066 var containingLibrary = resolutionMap 6066 var containingLibrary = resolutionMap
6067 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 6067 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
6068 .library; 6068 .library;
6069 var imports = containingLibrary.getImportsWithPrefix(prefix); 6069 var imports = containingLibrary.getImportsWithPrefix(prefix);
6070 return imports.length == 1 && imports[0].isDeferred; 6070 return imports.length == 1 && imports[0].isDeferred;
6071 } 6071 }
6072 6072
6073 bool _annotatedNullCheck(Element e) => 6073 bool _annotatedNullCheck(Element e) =>
6074 e != null && findAnnotation(e, isNullCheckAnnotation) != null; 6074 e != null && findAnnotation(e, isNullCheckAnnotation) != null;
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698