-
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 covariant parameters tests
- Loading branch information
Showing
6 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_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,53 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults | ||
/// `d1, ..., dk`, using `null` for parameters whose default value is not | ||
/// specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. Test covariant-by-declaration parameters. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C { | ||
num m<Y extends num>( | ||
covariant int r1, | ||
covariant Y r2, { | ||
covariant int p1 = 0 | ||
}) { | ||
return 42; | ||
} | ||
} | ||
|
||
main() { | ||
C o = C(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly<num Function<Y extends num>(int r1, Y r2, {int p1})> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is num Function<Y extends num>(Object? r1, Object? r2, {Object? p1}) | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_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,53 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults | ||
/// `d1, ..., dk`, using `null` for parameters whose default value is not | ||
/// specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. Test covariant-by-class parameters. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C<X> { | ||
X m<Y extends X>(X r1, Y r2, {required X p1}) { | ||
return 42 as X; | ||
} | ||
} | ||
|
||
main() { | ||
C<Object?> o = C<Object?>(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly<Object? Function<Y extends Object?>(Object? r1, Y r2, {required Object? p1})> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is Object? Function<Y extends Object?>( // ignore: unnecessary_type_check | ||
Object? r1, | ||
Y r2, { | ||
required Object? p1, | ||
}), | ||
); | ||
} |
57 changes: 57 additions & 0 deletions
57
...y_Extraction/Instance_Method_Closurization/method_closurization_named_params_A03_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,57 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, {Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk}) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn, pn+1: pn+1, ..., pn+k: pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and named parameters `pn+1, ..., pn+k` with defaults | ||
/// `d1, ..., dk`, using `null` for parameters whose default value is not | ||
/// specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C<X extends num> { | ||
X m<Y extends X>( | ||
covariant X r1, | ||
covariant Y r2, { | ||
required covariant int p1, | ||
}) { | ||
return 42 as X; | ||
} | ||
} | ||
|
||
main() { | ||
var o = C<num>(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly<num Function<Y extends num>(num r1, Y r2, {required int p1})> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is num Function<Y extends num>( | ||
Object? r1, | ||
Object? r2, { | ||
required Object? p1, | ||
}), | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
...raction/Instance_Method_Closurization/method_closurization_positional_params_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,54 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ... | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with | ||
/// defaults `d1, ..., dk`, using `null` for parameters whose default value is | ||
/// not specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. Test covariant-by-declaration parameters. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C { | ||
num m<Y extends num>( | ||
covariant int r1, | ||
covariant Y r2, [ | ||
covariant int p1 = 0, | ||
]) { | ||
return 42; | ||
} | ||
} | ||
|
||
main() { | ||
C o = C(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly<num Function<Y extends num>(int r1, Y r2, [int p1])> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1]), | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
...raction/Instance_Method_Closurization/method_closurization_positional_params_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,52 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ... | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with | ||
/// defaults `d1, ..., dk`, using `null` for parameters whose default value is | ||
/// not specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. Test covariant-by-class parameters. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C<X> { | ||
X m<Y extends X>(X r1, Y r2, [X? p1]) { | ||
return 42 as X; | ||
} | ||
} | ||
|
||
main() { | ||
C<Object?> o = C<Object?>(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly< | ||
Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) | ||
> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is Object? Function<Y extends Object?>(Object? r1, Y r2, [Object? p1]) // ignore: unnecessary_type_check | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
...raction/Instance_Method_Closurization/method_closurization_positional_params_A03_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,49 @@ | ||
// Copyright (c) 2025, 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 Let `o` be an object, and let `u` be a fresh final variable bound | ||
/// to o. The closurization of method `f` on object `o` is defined to be | ||
/// equivalent to: | ||
/// ... | ||
/// ``` | ||
/// - <X1 extends B′1, ..., Xs extends B′s> | ||
/// (T1 p1, ..., Tn pn, [Tn+1 pn+1 = d1, ..., Tn+k pn+k = dk]) => | ||
/// u.m<X1, ..., Xs>(p1, ..., pn+k); | ||
/// ``` | ||
/// where `f` is an instance method named `m` which has type parameter | ||
/// declarations `X1 extends B1, ..., Xs extends Bs`, required parameters | ||
/// `p1, ..., pn`, and optional positional parameters `pn+1, ..., pn+k` with | ||
/// defaults `d1, ..., dk`, using `null` for parameters whose default value is | ||
/// not specified. | ||
/// ... | ||
/// The parameter types `Tj,j ∈ 1..n + k`, are determined as follows: Let the | ||
/// method declaration `D` be the implementation of `m` which is invoked by the | ||
/// expression in the body. Let `T` be the class that contains D. | ||
/// | ||
/// For each parameter `pj, j ∈ 1..n + k`, if `pj` is covariant then `Tj` is | ||
/// the built-in class `Object`. | ||
/// | ||
/// @description Check that if `pj` is covariant then `Tj` is `Object?` at | ||
/// run time. | ||
/// @author [email protected] | ||
import '../../../../Utils/expect.dart'; | ||
import '../../../../Utils/static_type_helper.dart'; | ||
|
||
class C<X extends num> { | ||
X m<Y extends X>(covariant X r1, covariant Y r2, [covariant int? p1]) { | ||
return 42 as X; | ||
} | ||
} | ||
|
||
main() { | ||
var o = C<num>(); | ||
final f = o.m; | ||
f.expectStaticType< | ||
Exactly<num Function<Y extends num>(num r1, Y r2, [int? p1])> | ||
>(); | ||
|
||
Expect.isTrue( | ||
f is num Function<Y extends num>(Object? r1, Object? r2, [Object? p1])); | ||
} |