Skip to content

Commit db4c511

Browse files
authored
#1400. Static analysis of inline class tests. Part 3 (#2071)
Static analysis of inline class tests, part 3. Note that LanguageFeatures/Inline-classes/syntax_A02_t14.dart contains a syntax error, which is intentional.
1 parent af3a268 commit db4c511

11 files changed

+367
-12
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2023, 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+
/// @assertion Let DV be an inline class declaration named Inline with type
6+
/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final
7+
/// instance variable with name id and type R.
8+
///
9+
/// We say that the declared representation type of Inline is R, and the
10+
/// instantiated representation type corresponding to Inline<T1,.. Ts> is
11+
/// [T1/X1, .. Ts/Xs]R.
12+
/// ...
13+
/// In the body of a member of an inline class declaration DV named Inline and
14+
/// declaring the type parameters X1, .. Xs, the static type of this is
15+
/// Inline<X1 .. Xs>. The static type of the representation name is the
16+
/// representation type.
17+
///
18+
/// @description Checks that static type of `this` in an inline class
19+
/// `Inline<X1 .. Xs>` is `Inline<X1 .. Xs>`
20+
/// @author [email protected]
21+
22+
// SharedOptions=--enable-experiment=inline-class
23+
24+
import "../../Utils/static_type_helper.dart";
25+
26+
inline class V1 {
27+
final int id;
28+
V1(this.id);
29+
30+
test() {
31+
this.expectStaticType<Exactly<V1>>();
32+
}
33+
}
34+
35+
inline class V2<T1, T2 extends num> {
36+
final int id;
37+
V2(this.id);
38+
39+
test() {
40+
this.expectStaticType<Exactly<V2<T1, T2>>>();
41+
}
42+
}
43+
44+
main() {
45+
V1(42).test();
46+
V2(42).test();
47+
V2<String, num>(42).test();
48+
V2<int, int>(42).test();
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2023, 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+
/// @assertion Let DV be an inline class declaration named V with representation
6+
/// type R. Assuming that all types have been fully alias expanded, we say that
7+
/// DV has a representation dependency on an inline class declaration DV2 if R
8+
/// contains an identifier id (possibly qualified) that resolves to DV2, or id
9+
/// resolves to an inline class declaration DV3 and DV3 has a representation
10+
/// dependency on DV2.
11+
///
12+
/// It is a compile-time error if an inline class declaration has a
13+
/// representation dependency on itself.
14+
///
15+
/// @description Checks that it is a compile-time error if an inline class has a
16+
/// dependency on itself.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
inline class V1 implements V2 {
22+
// ^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
final int id;
26+
V1(this.id);
27+
}
28+
29+
inline class V2 implements V3 {
30+
// ^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
final int id;
34+
V2(this.id);
35+
}
36+
37+
typedef V1Alias = V1;
38+
39+
inline class V3 implements V1Alias {
40+
// ^^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
final int id;
44+
V3(this.id);
45+
}
46+
47+
main() {
48+
print(V1);
49+
print(V2);
50+
print(V3);
51+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2023, 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+
/// @assertion Let DV be an inline class declaration named V with representation
6+
/// type R. Assuming that all types have been fully alias expanded, we say that
7+
/// DV has a representation dependency on an inline class declaration DV2 if R
8+
/// contains an identifier id (possibly qualified) that resolves to DV2, or id
9+
/// resolves to an inline class declaration DV3 and DV3 has a representation
10+
/// dependency on DV2.
11+
///
12+
/// It is a compile-time error if an inline class declaration has a
13+
/// representation dependency on itself.
14+
///
15+
/// @description Checks that it is a compile-time error if an inline class has a
16+
/// representation dependency on itself.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
inline class V1 {
22+
// ^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
final V2 v2;
26+
V1(this.v2);
27+
}
28+
29+
inline class V2 implements V1 {
30+
// ^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
final int id;
34+
V2(this.id);
35+
36+
V2 get v2 => V2(42);
37+
}
38+
39+
main() {
40+
print(V1);
41+
print(V2);
42+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The inline erasure of an inline type V is obtained by recursively
6+
/// replacing every subterm of V which is an inline type by the corresponding
7+
/// representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, inline or not, or mixin,
11+
/// or typedef, or function). Let BBj be the inline erasure of Bj, for j in
12+
/// 1 .. s. It is a compile-time error if X1 extends BB1, .. Xs extends BBs has
13+
/// any compile-time errors.
14+
///
15+
/// @description Checks that if `BBj` is the inline erasure of `Bj`, for `j` in
16+
/// `1 .. s`, then it is a compile-time error if
17+
/// `X1 extends BB1, .. Xs extends BBs` has any compile-time errors.
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class V<T> {
23+
final T id;
24+
V(this.id);
25+
}
26+
27+
void foo<X extends V<Y>, Y extends X>() {} // foo<X extends Y, Y extends X>()
28+
// ^^^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
main() {
33+
print(foo);
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2023, 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+
/// @assertion A compile-time error occurs if an inline class constructor
6+
/// includes a superinitializer
7+
///
8+
/// @description Checks that a compile-time error occurs if an inline class
9+
/// constructor includes a superinitializer
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=inline-class
13+
14+
inline class V1 {
15+
final int id;
16+
V1([this.id = 0]);
17+
V1.x(this.id);
18+
}
19+
20+
inline class V2 implements V1 {
21+
final int id = 0;
22+
V2() : super();
23+
// ^^^^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
V2.x(int i) : super.x(i);
28+
// ^^^^^^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
}
32+
33+
main() {
34+
V1(42);
35+
V2();
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2023, 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+
/// @assertion A compile-time error occurs if an inline class constructor
6+
/// declares a super parameter
7+
///
8+
/// @description Checks that a compile-time error occurs if an inline class
9+
/// constructor declares a super parameter
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=inline-class
13+
14+
inline class V1 {
15+
final int id;
16+
V1(this.id, [Object? _]);
17+
}
18+
19+
inline class V2 implements V1 {
20+
final int id;
21+
V2(this.id, super.id);
22+
// ^^^^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
V2.n(super.id);
27+
// ^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
main() {
33+
V2(42, 0);
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2023, 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+
/// @assertion An inline type V used as an expression (a type literal) is
6+
/// allowed and has static type Type.
7+
///
8+
/// @description Checks that an inline type `V` can be used as an expression (a
9+
/// type literal) is and has static type `Type`.
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=inline-class
13+
14+
import "../../Utils/static_type_helper.dart";
15+
16+
inline class V {
17+
final int id;
18+
V(this.id);
19+
}
20+
21+
main() {
22+
var t = V;
23+
t.expectStaticType<Exactly<Type>>();
24+
}

LanguageFeatures/Inline-classes/syntax_A02_t10.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414
/// <inlineMemberDeclaration> ::= <classMemberDefinition>
1515
///
1616
/// @description Checks that it is a compile-time error if a `final inline`
17-
/// class is extended by another `final inline` class in the same library
17+
/// class is implemented by another `final inline` class outside of the library
18+
/// where it is defined
1819
/// @author [email protected]
1920
2021
// SharedOptions=--enable-experiment=inline-class
2122

22-
final inline class FIC {
23-
final int id ;
24-
const FIC(this.id);
25-
}
23+
import "inline_class_lib.dart";
2624

27-
final inline class FIC2 extends FIC {
28-
// ^^^
25+
final inline class FIC implements FinalInlineClass {
26+
// ^^^^^^^^^^^^^^^^
2927
// [analyzer] unspecified
3028
// [cfe] unspecified
31-
const FIC2(int id): super(id);
29+
final int id = 0;
30+
FIC();
3231
}
3332

3433
main() {
35-
print(FIC2);
34+
print(FIC);
3635
}

LanguageFeatures/Inline-classes/syntax_A02_t11.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import "../../Utils/expect.dart";
2323

2424
final inline class FIC {
25-
final int id;
26-
const FIC(this.id);
25+
final int id = 0;
26+
const FIC();
2727
}
2828

2929
final inline class FIC2 implements FIC {
@@ -32,6 +32,6 @@ final inline class FIC2 implements FIC {
3232
}
3333

3434
main() {
35-
Expect.equals(1, FIC(1).id);
35+
Expect.equals(0, FIC().id);
3636
Expect.equals(2, FIC2(2).id);
3737
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2023, 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+
/// @assertion A rule for <inlineClassDeclaration> is added to the grammar,
6+
/// along with some rules for elements used in inline class declarations:
7+
///
8+
/// <inlineClassDeclaration> ::=
9+
/// 'final'? 'inline' 'class' <typeIdentifier> <typeParameters>? <interfaces>?
10+
/// '{'
11+
/// (<metadata> <inlineMemberDeclaration>)*
12+
/// '}'
13+
///
14+
/// <inlineMemberDeclaration> ::= <classMemberDefinition>
15+
///
16+
/// @description Checks that it is a compile-time error if an `inline` class has
17+
/// an `extends` clause
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class IC1 {
23+
final int id = 0;
24+
IC1();
25+
}
26+
27+
inline class IC2 extends IC1 {
28+
// ^^^^^^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
IC2(int id);
32+
}
33+
34+
final inline class FIC1 {
35+
final int id = 0;
36+
FIC1();
37+
}
38+
39+
final inline class FIC2 extends FIC1 {
40+
// ^^^^^^^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
FIC2(int id);
44+
}
45+
46+
main() {
47+
print(IC2);
48+
print(FIC2);
49+
}

0 commit comments

Comments
 (0)