Skip to content

#1399. [Records] Type annotations and record expressions tests updated #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions LanguageFeatures/Records/record_expressions_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
/// record ::= 'const'? (' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
Expand All @@ -15,13 +15,16 @@
///
/// The same field name more than once.
///
/// No named fields and only one positional field. This avoids ambiguity with
/// parenthesized expressions.
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is a compile-time error if a record has the same
/// field name more than once
/// @author [email protected]
Expand Down
9 changes: 6 additions & 3 deletions LanguageFeatures/Records/record_expressions_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
Expand All @@ -15,13 +15,16 @@
///
/// The same field name more than once.
///
/// No named fields and only one positional field. This avoids ambiguity with
/// parenthesized expressions.
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is a compile-time error if a record has the same
/// field name more than once
/// @author [email protected]
Expand Down
33 changes: 29 additions & 4 deletions LanguageFeatures/Records/record_expressions_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
Expand All @@ -15,19 +15,34 @@
///
/// The same field name more than once.
///
/// No named fields and only one positional field. This avoids ambiguity with
/// parenthesized expressions.
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is a compile-time error if a record has no named
/// fields and only one positional field
/// fields and only one positional field with no trailing comma
/// @author [email protected]

// SharedOptions=--enable-experiment=records

Record foo1() => (42);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

Record foo2() => ((42));
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

void bar(Record r) {}

main() {
Record r1 = (42);
// ^^
Expand All @@ -37,5 +52,15 @@ main() {
Record r2 = ((42));
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

bar(("Hello"));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

bar((("Hello")));
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
51 changes: 28 additions & 23 deletions LanguageFeatures/Records/record_expressions_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
Expand All @@ -15,39 +15,44 @@
///
/// The same field name more than once.
///
/// No named fields and only one positional field. This avoids ambiguity with
/// parenthesized expressions.
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// @description Checks that it is a compile-time error if a record has no named
/// fields and only one positional field
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is no error if a record has no named fields and
/// only one positional field but with a trailing comma
/// @author [email protected]

// SharedOptions=--enable-experiment=records

Record foo1() => (42);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
import "../../Utils/expect.dart";

Record foo1() => (1,);

Record foo2() => ((2),);

Record foo2() => ((42));
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Record foo3() => ((3,),);

void bar(Record r) {}
dynamic bar(Record r) => r

main() {
bar(("Hello"));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

bar((("Hello")));
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
var r1 = (1,);
var r2 = ((2),);
var r3 = ((3,),);

Expect.equals(1, r1.$0);
Expect.equals(2, r2.$0);
Expect.equals(3, r2.$0.$0);

Expect.equals(1, foo1().$0);
Expect.equals(2, foo2().$0);
Expect.equals((3,), foo3().$0);
Expect.equals(("Hello",), bar(("Hello",)));
Expect.equals(("Hello",), bar((("Hello"),)));
}
61 changes: 61 additions & 0 deletions LanguageFeatures/Records/record_expressions_A02_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2022, 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 record is created using a record expression. The grammar is:
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
/// are a couple of syntactic restrictions not captured by the grammar. It is a
/// compile-time error if a record has any of:
///
/// The same field name more than once.
///
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is no error if a record has trailing commas
/// @author [email protected]

// SharedOptions=--enable-experiment=records

import "../../Utils/expect.dart";

Record foo1() => (1, 2,);

Record foo2() => ((2), (3),);

Record foo3() => ((3, n: 4,), n2: "", true,);

dynamic bar(Record r) => r

main() {
var r1 = (1, n: "n",);
var r2 = ((2), 3,);
var r3 = ((3,), n: Record.empty, (4),);

Expect.equals(1, r1.$0);
Expect.equals("n", r1.n);
Expect.equals(2, r2.$0);
Expect.equals(3, r2.$1);
Expect.equals(3, r3.$0.$0);
Expect.equals(4, r3.$1);
Expect.equals(Record.empty, r3.n);

Expect.equals((1, 2), foo1());
Expect.equals((2, 3), foo2());
Expect.equals(((3, n: 4), n2: "", true), foo3());
Expect.equals(("Hello", 1), bar(("Hello", 1,)));
Expect.equals((n1: "n1", n2: "n2"), bar((n1: "n1", n2: "n2",));
}
96 changes: 96 additions & 0 deletions LanguageFeatures/Records/record_expressions_A02_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2022, 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 record is created using a record expression. The grammar is:
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
/// are a couple of syntactic restrictions not captured by the grammar. It is a
/// compile-time error if a record has any of:
///
/// The same field name more than once.
///
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is a compile-time error if a record has more
/// than one trailing comma
/// @author [email protected]

// SharedOptions=--enable-experiment=records

Record foo1() => (1,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo2() => ((2),,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo3() => ((3,,),);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo4() => ((3,),,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo5() => (n1: 1,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo6() => ((2), n: 3,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

Record foo7() => (1, 2, n: 3, 4,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

dynamic bar(Record r) => r

main() {
var r1 = (1,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

var r2 = ((2),,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

var r3 = ((3,),,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

var r4 = (n1: 1,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified

var r5 = (1, 2, n: "n", 3,,);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
9 changes: 6 additions & 3 deletions LanguageFeatures/Records/record_expressions_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// literal ::= record
/// | // Existing literal productions...
/// record ::= '(' recordField ( ',' recordField )* ','? ')'
/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')'
/// recordField ::= (identifier ':' )? expression
///
/// This is identical to the grammar for a function call argument list. There
Expand All @@ -15,13 +15,16 @@
///
/// The same field name more than once.
///
/// No named fields and only one positional field. This avoids ambiguity with
/// parenthesized expressions.
/// Only one positional field and no trailing comma.
///
/// A field named hashCode, runtimeType, noSuchMethod, or toString.
///
/// A field name that starts with an underscore.
///
/// A field name that collides with the synthesized getter name of a positional
/// field. For example: ('pos', $0: 'named') since the named field '$0' collides
/// with the getter for the first positional field.
///
/// @description Checks that it is a compile-time error if a record has a field
/// named `hashCode`, `runtimeType`, `noSuchMethod`, or `toString`
/// @author [email protected]
Expand Down
Loading