|
| 1 | +// Copyright (c) 2024, 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 A record is created using a record expression. The grammar is: |
| 6 | +/// |
| 7 | +/// literal ::= record |
| 8 | +/// | // Existing literal productions... |
| 9 | +/// record ::= 'const'? '(' recordField ( ',' recordField )* ','? ')' |
| 10 | +/// recordField ::= (identifier ':' )? expression |
| 11 | +/// |
| 12 | +/// This is identical to the grammar for a function call argument list. There |
| 13 | +/// are a couple of syntactic restrictions not captured by the grammar. It is a |
| 14 | +/// compile-time error if a record has any of: |
| 15 | +/// |
| 16 | +/// The same field name more than once. |
| 17 | +/// |
| 18 | +/// Only one positional field and no trailing comma. |
| 19 | +/// |
| 20 | +/// No fields and a trailing comma. The expression (,) isn't allowed. |
| 21 | +/// |
| 22 | +/// A field named hashCode, runtimeType, noSuchMethod, or toString. |
| 23 | +/// |
| 24 | +/// A field name that starts with an underscore. |
| 25 | +/// |
| 26 | +/// A field name that collides with the synthesized getter name of a positional |
| 27 | +/// field. For example: ('pos', $1: 'named') since the named field '$1' collides |
| 28 | +/// with the getter for the first positional field. |
| 29 | +/// |
| 30 | +/// @description Checks that it is a compile-time error if a record has one |
| 31 | +/// named field with no trailing comma |
| 32 | + |
| 33 | +
|
| 34 | +void foo((int,) r) {} |
| 35 | + |
| 36 | +(String,) bar() => ("No trailing comma"); |
| 37 | +// ^^^^^^^^^^^^^^^^^^^ |
| 38 | +// [analyzer] unspecified |
| 39 | +// [cfe] unspecified |
| 40 | + |
| 41 | +main() { |
| 42 | + foo((1)); |
| 43 | +// ^^^ |
| 44 | +// [analyzer] unspecified |
| 45 | +// [cfe] unspecified |
| 46 | + print(bar); |
| 47 | +} |
0 commit comments