Skip to content

Commit 3bf29dc

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Test that generic metadata is unsupported inside function bodies.
Currently we don't support generic metadata, but we'll be adding support soon (dart-lang/language#1297). When we add it, we'll still want to have tests to make sure that it's not allowed in older language versions. The tests we currently have to make sure it's not allowed only test annotations occurring outside of function bodies, however the front end code paths for handling code inside function bodies are sufficiently different that it makes sense to test inside function bodies too. Bug: #44838 Change-Id: I846f2fc2e5ae090f21744ed6407b21a48a6d08ff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182601 Reviewed-by: Bob Nystrom <[email protected]>
1 parent 61b80d1 commit 3bf29dc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, 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+
// Check that annotations inside function bodies cannot use type arguments, but
6+
// can be raw.
7+
8+
class C<T> {
9+
const C();
10+
}
11+
12+
void ignore(dynamic value) {}
13+
14+
main() {
15+
@C()
16+
@C<dynamic>()
17+
//^
18+
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
19+
// [cfe] An annotation (metadata) can't use type arguments.
20+
@C<int>()
21+
//^
22+
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
23+
// [cfe] An annotation (metadata) can't use type arguments.
24+
int i = 0;
25+
ignore(i);
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, 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+
// Check that annotations inside function bodies cannot use type arguments, but
6+
// can be raw.
7+
8+
class C<T> {
9+
const C();
10+
}
11+
12+
void ignore(dynamic value) {}
13+
14+
main() {
15+
@C()
16+
@C<dynamic>()
17+
//^
18+
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
19+
// [cfe] An annotation (metadata) can't use type arguments.
20+
@C<int>()
21+
//^
22+
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
23+
// [cfe] An annotation (metadata) can't use type arguments.
24+
int i = 0;
25+
ignore(i);
26+
}

0 commit comments

Comments
 (0)