Skip to content

Commit a93ffd7

Browse files
author
sgrekhov
committed
#912. More test for static analysis of external variables added
1 parent 47db76b commit a93ffd7

19 files changed

+564
-9
lines changed

LanguageFeatures/Abstract-external-fields/static_analysis_external_A01_t01.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external int i;
@@ -16,7 +23,7 @@
1623
external int i;
1724

1825
test() {
19-
i;
26+
int j = i;
2027
i = 42;
2128
}
2229

LanguageFeatures/Abstract-external-fields/static_analysis_external_A01_t02.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external var i;
@@ -16,7 +23,8 @@
1623
external var i;
1724

1825
test() {
19-
i;
26+
int j = i;
27+
String s = i;
2028
i = 42;
2129
i = "Lily was here";
2230
}

LanguageFeatures/Abstract-external-fields/static_analysis_external_A01_t03.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external int i;
@@ -14,6 +21,7 @@
1421
1522
*/
1623
import "../../Utils/expect.dart";
24+
1725
external int i1;
1826
external var i2;
1927

LanguageFeatures/Abstract-external-fields/static_analysis_external_A02_t01.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external final int i;

LanguageFeatures/Abstract-external-fields/static_analysis_external_A02_t02.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external final int i;

LanguageFeatures/Abstract-external-fields/static_analysis_external_A02_t03.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external final i;

LanguageFeatures/Abstract-external-fields/static_analysis_external_A02_t04.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
/**
7-
* @assertion An external variable declaration D is treated as an external getter declaration and possibly an external setter declaration. The setter is included if and only if D is non-final. The return type of the getter and the parameter type of the setter, if present, is the type of D (which may be declared explicitly, obtained by override inference, or defaulted to dynamic). The parameter of the setter, if present, has the modifier covariant if and only if D has the modifier covariant (the grammar only allows this modifier on external instance variables).
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
815
*
916
* @description Checks that declaration
1017
* external final int i1;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external int i1;
19+
* desugared as
20+
* class A {
21+
* external int get i1;
22+
* external void set i1(int _);
23+
24+
*/
25+
class A {
26+
external int i;
27+
28+
test() {
29+
int j = i;
30+
i = 42;
31+
}
32+
}
33+
34+
main() {
35+
new A();
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external var i1;
19+
* desugared as
20+
* class A {
21+
* external dynamic get i1;
22+
* external void set i1(dynamic _);
23+
24+
*/
25+
class A {
26+
external var i;
27+
28+
test() {
29+
i;
30+
i = 42;
31+
i = "Lily was here";
32+
}
33+
}
34+
35+
main() {
36+
new A();
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external var i1;
19+
* desugared as
20+
* class A {
21+
* external dynamic get i1;
22+
* external void set i1(dynamic _);
23+
24+
*/
25+
import "../../Utils/expect.dart";
26+
27+
class A {
28+
external int i1;
29+
external var i2;
30+
31+
test() {
32+
Expect.throws(() { i1;}, (e) => e is NoSuchMethodError);
33+
Expect.throws(() { i2;}, (e) => e is NoSuchMethodError);
34+
Expect.throws(() { i1 = 42;}, (e) => e is NoSuchMethodError);
35+
Expect.throws(() { i2 = 42;}, (e) => e is NoSuchMethodError);
36+
}
37+
}
38+
39+
main() {
40+
new A().test();
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external final int i1;
19+
* external final i2;
20+
* desugared as
21+
* class A {
22+
* external int get i1;
23+
* external dynamic get i2;
24+
25+
*/
26+
class A {
27+
external final int i1;
28+
external final i2;
29+
30+
test() {
31+
int j = i1;
32+
int k = i2;
33+
String s = i2;
34+
}
35+
}
36+
37+
main() {
38+
new A();
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external final int i1;
19+
* external final i2;
20+
* desugared as
21+
* class A {
22+
* external int get i1;
23+
* external dynamic get i2;
24+
25+
*/
26+
class A {
27+
external final int i1;
28+
external final i2;
29+
30+
test() {
31+
i1 = 42;
32+
// ^^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
i2 = "Lily was here";
37+
// ^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
}
42+
43+
main() {
44+
new A();
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion An external variable declaration D is treated as an external
8+
* getter declaration and possibly an external setter declaration. The setter is
9+
* included if and only if D is non-final. The return type of the getter and the
10+
* parameter type of the setter, if present, is the type of D (which may be
11+
* declared explicitly, obtained by override inference, or defaulted to dynamic).
12+
* The parameter of the setter, if present, has the modifier covariant if and
13+
* only if D has the modifier covariant (the grammar only allows this modifier
14+
* on external instance variables).
15+
*
16+
* @description Checks that declaration
17+
* class A {
18+
* external final int i1;
19+
* external final i2;
20+
* desugared as
21+
* class A {
22+
* external int get i1;
23+
* external dynamic get i2;
24+
25+
*/
26+
import "../../Utils/expect.dart";
27+
28+
class A {
29+
external final int i1;
30+
external final i2;
31+
32+
test() {
33+
Expect.throws(() { i1;}, (e) => e is NoSuchMethodError);
34+
Expect.throws(() { i2;}, (e) => e is NoSuchMethodError);
35+
}
36+
}
37+
38+
main() {
39+
new A().test();
40+
}

0 commit comments

Comments
 (0)