Files
sdk/tests/language/inlined_conditional_test.dart
T
Jacob Richman 2dcd56ef43 Format all tests.
There are far too many files here to review everyone carefully.
Spot checking most of the diffs look good as test code is generally written
with less care than application code so lots of ugly formatting get through.
If people notice files where the automated formatting bothers them feel free
to comment indicating file names and I'll move spaces within comments to make
the formatting cleaner and use comments to force block formatting as I have
done for other case where formatting looked bad.

BUG=
R=efortuna@google.com

Review-Url: https://codereview.chromium.org/2771453003 .
2017-04-17 14:53:02 -07:00

51 lines
1.7 KiB
Dart

// 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.
// Regression test for dart2js. There was a bug in the variable
// allocator when a pure (side-effect free) instruction stand
// in-between an inlined `if` and its inlined expression.
import "package:expect/expect.dart";
var topLevel;
// Make [foo] an inlineable expression with a return type check.
Function foo(c) {
// Use [c] twice to make sure it is stored in a local.
return (c is Function ? null : c);
}
bar() {
var b = new Object();
f() {
// Inside a closure, locals that escape are stored in a closure
// class. By using [b] in both branches, the optimizers will move
// the fetching of [b] before the `if`. This puts the fetching
// instruction in between the `if` and the expression of the `if`.
// This instruction being pure, the variable allocator was dealing
// with it in a special way.
//
// Because the expression in the `if` is being recognized by the
// optimizers as being also a JavaScript expression, we do not
// allocate a name for it. But some expressions that it uses still
// can have a name, and our variable allocator did not handle live
// variables due to the inlining of the ternary expression in [foo].
if (foo(topLevel) == null) {
return b.toString();
} else {
return b.hashCode;
}
}
return f();
}
main() {
// Make sure the inferrer does not get an exact type for [topLevel].
topLevel = new Object();
topLevel = main;
var res = bar();
Expect.isTrue(res is String);
}