Skip to content

Commit

Permalink
dart-lang#2350. Update existing factory constructor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Nov 6, 2023
1 parent 7ccb121 commit 8a3c7ae
Show file tree
Hide file tree
Showing 55 changed files with 1,008 additions and 469 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2011, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile error is produced if `T` does not denote
/// a class accessible in the current scope.
/// @author ilya
class C {
factory C() = A;
// ^
// [analyzer] unspecified
// [cfe] unspecified

factory C.f() = A<String>;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e1, e2;

const factory E() = A;
// ^
// [analyzer] unspecified
// [cfe] unspecified

const factory E.f() = A<String>;
// ^
// [analyzer] unspecified
// [cfe] unspecified

}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile error is produced if `T` does not denote
/// a class accessible in the current scope.
/// @author sgrekhov22@gmail.com
import "accessible_class_A01_t02_lib.dart";

class C {
factory C() = _PrivateClass;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2023, 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.

/// @description Auxiliary library for testing factory constructors.
/// @author sgrekhov22@gmail.com
library factories_lib;

import "accessible_class_A01_t02.dart";

class _PrivateClass implements C {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2011, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile error is produced if `R` does not denote
/// a constructor
/// @author ilya
var variable;

class C {
factory C() = variable;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e1, e2;

const factory E() = variable;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2011, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile error is produced if `R` does not denote
/// a constructor
/// @author ilya
foo() {}

T bar<T>() => C.gen() as dynamic;

class C {
C.gen();

factory C() = function;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

factory C.f() = bar<C>;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e1, e2;
const factory E() = function;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
factory E.f() = bar<E>;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2011, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile error is produced if referenced type in a
/// redirecting constructor is in fact an accessible type, but the referenced
/// name does not denote a constructor.
/// @author ilya
class F {
factory F.foo() = C.foo;
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

factory F.bar() = C.bar;
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

factory F.baz() = C.cInstance;
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

class C implements F {
C foo() => this;
late C bar;
static C cInstance() => C();
static E eInstance() => E.e1;

C() {
bar = this;
}
}

enum E {
e1, e2;

factory E.foo() = C.eInstance;
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(F);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2023, 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.

/// @assertion Assume that C<X1 extends B1 . . . , Xm extends Bm> is the name
/// and formal type parameters of the enclosing class, const? is const or empty,
/// N is C or C.id0 for some identifier id0, and id is an identifier, then
/// consider a declaration of a redirecting factory constructor k of one of the
/// forms
/// const? factory
/// N(T1 x1 . . . , Tn xn, [Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk]) = R;
/// const? factory
/// N(T1 x1 . . . , Tn xn, {Tn+1 xn+1=d1, . . . , Tn+k xn+k=dk}) = R;
/// where R is of one of the forms T<S1 . . . , Sp> or T<S1 . . . , Sp>.id.
///
/// It is a compile-time error if T does not denote a class accessible in the
/// current scope. If T does denote such a class D, it is a compile-time error
/// if R does not denote a constructor. Otherwise, it is a compile-time error if
/// R denotes a generative constructor and D is abstract.
///
/// @description Checks that a compile-time error if `R` denotes a generative
/// constructor and `D` is abstract.
/// @author sgrekhov22@gmail.com
class C {
factory C() = D;
// ^
// [analyzer] unspecified
// [cfe] unspecified

factory C.n() = D.n;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

abstract class D implements C {
D() {}
const D.n();
}

main() {
print(C);
}
23 changes: 0 additions & 23 deletions Language/Classes/Constructors/Factories/accessible_class_t01.dart

This file was deleted.

25 changes: 0 additions & 25 deletions Language/Classes/Constructors/Factories/accessible_class_t02.dart

This file was deleted.

24 changes: 0 additions & 24 deletions Language/Classes/Constructors/Factories/accessible_class_t03.dart

This file was deleted.

Loading

0 comments on commit 8a3c7ae

Please sign in to comment.