Skip to content

Commit 150c9f1

Browse files
committed
dart-lang#1399. Object member names are not allowed for positional fields names
1 parent 0c2b4c6 commit 150c9f1

14 files changed

+297
-48
lines changed

LanguageFeatures/Records/record_type_annotations_A04_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A04_t02.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A04_t03.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A04_t04.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A04_t05.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A04_t06.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///

LanguageFeatures/Records/record_type_annotations_A05_t01.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///
@@ -23,7 +23,7 @@
2323
/// the getter for the first positional field.
2424
///
2525
/// @description Checks that it is a compile-time error if a record type has a
26-
/// field named `hashCode`
26+
/// named field named `hashCode`
2727
/// @author [email protected]
2828
2929
// SharedOptions=--enable-experiment=records
@@ -38,7 +38,7 @@ typedef (int, {int hashCode}) R2();
3838
// [analyzer] unspecified
3939
// [cfe] unspecified
4040

41-
typedef void R3((String s, {String hashCode}));
41+
typedef void R3((String s, {String hashCode}) r);
4242
// ^^^^^^^^
4343
// [analyzer] unspecified
4444
// [cfe] unspecified
@@ -48,7 +48,7 @@ typedef void R3((String s, {String hashCode}));
4848
// [analyzer] unspecified
4949
// [cfe] unspecified
5050

51-
void bar((int i, {bool hashCode})) {}
51+
void bar((int i, {bool hashCode}) r) {}
5252
// ^^^^^^^^
5353
// [analyzer] unspecified
5454
// [cfe] unspecified

LanguageFeatures/Records/record_type_annotations_A05_t02.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///
@@ -23,7 +23,7 @@
2323
/// the getter for the first positional field.
2424
///
2525
/// @description Checks that it is a compile-time error if a record type has a
26-
/// field named `runtimeType`
26+
/// named field named `runtimeType`
2727
/// @author [email protected]
2828
2929
// SharedOptions=--enable-experiment=records
@@ -38,7 +38,7 @@ typedef (int, {Type runtimeType}) R2();
3838
// [analyzer] unspecified
3939
// [cfe] unspecified
4040

41-
typedef void R3((String s, {String runtimeType}));
41+
typedef void R3((String s, {String runtimeType}) r);
4242
// ^^^^^^^^^^^
4343
// [analyzer] unspecified
4444
// [cfe] unspecified
@@ -48,7 +48,7 @@ typedef void R3((String s, {String runtimeType}));
4848
// [analyzer] unspecified
4949
// [cfe] unspecified
5050

51-
void bar((int i, {Type runtimeType})) {}
51+
void bar((int i, {Type runtimeType}) r) {}
5252
// ^^^^^^^^^^^
5353
// [analyzer] unspecified
5454
// [cfe] unspecified

LanguageFeatures/Records/record_type_annotations_A05_t03.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///
@@ -23,7 +23,7 @@
2323
/// the getter for the first positional field.
2424
///
2525
/// @description Checks that it is a compile-time error if a record type has a
26-
/// field named `noSuchMethod`
26+
/// named field named `noSuchMethod`
2727
/// @author [email protected]
2828
2929
// SharedOptions=--enable-experiment=records
@@ -38,7 +38,7 @@ typedef (int, {Function noSuchMethod}) R2();
3838
// [analyzer] unspecified
3939
// [cfe] unspecified
4040

41-
typedef void R3((String s, {String noSuchMethod}));
41+
typedef void R3((String s, {String noSuchMethod}) r);
4242
// ^^^^^^^^^^^^
4343
// [analyzer] unspecified
4444
// [cfe] unspecified
@@ -48,7 +48,7 @@ typedef void R3((String s, {String noSuchMethod}));
4848
// [analyzer] unspecified
4949
// [cfe] unspecified
5050

51-
void bar((int i, {Function noSuchMethod})) {}
51+
void bar((int i, {Function noSuchMethod}) r) {}
5252
// ^^^^^^^^^^^^
5353
// [analyzer] unspecified
5454
// [cfe] unspecified

LanguageFeatures/Records/record_type_annotations_A05_t04.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///
@@ -23,7 +23,7 @@
2323
/// the getter for the first positional field.
2424
///
2525
/// @description Checks that it is a compile-time error if a record type has a
26-
/// field named `toString`
26+
/// named field named `toString`
2727
/// @author [email protected]
2828
2929
// SharedOptions=--enable-experiment=records
@@ -38,7 +38,7 @@ typedef (int, {int toString}) R2();
3838
// [analyzer] unspecified
3939
// [cfe] unspecified
4040

41-
typedef void R3((String s, {String toString}));
41+
typedef void R3((String s, {String toString}) r);
4242
// ^^^^^^^^
4343
// [analyzer] unspecified
4444
// [cfe] unspecified
@@ -48,7 +48,7 @@ typedef void R3((String s, {String toString}));
4848
// [analyzer] unspecified
4949
// [cfe] unspecified
5050

51-
void bar((int i, {bool toString})) {}
51+
void bar((int i, {bool toString}) r) {}
5252
// ^^^^^^^^
5353
// [analyzer] unspecified
5454
// [cfe] unspecified

LanguageFeatures/Records/record_type_annotations_A05_t05.dart

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,65 @@
1414
/// symmetric with record expressions and leaves the potential for later support
1515
/// for parentheses for grouping in type expressions.
1616
///
17-
/// A named field named hashCode, runtimeType, noSuchMethod, or toString.
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
1818
///
1919
/// A field name that starts with an underscore.
2020
///
2121
/// A field name that collides with the synthesized getter name of a positional
2222
/// field. For example: (int, $0: int) since the named field '$0' collides with
2323
/// the getter for the first positional field.
2424
///
25-
/// @description Checks that optional name of a positional field may include
26-
/// `hashCode`, `runtimeType`, `noSuchMethod`, and `toString`
25+
/// @description Checks that it is a compile-time error if record contains a
26+
/// positional field named `hashCode`
2727
/// @author [email protected]
2828
2929
// SharedOptions=--enable-experiment=records
3030

31-
typedef R1 = (String hashCode, int runtimeType, Function noSuchMethod,
32-
String toString);
31+
typedef R1 = (int hashCode, {String s});
32+
// ^^^^^^^^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
3335

34-
typedef (int hashCode, Type runtimeType, Function noSuchMethod,
35-
String toString) R2();
36+
typedef (int hashCode, {int i}) R2();
37+
// ^^^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
3640

37-
typedef void R3((int hashCode, Type runtimeType, Function noSuchMethod,
38-
String toString) r);
41+
typedef void R3((String hashCode, {String s}) r);
42+
// ^^^^^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
3945

40-
(int? hashCode, Type? runtimeType, Function? noSuchMethod, String? toString)
41-
foo() => (null, null, null, null);
46+
(int hashCode, {int x}) foo() => (42, x: 0);
47+
// ^^^^^^^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
4250

43-
void bar((int hashCode, Type runtimeType, Function noSuchMethod,
44-
String toString) r) {}
51+
void bar((int hashCode, {bool b}) r) {}
52+
// ^^^^^^^^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
4555

4656
main() {
47-
(int? hashCode, Type? runtimeType, Function? noSuchMethod, String? toString)
48-
r1 = (null, null, null, null);
57+
(int hashCode, {String s}) r1 = (42, s: "");
58+
// ^^^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
4961

50-
dynamic d = (null, null, null, null);
51-
if (d is (int? hashCode, Type? runtimeType, Function? noSuchMethod,
52-
String? toString)) {
53-
}
62+
(double hashCode, {int i}) r2 = (3.14, i: 42);
63+
// ^^^^^^^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
5466

55-
d as (int? hashCode, Type? runtimeType, Function? noSuchMethod,
56-
String? toString);
67+
dynamic d = (1, 3.14);
68+
if (d is (int hashCode, {String s})) {
69+
// ^^^^^^^^
70+
// [analyzer] unspecified
71+
// [cfe] unspecified
72+
}
5773

58-
print(R1);
59-
print(R2);
60-
print(R3);
61-
print(foo);
62-
print(bar);
74+
d as (int hashCode, {double i});
75+
// ^^^^^^^^
76+
// [analyzer] unspecified
77+
// [cfe] unspecified
6378
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2022, 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 It is a compile-time error if a record type has any of:
6+
///
7+
/// The same field name more than once. This is true even if one or both of the
8+
/// colliding fields is positional. We could permit collisions with positional
9+
/// field names since they are only used for documentation, but we disallow it
10+
/// because it's confusing and not useful.
11+
///
12+
/// Only one positional field and no trailing comma. This isn't ambiguous, since
13+
/// there are no parenthesized type expressions in Dart. But prohibiting this is
14+
/// symmetric with record expressions and leaves the potential for later support
15+
/// for parentheses for grouping in type expressions.
16+
///
17+
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
18+
///
19+
/// A field name that starts with an underscore.
20+
///
21+
/// A field name that collides with the synthesized getter name of a positional
22+
/// field. For example: (int, $0: int) since the named field '$0' collides with
23+
/// the getter for the first positional field.
24+
///
25+
/// @description Checks that it is a compile-time error if record contains a
26+
/// positional field named `runtimeType`
27+
/// @author [email protected]
28+
29+
// SharedOptions=--enable-experiment=records
30+
31+
typedef R1 = (Type runtimeType, {String s});
32+
// ^^^^^^^^^^^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
typedef (Type runtimeType, {int i}) R2();
37+
// ^^^^^^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
typedef void R3((Type runtimeType, {String s}) r);
42+
// ^^^^^^^^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
(int runtimeType, {int x}) foo() => (42, x: 0);
47+
// ^^^^^^^^^^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
void bar((Type runtimeType, {bool b}) r) {}
52+
// ^^^^^^^^^^^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
55+
56+
main() {
57+
(int runtimeType, {String s}) r1 = (42, s: "");
58+
// ^^^^^^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
(double runtimeType, {int i}) r2 = (3.14, i: 42);
63+
// ^^^^^^^^^^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
dynamic d = (1, 3.14);
68+
if (d is (int runtimeType, {String s})) {
69+
// ^^^^^^^^^^^
70+
// [analyzer] unspecified
71+
// [cfe] unspecified
72+
}
73+
74+
d as (int runtimeType, {double i});
75+
// ^^^^^^^^^^^
76+
// [analyzer] unspecified
77+
// [cfe] unspecified
78+
}

0 commit comments

Comments
 (0)