Skip to content

Commit c513372

Browse files
committed
[tests] Dot Shorthands: .call() tests.
Adding tests for calling .call() on the dot shorthand getters/fields. Bug: #57038 Change-Id: Ibdacd2bb9feba617f96996dd467328dbdb55c7b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417904 Reviewed-by: Erik Ernst <[email protected]>
1 parent 656680e commit c513372

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// `id()` calls the `call()` method of the type of `id` if `id` is a getter or
6+
// field. It's a compile-time error if that `call` method does not exist.
7+
8+
// SharedOptions=--enable-experiment=dot-shorthands
9+
10+
class C {
11+
const C();
12+
static C get id1 => const C();
13+
static C id2 = const C();
14+
}
15+
16+
void main() {
17+
C c1 = .id1();
18+
// ^
19+
// [analyzer] unspecified
20+
// [cfe] unspecified
21+
22+
C c2 = .id2();
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// `id()` calls the `call()` method of the type of `id` if `id` is a getter or
6+
// field.
7+
8+
// SharedOptions=--enable-experiment=dot-shorthands
9+
10+
class C {
11+
const C();
12+
static C get id1 => const C();
13+
static C id2 = const C();
14+
15+
C call() => const C();
16+
}
17+
18+
void main() {
19+
C c1 = .id1();
20+
C c2 = .id2();
21+
}

0 commit comments

Comments
 (0)