Reapply "Don't try to box immutable objects."

This reapplies (a fixed version of) commit 6631 which was reverted in commit 6632.

Fix tests (types were wrong).

Review URL: https://chromiumcodereview.appspot.com//10091039

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6639 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
floitsch@google.com 2012-04-17 13:47:29 +00:00
parent cf0cedfdda
commit 144860c0d9
3 changed files with 38 additions and 3 deletions

View file

@ -240,6 +240,8 @@ class ClosureTranslator extends AbstractVisitor {
Element box = null;
Map<Element, Element> scopeMapping = new Map<Element, Element>();
for (Element element in scopeVariables) {
// No need to box non-assignable elements.
if (!element.isAssignable()) continue;
if (capturedVariableMapping.containsKey(element)) {
if (box == null) {
// TODO(floitsch): construct better box names.
@ -354,9 +356,6 @@ class ClosureTranslator extends AbstractVisitor {
}
scopeVariables = new List<Element>();
// TODO(floitsch): a named function is visible from inside itself. Add
// the element to the block.
// We have to declare the implicit 'this' parameter.
if (!insideClosure && closureData.thisElement !== null) {
declareLocal(closureData.thisElement);

View file

@ -0,0 +1,18 @@
// Copyright (c) 2012, 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.
// Dart2js failed when a declared function was captured inside itself.
foo(f) => f(499);
main() {
fun(x) {
if (x < 3) {
return foo((x) => fun(x));
} else {
return x;
}
}
Expect.equals(499, fun(499));
}

View file

@ -0,0 +1,18 @@
// Copyright (c) 2012, 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.
// Dart2js failed when a declared function was captured inside itself.
foo(f) => f(499);
main() {
fun(x) {
if (x < 3) {
return foo((x) => fun(x));
} else {
return x;
}
}
Expect.equals(499, foo((x) => fun(x)));
}