Version 1.1.0-dev.5.6

svn merge -c 31657 https://dart.googlecode.com/svn/branches/bleeding_edge trunk

R=kasperl@google.com

Review URL: https://codereview.chromium.org//131403007

git-svn-id: http://dart.googlecode.com/svn/trunk@31661 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
index 9488f91..a36e0d9 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
@@ -603,6 +603,15 @@
       if (variables.head.element == variable) return index;
     }
   }
+
+  /// Return all classes that are referenced in the type of the function, i.e.,
+  /// in the return type or the argument types.
+  Set<ClassElement> getReferencedClasses(FunctionType type) {
+    FunctionArgumentCollector collector =
+        new FunctionArgumentCollector(backend);
+    collector.collect(type);
+    return collector.classes;
+  }
 }
 
 class TypeRepresentationGenerator extends DartTypeVisitor {
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/js_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/js_emitter.dart
index c84e44e..71fcaee 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/js_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/js_emitter.dart
@@ -19,7 +19,8 @@
     CodeBuffer;
 
 import '../elements/elements.dart' show
-    TypeVariableElement;
+    TypeVariableElement,
+    ConstructorBodyElement;
 
 import '../js/js.dart' show
     js;
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/type_test_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/type_test_emitter.dart
index 076240a..09e7eb2 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/type_test_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/type_test_emitter.dart
@@ -376,6 +376,33 @@
       }
     }
 
+    bool canTearOff(Element function) {
+      if (!function.isFunction() ||
+          function.isConstructor() ||
+          function.isAccessor()) {
+        return false;
+      } else if (function.isInstanceMember()) {
+        if (!function.getEnclosingClass().isClosure()) {
+          return compiler.codegenWorld.hasInvokedGetter(function, compiler);
+        }
+      }
+      return false;
+    }
+
+    backend.generatedCode.keys.where((element) {
+      return element is FunctionElement &&
+          element is! ConstructorBodyElement &&
+          (canTearOff(element) || backend.isAccessibleByReflection(element));
+    }).forEach((FunctionElement function) {
+      DartType type = function.computeType(compiler);
+      for (ClassElement cls in backend.rti.getReferencedClasses(type)) {
+        while (cls != null) {
+          rtiNeededClasses.add(cls);
+          cls = cls.superclass;
+        }
+      }
+    });
+
     return rtiNeededClasses;
   }
 
diff --git a/tests/compiler/dart2js_extra/closure_type_reflection2_test.dart b/tests/compiler/dart2js_extra/closure_type_reflection2_test.dart
new file mode 100644
index 0000000..ef97222
--- /dev/null
+++ b/tests/compiler/dart2js_extra/closure_type_reflection2_test.dart
@@ -0,0 +1,22 @@
+// Copyright (c) 2014, 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.
+
+// Test that classes referenced from a signature of a tear-off closure
+// are emitted.
+
+@MirrorsUsed(targets: 'C')
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+class A {}
+
+class C {
+  A foo() {}
+}
+
+main() {
+  Expect.isFalse(reflect(new C().foo).function.returnType.toString()
+      .contains('dynamic'));
+}
diff --git a/tests/compiler/dart2js_extra/closure_type_reflection_test.dart b/tests/compiler/dart2js_extra/closure_type_reflection_test.dart
new file mode 100644
index 0000000..e289f4d
--- /dev/null
+++ b/tests/compiler/dart2js_extra/closure_type_reflection_test.dart
@@ -0,0 +1,22 @@
+// Copyright (c) 2014, 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.
+
+// Test that classes referenced from a signature of a tear-off closure
+// are emitted.
+
+@MirrorsUsed(targets: 'C', symbols: 'A')
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+class A {}
+
+class C {
+  A foo() {}
+}
+
+main() {
+  Expect.equals("ClassMirror on 'A'",
+                reflect(new C().foo).function.returnType.toString());
+}
diff --git a/tools/VERSION b/tools/VERSION
index 8239aec..02e71ef 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -28,4 +28,4 @@
 MINOR 1
 PATCH 0
 PRERELEASE 5
-PRERELEASE_PATCH 5
+PRERELEASE_PATCH 6