Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2142. Change dynamic semantics inline class tests to be extension type tests #2188

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion At run time, for a given instance o typed as an inline type V,
/// @assertion At run time, for a given instance o typed as an extension type V,
/// there is no reification of V associated with o.
///
/// @description Check that the run-time type of an instance of an inline class
/// is its representation type
/// @description Check that the run-time type of an instance of an extension
/// type is its representation type
/// @author [email protected]

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

inline class V2<T> {
final T id;
V2(this.id);
}
extension type V2<T>(T id) {}

main() {
var v1 = V1(42);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion The run-time representation of a type argument which is an inline
/// type V is the corresponding instantiated representation type.
/// @assertion The run-time representation of a type argument which is an
/// extension type V is the run-time representation of the corresponding
/// instantiated representation type.
///
/// @description Check that the run-time representation of a type argument which
/// is an inline type V is the corresponding instantiated representation type.
/// is an extension type is the the run-time representation of the corresponding
/// instantiated representation type.
/// @author [email protected]

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

extension type V2<T>(T id) {}

inline class V2<T> {
final T id;
V2(this.id);
class C<T> {
T x;
C(this.x);
}

main() {
List<V1> l1 = [];
Expect.equals(List<int>, l1.runtimeType);
(l1 as List<int>).add(42);
Expect.throws(() { (l1 as dynamic).add(3.14);});

List<V2<String>> l2 = [];
Expect.equals(List<String>, l2.runtimeType);
(l2 as List<String>).add("42");
Expect.throws(() { (l2 as dynamic).add(42);});
var l1 = C<V1>(V1(1));
Expect.equals(C<int>, l1.runtimeType);
(l1 as C<int>).x = 42;
Expect.equals(42, l1.x);
Expect.throws(() { (l1 as dynamic).x = 3.14;});

C<V2<String>> l2 = C<V2<String>>(V2("42"));
Expect.equals(C<String>, l2.runtimeType);
(l2 as C<String>).x = "answer";
Expect.throws(() { (l2 as dynamic).x = 42;});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion A type test, o is U or o is! U, and a type cast, o as U, where U
/// is or contains an inline type, is performed at run time as a type test and
/// type cast on the run-time representation of the inline type
/// @assertion A type test, `o is U` or `o is! U`, and a type cast, `o as U`,
/// where `U` is or contains an extension type, is performed at run time as a
/// type test and type cast on the run-time representation of the extension type
///
/// @description Check that at run time a type test, `o is U` or `o is! U` is
/// performed as a type test on the run-time representation of the inline type
/// performed as a type test on the run-time representation of the extension
/// type
/// @author [email protected]

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

inline class V2<T> {
final T id;
V2(this.id);
}
extension type V2<T>(T id) {}

void main() {
var objects = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion A type test, o is U or o is! U, and a type cast, o as U, where U
/// is or contains an inline type, is performed at run time as a type test and
/// type cast on the run-time representation of the inline type
/// @assertion A type test, `o is U` or `o is! U`, and a type cast, `o as U`,
/// where `U` is or contains an extension type, is performed at run time as a
/// type test and type cast on the run-time representation of the extension type
///
/// @description Check that at run time a type cast, `o as U` is performed as a
/// type cast on the run-time representation of the inline type
/// type cast on the run-time representation of the extension type
/// @author [email protected]

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

inline class V2<T> {
final T id;
V2(this.id);
}
extension type V2<T>(T id) {}

bool testAsInt(Object instance) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion An inline type V used as an expression (a type literal) evaluates
/// to the value of the corresponding instantiated representation type used as
/// an expression.
/// @assertion An extension type V used as an expression (a type literal)
/// evaluates to the value of the extension type erasure of the representation
/// type used as an expression
///
/// @description Check that if an inline type `V` is used as an expression then
/// @description Check that if an extension type is used as an expression then
/// it evaluates to the value of the corresponding instantiated representation
/// type
/// @author [email protected]
Expand All @@ -15,15 +15,9 @@

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

inline class V2<T> {
final T Function(int) f;
V2(this.f);
}
extension type V2<T>(T Function(int) id) {}

main() {
Expect.equals(int, V1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion Consider an inline class declaration DV named Inline with
/// @assertion Consider an extension type declaration DV named Name with
/// representation name id and representation type R. Invocation of a
/// non-redirecting generative inline class constructor proceeds as follows:
/// non-redirecting generative extension type constructor proceeds as follows:
/// A fresh, non-late, final variable v is created. An initializing formal
/// this.id has the side-effect that it initializes v to the actual argument
/// passed to this formal. An initializer list element of the form id = e or
Expand All @@ -13,23 +13,18 @@
/// value of v. The value of the instance creation expression that gave rise to
/// this constructor execution is the value of this.
///
/// @description Check that during the execution of the constructor body, this
/// and `id` are bound to the value of `v`
/// @description Check that during the execution of the constructor body, `this`
/// and `id` are bound to the value of `v`. Check the default constructor
/// introduced by representation declaration
/// @author [email protected]

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

inline class V1 {
final int id;
V1(this.id);
}
extension type V1(int id) {}

inline class V2<T> {
final T id;
V2(this.id);
}
extension type V2<T>(T id) {}

main() {
int i = 42;
Expand Down