mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:59:47 +00:00
d0998d6996
Bug: https://github.com/dart-lang/sdk/issues/29106 Change-Id: Ie676295f104fcbb8458fbb27f3f01ed52e99fef9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370662 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Sam Rawlins <srawlins@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
72 lines
1.9 KiB
Dart
72 lines
1.9 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.
|
|
|
|
import "dart:collection";
|
|
|
|
// Test compile time error for factories with parameterized types.
|
|
|
|
abstract class A<T> {
|
|
A();
|
|
A.create();
|
|
}
|
|
|
|
abstract class B<T> extends A<T> {}
|
|
|
|
// Compile time error: should be AFactory<T> to match abstract class above
|
|
class AFactory extends B<int> {
|
|
factory A.create() {
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.INVALID_FACTORY_NAME_NOT_A_CLASS
|
|
// [cfe] The name of a constructor must match the name of the enclosing class.
|
|
throw UnimplementedError();
|
|
}
|
|
}
|
|
|
|
abstract class Link<T> extends IterableBase<T> {
|
|
factory Link(T head, [Link<T>? tail]) = LinkEntry<T>;
|
|
Link<T> prepend(T element);
|
|
}
|
|
|
|
abstract class EmptyLink<T> extends Link<T> {
|
|
const factory EmptyLink() = LinkTail<T>;
|
|
}
|
|
|
|
class AbstractLink<T> implements Link<T> {
|
|
// ^^^^^^^^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER
|
|
// [cfe] The non-abstract class 'AbstractLink' is missing implementations for these members:
|
|
const AbstractLink();
|
|
Link<T> prepend(T element) {
|
|
print("$element");
|
|
if (0 is T) {
|
|
throw "0 is not a T";
|
|
}
|
|
return new Link<T>(element, this);
|
|
}
|
|
}
|
|
|
|
class LinkTail<T> extends AbstractLink<T> implements EmptyLink<T> {
|
|
// ^^^^^^^^
|
|
// [cfe] The non-abstract class 'LinkTail' is missing implementations for these members:
|
|
const LinkTail();
|
|
}
|
|
|
|
class LinkEntry<T> extends AbstractLink<T> {
|
|
// ^^^^^^^^^
|
|
// [cfe] The non-abstract class 'LinkEntry' is missing implementations for these members:
|
|
LinkEntry(T head, [Link<T>? Tail]);
|
|
}
|
|
|
|
class Fisk {
|
|
Link<Fisk> nodes = const EmptyLink<Fisk>();
|
|
final int id;
|
|
Fisk(this.id);
|
|
toString() => id.toString();
|
|
}
|
|
|
|
main() {
|
|
var a = new AFactory.create();
|
|
new Fisk(0).nodes.prepend(new Fisk(1)).prepend(new Fisk(2));
|
|
}
|