Use assertSubtype for lists.
Also omit access to as-fields if possible.
R=johnniwinther@google.com
Review URL: https://codereview.chromium.org//15735003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23014 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
index f045168..b4bfbdb 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/backend.dart
@@ -1689,7 +1689,8 @@
? const SourceString("stringSuperTypeCast")
: const SourceString('stringSuperTypeCheck');
}
- } else if (element == compiler.listClass || element == jsArrayClass) {
+ } else if ((element == compiler.listClass || element == jsArrayClass) &&
+ type.isRaw) {
if (nativeCheckOnly) return null;
return typeCast
? const SourceString("listTypeCast")
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index 0599317..1affd60 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -2830,7 +2830,7 @@
return new HIs(type, <HInstruction>[expression, call],
HIs.VARIABLE_CHECK);
} else if (RuntimeTypes.hasTypeArguments(type)) {
- Element element = type.element;
+ ClassElement element = type.element;
Element helper = backend.getCheckSubtype();
HInstruction representations =
buildTypeArgumentRepresentations(type);
@@ -2838,10 +2838,9 @@
String operator =
backend.namer.operatorIs(backend.getImplementationClass(element));
HInstruction isFieldName = addConstantString(node, operator);
- // TODO(karlklose): use [:null:] for [asField] if [element] does not
- // have a subclass.
- HInstruction asFieldName =
- addConstantString(node, backend.namer.substitutionName(element));
+ HInstruction asFieldName = compiler.world.hasAnySubtype(element)
+ ? addConstantString(node, backend.namer.substitutionName(element))
+ : graph.addConstantNull(constantSystem);
List<HInstruction> inputs = <HInstruction>[expression,
isFieldName,
representations,
diff --git a/tests/language/generic_list_checked_test.dart b/tests/language/generic_list_checked_test.dart
new file mode 100644
index 0000000..fcff24b
--- /dev/null
+++ b/tests/language/generic_list_checked_test.dart
@@ -0,0 +1,20 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+
+bool inCheckedMode() {
+ try {
+ int i = 'hest';
+ } catch (e) {
+ return true;
+ }
+ return false;
+}
+
+main() {
+ if (inCheckedMode()) {
+ Expect.throws(() { List<int> t = new List<String>(); });
+ }
+}