Skip to content
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
58 changes: 58 additions & 0 deletions LanguageFeatures/Patterns/object_A07_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 objectPattern ::= typeName typeArguments? '(' patternFields? ')'
/// ...
/// It is a compile-time error if:
///
/// `typeNam`e does not refer to a type.
///
/// A type argument list is present and does not match the arity of the type of
/// `typeName`.
///
/// A `patternField` is of the form `pattern`. Positional fields aren't allowed.
///
/// Any two named fields have the same name. This applies to both explicit and
/// inferred field names.
///
/// It is a compile-time error if a name cannot be inferred for a named getter
/// pattern with the getter name omitted (see name inference below).
///
/// @description Checks that it is a compile-time error if a name cannot be
/// inferred for a named getter pattern with the getter name omitted. Test the
/// case when class has a getter named `_`
/// @author [email protected]

// SharedOptions=--enable-experiment=patterns,records

class C {
int get _ => 42;
}

main() {
C c = C();
switch (c) {
case C(:var _):
// ^
// [analyzer] unspecified
// [cfe] unspecified
print("matched");
break;
default:
print("not matched");
}

if (c case C(:var _)) {
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
var x = switch(c) {
C(:final _) => "match",
// ^
// [analyzer] unspecified
// [cfe] unspecified
_ => "no match"
};
}
46 changes: 46 additions & 0 deletions LanguageFeatures/Patterns/object_A07_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023, 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 objectPattern ::= typeName typeArguments? '(' patternFields? ')'
/// ...
/// It is a compile-time error if:
///
/// `typeNam`e does not refer to a type.
///
/// A type argument list is present and does not match the arity of the type of
/// `typeName`.
///
/// A `patternField` is of the form `pattern`. Positional fields aren't allowed.
///
/// Any two named fields have the same name. This applies to both explicit and
/// inferred field names.
///
/// It is a compile-time error if a name cannot be inferred for a named getter
/// pattern with the getter name omitted (see name inference below).
///
/// @description Check that wildcard `_` can be used in Object pattern in a
/// declaration context. Getter is called, but its value is ignored
/// @author [email protected]

// SharedOptions=--enable-experiment=patterns,records

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

String log = "";

void logger(String s) {
log += s;
}

main() {
var Square(area: _) = Square(2, logger);
Expect.equals("Square.area", log);

var Square(areaAsInt: int _) = Square(1);

Expect.throws(() {
var Square(areaAsInt: _ as String) = Square(1);
});
}