mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 23:41:50 +00:00
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:
parent
cf0cedfdda
commit
144860c0d9
|
@ -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);
|
||||
|
|
18
tests/language/src/Closure4Test.dart
Normal file
18
tests/language/src/Closure4Test.dart
Normal 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));
|
||||
}
|
18
tests/language/src/Closure5Test.dart
Normal file
18
tests/language/src/Closure5Test.dart
Normal 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)));
|
||||
}
|
Loading…
Reference in a new issue