Skip to content

Commit 678f561

Browse files
kallentucommit-bot@chromium.org
authored andcommitted
Syntax tests for disabled variance flag.
Change-Id: I796db1ce44b37e65bd4633abb962004a6e079041 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117288 Reviewed-by: Leaf Petersen <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent b510b91 commit 678f561

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2019, 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+
// Tests that since `variance` flag is disabled, correct variance modifier usage will issue an error.
6+
7+
class A<in X> {}
8+
// ^^
9+
// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME
10+
// [cfe] Expected an identifier, but got 'in'.
11+
// ^^
12+
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
13+
// ^
14+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
15+
// [cfe] Expected ',' before this.
16+
17+
class B<out X, in Y, inout Z> {}
18+
// ^
19+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
20+
// [cfe] Expected ',' before this.
21+
// ^^
22+
// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME
23+
// [cfe] Expected an identifier, but got 'in'.
24+
// ^^
25+
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
26+
// ^
27+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
28+
// [cfe] Expected ',' before this.
29+
// ^
30+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
31+
// [cfe] Expected ',' before this.
32+
33+
mixin C<inout T> {}
34+
// ^
35+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
36+
// [cfe] Expected ',' before this.
37+
38+
typedef D<out T> = T Function();
39+
// ^
40+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
41+
// [cfe] Expected ',' before this.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2019, 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+
// Tests identifier usage of keywords `out` and `inout`, correct usage of `in`.
6+
7+
import "package:expect/expect.dart";
8+
9+
class OutParameter {
10+
var out = 3;
11+
int func(int out) {
12+
return out;
13+
}
14+
}
15+
16+
class inout {
17+
void out(int x) {}
18+
}
19+
20+
var out = 5;
21+
22+
main() {
23+
OutParameter x = new OutParameter();
24+
Expect.equals(2, x.func(2));
25+
Expect.equals(3, x.out);
26+
27+
inout foo = inout();
28+
foo.out(4);
29+
30+
Expect.equals(5, out);
31+
32+
var collection = [0, 1, 2];
33+
for (var x in collection) {
34+
Expect.isTrue(x is int);
35+
}
36+
}

0 commit comments

Comments
 (0)