Files
sdk/tests/language/cascade_2_test.dart
T
kmillikin@google.com 309fcb1ba3 Fix incorrect desugaring of cascades.
Make use of the attractive and powerful way that the LoadLocal expression is
really a pair of an arbitrary statement and a local variable load.

BUG=dart:7494

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16684 260f80e4-7a28-3924-810f-c04153c831b5
2013-01-07 10:03:17 +00:00

54 lines
1.3 KiB
Dart

// 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.
// Test cascades, issues 7494 (vm), 7689 (dart2js).
main() {
var a = new Element(null);
Expect.equals(1, a.path0.length);
Expect.equals(a, a.path0[0]);
// Issue 7693: e0 ? e1 : e2..f() parses as (e0 ? e1 : e2)..f().
Expect.equals(2, a.path1.length);
Expect.equals(a, a.path1[0]);
Expect.equals(a, a.path1[1]);
Expect.equals(1, a.path2.length); // NPE.
var b = new Element(a);
Expect.equals(2, b.path0.length);
Expect.equals(a, b.path0[0]);
Expect.equals(b, b.path0[1]);
Expect.equals(3, b.path1.length);
Expect.equals(a, b.path1[0]);
Expect.equals(a, b.path1[1]);
Expect.equals(b, b.path1[2]);
Expect.equals(2, b.path2.length); // NPE.
}
class Element {
final Element parent;
Element(this.parent);
List<Element> get path0 {
if (parent == null) {
return <Element>[this];
} else {
return parent.path0..add(this);
}
}
List<Element> get path1 {
return (parent == null) ? <Element>[this] : parent.path1..add(this);
}
List<Element> get path2 {
return (parent == null) ? <Element>[this] : (parent.path2..add(this));
}
}