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. Add/update factory constructor tests. Part 4
- Loading branch information
Showing
14 changed files
with
447 additions
and
36 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Language/Classes/Constructors/Factories/function_type_t06.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,48 @@ | ||
// 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. | ||
/// ... | ||
/// The redirectee constructor for this declaration is the constructor k′ | ||
/// denoted by R. | ||
/// ... | ||
/// It is a compile error if the function type of k' is not a subtype of the | ||
/// type of k. | ||
/// | ||
/// @description Checks that it is a compile-time error is if a factory | ||
/// constructor redirects to a null | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class F { | ||
factory F(x) = null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
const E(); | ||
|
||
factory E.f() = null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(F); | ||
print(E); | ||
} |
52 changes: 52 additions & 0 deletions
52
Language/Classes/Constructors/Factories/parameter_type_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,52 @@ | ||
// 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 For the dynamic semantics, assume that k is a redirecting factory | ||
/// constructor and k′ is the redirectee of k | ||
/// | ||
/// It is a dynamic type error if an actual argument passed in an invocation of | ||
/// k is not a subtype of the actual type of the corresponding formal parameter | ||
/// in the declaration of k. | ||
/// | ||
/// @description Checks that it is a dynamic type error if an actual argument | ||
/// type of a redirecting factory constructor call is not a subtype of the | ||
/// actual type of its corresponding formal parameter. | ||
/// @author sgrekhov22@gmail.com | ||
import "../../../../Utils/expect.dart"; | ||
|
||
class F { | ||
factory F(num x) = C; | ||
factory F.foo(num x, [num y]) = C.foo; | ||
factory F.bar(num x, {num z}) = C.bar; | ||
} | ||
|
||
class C implements F { | ||
num x, y = 1, z = 2; | ||
|
||
C(this.x); | ||
C.foo(this.x, [this.y = 1]); | ||
C.bar(this.x, {this.z = 2}); | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
const E(); | ||
|
||
factory E.g1(num x) => E.e1; | ||
factory E.g2(num x, [num y = 1]) => E.e1; | ||
factory E.g3(num x, {num z = 2}) => E.e1; | ||
factory E.f1(num x) = E.g1; | ||
factory E.f2(num x, [num y]) = E.g2; | ||
factory E.f3(num x, {num z}) = E.g3; | ||
} | ||
|
||
main() { | ||
Expect.throws(() {F(Object() as dynamic);}); | ||
Expect.throws(() {F.foo(42, Object() as dynamic);}); | ||
Expect.throws(() {F.bar(3.14, z: Object() as dynamic);}); | ||
Expect.throws(() {E.f1(Object() as dynamic);}); | ||
Expect.throws(() {E.f2(42, Object() as dynamic);}); | ||
Expect.throws(() {E.f3(3.14, z: Object() as dynamic);}); | ||
} |
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
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
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
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
77 changes: 77 additions & 0 deletions
77
Language/Classes/Constructors/Factories/redirecting_constructor_t05.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,77 @@ | ||
// 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 redirecting factory constructor specifies a call to a | ||
/// constructor of another class that is to be used whenever the redirecting | ||
/// constructor is called. | ||
/// ⟨redirectingFactoryConstructorSignature⟩ ::= | ||
/// const? factory ⟨constructorName⟩ ⟨formalParameterList⟩ ‘=’ | ||
/// ⟨constructorDesignation⟩ | ||
/// ⟨constructorDesignation⟩ ::= ⟨typeIdentifier⟩ | ||
/// | ⟨qualifiedName⟩ | ||
/// | ⟨typeName⟩ ⟨typeArguments⟩ (‘.’ ⟨identifier⟩)? | ||
/// | ||
/// @description Checks that it is a compile-time error if any parameter of the | ||
/// factory constructor has modifier `covariant` | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 54030 | ||
class F { | ||
factory F(covariant num x) = C; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory F.f1(num x, [covariant num y]) = C.f1; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory F.f2(num x, {covariant num z}) = C.f2; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory F.f3(num x, {required covariant num z}) = C.f3; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C implements F { | ||
num x, y = 1, z = 2; | ||
|
||
C(this.x); | ||
C.f1(this.x, [this.y = 1]); | ||
C.f2(this.x, {this.z = 2}); | ||
C.f3(this.x, {required this.z}); | ||
} | ||
|
||
enum E { | ||
e1, e2; | ||
const E(); | ||
|
||
factory E.g1(num x) => E.e1; | ||
factory E.g2(num x, [num y = 1]) => E.e1; | ||
factory E.g3(num x, {num z = 2}) => E.e1; | ||
factory E.g4(num x, {num z = 2}) => E.e1; | ||
factory E.f1(covariant num x) = E.g1; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory E.f2(num x, [covariant num y]) = E.g2; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory E.f3(num x, {covariant num z}) = E.g3; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory E.f4(num x, {required covariant num z}) = E.g3; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(E); | ||
} |
Oops, something went wrong.