-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more factory constructors tests. Note that there are several intentional syntax errors.
- Loading branch information
Showing
4 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Language/Classes/Constructors/Factories/accessible_class_A03_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,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 it is a compile-time error if `R` denotes a | ||
/// generative constructor and `D` is abstract. Test a sealed class | ||
/// @author sgrekhov22@gmail.com | ||
class C { | ||
factory C() = D; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
factory C.n() = D.n; | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
sealed class D implements C { | ||
D() {} | ||
const D.n(); | ||
} | ||
|
||
main() { | ||
print(C); | ||
} |
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 |
---|---|---|
|
@@ -28,5 +28,5 @@ enum E { | |
|
||
main() { | ||
print(C); | ||
print(F); | ||
print(E); | ||
} |
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
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,49 @@ | ||
// 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 A factory is a constructor prefaced by the built-in identifier | ||
/// factory. | ||
/// ⟨factoryConstructorSignature⟩ ::= | ||
/// const? factory ⟨constructorName⟩ ⟨formalParameterList⟩ | ||
/// | ||
/// @description Checks that it is a compile-time error if a non-redirecting | ||
/// factory constructor has an initializers list | ||
/// @author msyabro | ||
class A { | ||
int x; | ||
A(this.x); | ||
factory A.f() : x = 1 { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return C(); | ||
} | ||
} | ||
|
||
class C extends A { | ||
C() : super(0); | ||
} | ||
|
||
enum E { | ||
e1(1), e2(2); | ||
|
||
final x; | ||
|
||
const E(this.x); | ||
// ^ | ||
// [analyzer] unspecified | ||
|
||
factory E.f() : x = 0 { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return E.e1; | ||
} | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(E); | ||
} |