-
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 constructor tests. Part 3
- Loading branch information
Showing
5 changed files
with
237 additions
and
15 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
Language/Classes/Constructors/Factories/function_type_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,50 @@ | ||
// 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 a formal parameter of k′ has a default value | ||
/// whose type is not a subtype of the type annotation on the corresponding | ||
/// formal parameter in k | ||
/// | ||
/// @description Checks that it is a compile-time error is if a factory | ||
/// constructor redirects to a constructor whose type is not a subtype of the | ||
/// factory's function type. Checks the case when constructor function type is | ||
/// not assignable. | ||
/// @author [email protected] | ||
class F<T extends num> { | ||
factory F(int x, [T y]) = C<T>; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory F.foo(int x, [T y]) = C.foo; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
factory F.bar(int x, {T y}) = C.bar; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C<T extends num> implements F<int> { | ||
C(int x, [int y = 0]) {} | ||
C.foo(int x, [int y = 0]) {} | ||
C.bar(int x, {int y = 0}) {} | ||
} | ||
|
||
main() { | ||
print(F); | ||
print(C); | ||
} |
47 changes: 47 additions & 0 deletions
47
Language/Classes/Constructors/Factories/function_type_t04.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,47 @@ | ||
// 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 constructor whose type is not a subtype of the | ||
/// factory's function type. Checks extension type | ||
/// @author [email protected] | ||
/// @issue 53934 | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
enum Bool { | ||
_true._(true), | ||
_false._(false); | ||
final bool isTrue; | ||
const Bool._(this.isTrue); | ||
const factory Bool(bool value) = _BoolHelper; | ||
// ^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
extension type const _BoolHelper._(Bool _) { // missed implements Bool | ||
const _BoolHelper(bool isTrue) : this._(isTrue ? Bool._true : Bool._false); | ||
} | ||
|
||
main() { | ||
print(Bool); | ||
} |
45 changes: 45 additions & 0 deletions
45
Language/Classes/Constructors/Factories/function_type_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,45 @@ | ||
// 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 constructor whose type is not a subtype of the | ||
/// factory's function type. Checks extension type | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class Bool { | ||
final bool _value; | ||
Bool(this._value); | ||
|
||
factory Bool.f(bool value) = _BoolHelper; | ||
// ^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
extension type const _BoolHelper(Bool _) { // missed implements Bool | ||
_BoolHelper.g(bool val) : this(Bool(val)); | ||
} | ||
|
||
main() { | ||
print(Bool); | ||
} |