Skip to content

Commit ac0e211

Browse files
authored
#1400. Dynamic semantics inline class test added (#2082)
1 parent c426664 commit ac0e211

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
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 Consider an inline class declaration DV named Inline with
6+
/// representation name id and representation type R. Invocation of a
7+
/// non-redirecting generative inline class constructor proceeds as follows:
8+
/// A fresh, non-late, final variable v is created. An initializing formal
9+
/// this.id has the side-effect that it initializes v to the actual argument
10+
/// passed to this formal. An initializer list element of the form id = e or
11+
/// this.id = e is evaluated by evaluating e to an object o and binding v to o.
12+
/// During the execution of the constructor body, this and id are bound to the
13+
/// value of v. The value of the instance creation expression that gave rise to
14+
/// this constructor execution is the value of this.
15+
///
16+
/// @description Check that during the execution of the constructor body, this
17+
/// and `id` are bound to the value of `v`
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
import "../../Utils/expect.dart";
23+
24+
inline class V1 {
25+
final int id;
26+
V1(this.id);
27+
}
28+
29+
inline class V2<T> {
30+
final T id;
31+
V2(this.id);
32+
}
33+
34+
main() {
35+
int i = 42;
36+
var v1 = V1(i);
37+
Expect.identical(i, v1);
38+
39+
String s = "The String";
40+
var v2 = V2<String>(s);
41+
Expect.identical(s, v2);
42+
}

0 commit comments

Comments
 (0)