forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2350. Update existing factory constructor tests
- Loading branch information
Showing
55 changed files
with
1,008 additions
and
469 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Language/Classes/Constructors/Factories/accessible_class_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
36 changes: 36 additions & 0 deletions
36
Language/Classes/Constructors/Factories/accessible_class_A01_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
13 changes: 13 additions & 0 deletions
13
Language/Classes/Constructors/Factories/accessible_class_A01_t02_lib.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
46 changes: 46 additions & 0 deletions
46
Language/Classes/Constructors/Factories/accessible_class_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
58 changes: 58 additions & 0 deletions
58
Language/Classes/Constructors/Factories/accessible_class_A02_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
66 changes: 66 additions & 0 deletions
66
Language/Classes/Constructors/Factories/accessible_class_A02_t03.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
44 changes: 44 additions & 0 deletions
44
Language/Classes/Constructors/Factories/accessible_class_A03_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
Language/Classes/Constructors/Factories/accessible_class_t01.dart
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
Language/Classes/Constructors/Factories/accessible_class_t02.dart
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
Language/Classes/Constructors/Factories/accessible_class_t03.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.