Skip to content

Commit bb679a0

Browse files
authored
#3315. Update assertions. Add test for setters. (#3347)
1 parent 87098a9 commit bb679a0

File tree

6 files changed

+118
-37
lines changed

6 files changed

+118
-37
lines changed

LanguageFeatures/Declaring-constructors/static_processing_A11_t01.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
1616
/// occur as follows:
1717
///
18-
/// Assume that `p` is an formal parameter in `D` which has the modifier `var`
19-
/// or the modifier `final` (that is, p is a declaring parameter).
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
2020
///
21-
/// Assume that the combined member signature for a getter with the same name as
22-
/// `p` from the superinterfaces of `D` exists, and has return type `T`. In that
23-
/// case the parameter `p` has declared type `T` as well.
21+
/// Consider the situation where `p` has no type annotation:
22+
/// - if combined member signature for a getter with the same name as `p` from
23+
/// the superinterfaces of `D` exists and has return type `T`, the parameter
24+
/// `p` has declared type `T`. If no such getter exists, but a setter with the
25+
/// same basename exists, with a formal parameter whose type is `T`, the
26+
/// parameter `p` has declared type `T`.
2427
///
2528
/// @description Check that if the combined member signature for a getter with
2629
/// the same name as `p` from the superinterfaces of `D` exists, and has return
@@ -58,6 +61,10 @@ class C5(var x, {var y = 2}) extends A2;
5861

5962
class C6(final x, {final y = 3}) extends A3;
6063

64+
class C7(var x, {required var y}) extends A1;
65+
66+
class C8(final x, {required final y}) extends A2;
67+
6168
main() {
6269
C1(1).x.expectStaticType<Exactly<num>>();
6370
C1(1).y.expectStaticType<Exactly<num>>();
@@ -71,4 +78,8 @@ main() {
7178
C5(5).y.expectStaticType<Exactly<num>>();
7279
C6(6).x.expectStaticType<Exactly<num>>();
7380
C6(6).y.expectStaticType<Exactly<num>>();
81+
C7(7, y: 7).x.expectStaticType<Exactly<num>>();
82+
C7(7, y: 7).y.expectStaticType<Exactly<num>>();
83+
C8(8, y: 8).x.expectStaticType<Exactly<num>>();
84+
C8(8, y: 8).y.expectStaticType<Exactly<num>>();
7485
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion The following applies to both the header and the body form of
6+
/// declaring constructors.
7+
///
8+
/// The semantics of the declaring constructor is found in the following steps,
9+
/// where `D` is the class, extension type, or enum declaration in the program
10+
/// that includes a declaring constructor, and `D2` is the result of the
11+
/// derivation of the semantics of `D`. The derivation step will delete elements
12+
/// that amount to the declaring constructor; it will add a new constructor `k`;
13+
/// and it will add zero or more instance variable declarations.
14+
///
15+
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
16+
/// occur as follows:
17+
///
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
20+
///
21+
/// Consider the situation where `p` has no type annotation:
22+
/// - if combined member signature for a getter with the same name as `p` from
23+
/// the superinterfaces of `D` exists and has return type `T`, the parameter
24+
/// `p` has declared type `T`. If no such getter exists, but a setter with the
25+
/// same basename exists, with a formal parameter whose type is `T`, the
26+
/// parameter `p` has declared type `T`.
27+
///
28+
/// @description Check that if the combined member signature for a setter with
29+
/// the same basename as `p` from the superinterfaces of `D` exists, and has a
30+
/// formal parameter type `T` then the parameter `p` has declared type `T` as
31+
/// well.
32+
/// @author sgrekhov22@gmail.com
33+
34+
// SharedOptions=--enable-experiment=declaring-constructors
35+
36+
import '../../Utils/static_type_helper.dart';
37+
38+
class A {
39+
void set x(num x) {}
40+
void set y(num x) {}
41+
}
42+
43+
class C1(var x, [var y = 1]) extends A;
44+
45+
class C2(final x, [final y = 2]) extends A;
46+
47+
class C3(final x, {final y = 1}) extends A;
48+
49+
class C4(var x, {var y = 2}) extends A;
50+
51+
class C5(final x, {required final y}) extends A;
52+
53+
class C6(var x, {required var y}) extends A;
54+
55+
main() {
56+
C1(1).x.expectStaticType<Exactly<num>>();
57+
C1(1).y.expectStaticType<Exactly<num>>();
58+
C2(2).x.expectStaticType<Exactly<num>>();
59+
C2(2).y.expectStaticType<Exactly<num>>();
60+
C3(3).x.expectStaticType<Exactly<num>>();
61+
C3(3).y.expectStaticType<Exactly<num>>();
62+
C4(4).x.expectStaticType<Exactly<num>>();
63+
C4(4).y.expectStaticType<Exactly<num>>();
64+
C5(5, y: 5).x.expectStaticType<Exactly<num>>();
65+
C5(5, y: 5).y.expectStaticType<Exactly<num>>();
66+
C6(6, y: 6).x.expectStaticType<Exactly<num>>();
67+
C6(6, y: 6).y.expectStaticType<Exactly<num>>();
68+
}

LanguageFeatures/Declaring-constructors/static_processing_A12_t01.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
1616
/// occur as follows:
1717
///
18-
/// Assume that `p` is an formal parameter in `D` which has the modifier `var`
19-
/// or the modifier `final` (that is, p is a declaring parameter).
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
20+
///
21+
/// Consider the situation where `p` has no type annotation:
2022
/// ...
21-
/// Otherwise, assume that `p` does not have a declared type, but it does have a
22-
/// default value whose static type in the empty context is a type (not a type
23-
/// schema) `T` which is not `Null`. In that case `p` is considered to have the
24-
/// declared type `T`. When `T` is `Null`, `p` is considered to have the
25-
/// declared type `Object?`. If `p` does not have a declared type nor a default
26-
/// value then `p` is considered to have the declared type `Object?`.
23+
/// - otherwise, if `p` is optional and has a default value whose static type in
24+
/// the empty context is a type `T` which is not `Null` then `p` has declared
25+
/// type `T`. When `T` is `Null`, `p` has declared type `Object?`.
2726
///
2827
/// @description Check that if `p` does not have a declared type, but it does
2928
/// have a default value whose static type is `T` which is not `Null` then `p`

LanguageFeatures/Declaring-constructors/static_processing_A12_t02.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
1616
/// occur as follows:
1717
///
18-
/// Assume that `p` is an formal parameter in `D` which has the modifier `var`
19-
/// or the modifier `final` (that is, p is a declaring parameter).
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
20+
///
21+
/// Consider the situation where `p` has no type annotation:
2022
/// ...
21-
/// Otherwise, assume that `p` does not have a declared type, but it does have a
22-
/// default value whose static type in the empty context is a type (not a type
23-
/// schema) `T` which is not `Null`. In that case `p` is considered to have the
24-
/// declared type `T`. When `T` is `Null`, `p` is considered to have the
25-
/// declared type `Object?`. If `p` does not have a declared type nor a default
26-
/// value then `p` is considered to have the declared type `Object?`.
23+
/// - otherwise, if `p` is optional and has a default value whose static type in
24+
/// the empty context is a type `T` which is not `Null` then `p` has declared
25+
/// type `T`. When `T` is `Null`, `p` has declared type `Object?`.
2726
///
2827
/// @description Check that if `p` does not have a declared type, but it does
2928
/// have a default value whose static type is `Null` then `p` has the declared

LanguageFeatures/Declaring-constructors/static_processing_A12_t03.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
1616
/// occur as follows:
1717
///
18-
/// Assume that `p` is an formal parameter in `D` which has the modifier `var`
19-
/// or the modifier `final` (that is, p is a declaring parameter).
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
20+
///
21+
/// Consider the situation where `p` has no type annotation:
2022
/// ...
21-
/// Otherwise, assume that `p` does not have a declared type, but it does have a
22-
/// default value whose static type in the empty context is a type (not a type
23-
/// schema) `T` which is not `Null`. In that case `p` is considered to have the
24-
/// declared type `T`. When `T` is `Null`, `p` is considered to have the
25-
/// declared type `Object?`. If `p` does not have a declared type nor a default
26-
/// value then `p` is considered to have the declared type `Object?`.
23+
/// - otherwise, if `p` does not have a default value then `p` has declared type
24+
/// `Object?`.
2725
///
2826
/// @description Check that if `p` does not have a declared type nor a default
2927
/// value then `p` is considered to have the declared type `Object?`.
@@ -41,6 +39,10 @@ class C3(final x, {final y});
4139

4240
class C4(var x, {var x});
4341

42+
class C5(final x, {required final y});
43+
44+
class C6(var x, {required var x});
45+
4446
main() {
4547
C1(1).x.expectStaticType<Exactly<Object?>>();
4648
C1(1).y.expectStaticType<Exactly<Object?>>();
@@ -50,4 +52,8 @@ main() {
5052
C3(3).y.expectStaticType<Exactly<Object?>>();
5153
C4(4).x.expectStaticType<Exactly<Object?>>();
5254
C4(4).y.expectStaticType<Exactly<Object?>>();
55+
C5(5, y: 5).x.expectStaticType<Exactly<Object?>>();
56+
C5(5, y: 5).y.expectStaticType<Exactly<Object?>>();
57+
C6(6, y: 6).x.expectStaticType<Exactly<Object?>>();
58+
C6(6, y: 6).y.expectStaticType<Exactly<Object?>>();
5359
}

LanguageFeatures/Declaring-constructors/static_processing_A12_t04.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
/// Where no processing is mentioned below, `D2` is identical to `D`. Changes
1616
/// occur as follows:
1717
///
18-
/// Assume that `p` is an optional formal parameter in `D` which has the
19-
/// modifier `var` or the modifier `final` (that is, p is a declaring parameter).
18+
/// Let `p` be a formal parameter in `k` which has the modifier `var` or the
19+
/// modifier `final` (that is, `p` is a declaring parameter).
20+
///
21+
/// Consider the situation where `p` has no type annotation:
2022
/// ...
21-
/// Otherwise, assume that `p` does not have a declared type, but it does have a
22-
/// default value whose static type in the empty context is a type (not a type
23-
/// schema) `T` which is not `Null`. In that case `p` is considered to have the
24-
/// declared type `T`. When `T` is `Null`, `p` is considered to have the
25-
/// declared type `Object?`. If `p` does not have a declared type nor a default
26-
/// value then `p` is considered to have the declared type `Object?`.
23+
/// - otherwise, if `p` does not have a default value then `p` has declared type
24+
/// `Object?`.
2725
///
2826
/// @description Check that if `p` does not have a declared type and its default
2927
/// value is `Null` or absent then the declared type of `p` is `Object?` not

0 commit comments

Comments
 (0)