// 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.

// @dart = 2.9

main() {
  var parent = new Element(null);
  var child = new Element(parent);
  var result = child.path0.length;
  if (result != 2) {
    throw "Expected 2, but child.path0.length was $result";
  }
}

class Element {
  final Element parent;

  Element(this.parent);

  List<Element> get path0 {
    if (parent == null) {
      return <Element>[this];
    } else {
      var list = parent.path0;
      list.add(this);
      return list;
    }
  }
}
