diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t03.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t03.dart new file mode 100644 index 0000000000..f76ce03bc3 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t03.dart @@ -0,0 +1,55 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Assume that T1, .. Ts are types, and V resolves to an inline +/// class declaration of the following form: +/// +/// inline class V ... { +/// final T id; +/// V(this.id); +/// +/// ... // Other members. +/// } +/// ... +/// When s is zero, V simply stands for V, a non-generic inline type. +/// When s is greater than zero, a raw occurrence V is treated like a raw type: +/// Instantiation to bound is used to obtain the omitted type arguments +/// +/// @description Checks that instantiation to bound is used to obtain the +/// omitted type arguments +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/static_type_helper.dart"; + +inline class V1 { + final int id; + V1(this.id); +} + +inline class V2 { + final int id; + V2(this.id); +} + +inline class V3 { + final int id; + V3(this.id); +} + +main() { + var v1 = V1(42); + v1.expectStaticType>>(); + + var v2 = V2(42); + v2.expectStaticType>>(); + + var v3 = V3(42); + v3.expectStaticType>>(); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t04.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t04.dart new file mode 100644 index 0000000000..9ac7cb2e18 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t04.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Assume that T1, .. Ts are types, and V resolves to an inline +/// class declaration of the following form: +/// +/// inline class V ... { +/// final T id; +/// V(this.id); +/// +/// ... // Other members. +/// } +/// ... +/// When s is zero, V simply stands for V, a non-generic inline type. +/// When s is greater than zero, a raw occurrence V is treated like a raw type: +/// Instantiation to bound is used to obtain the omitted type arguments +/// +/// @description Checks that instantiation to bound is used to obtain the +/// omitted type arguments. Test default bound +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/expect.dart"; + +inline class V1 { + final int id; + V1(this.id); + + Type get type => T; +} + +main() { + var v1 = V1(42); + Expect.equals(dynamic, v1.type); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A09_t01.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A09_t01.dart new file mode 100644 index 0000000000..96532d5e7b --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A09_t01.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and m is the name of a member that V has, a member access +/// like e.m(args) is treated as an invocation of the inline member m on the +/// receiver e according to the inline type Inline and with the actual type +/// arguments T1, ..., Ts, with the actual argument part args. +/// +/// @description Checks that a member access `e.m(args)` is treated as an +/// invocation of the inline member m on the receiver `e` according to the +/// inline type `Inline` and with the actual type arguments `T1, ..., Ts`, with +/// the actual argument part `args`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/static_type_helper.dart"; + +inline class V1 { + final T id; + V1(this.id); + + (Map, T) asMap() => ({}, id); +} + +main() { + V1 v1 = V1(42); + v1.asMap() + .expectStaticType, num)>>(); + + V1 v2 = V1("42"); + v2.asMap() + .expectStaticType, String)>>(); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A10_t01.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A10_t01.dart new file mode 100644 index 0000000000..e7dad03bd7 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A10_t01.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Similarly, e.m is treated an invocation of the inline member m on +/// the receiver e according to the inline type Inline and with the actual type +/// arguments T1, ..., Ts and no actual argument part. +/// +/// @description Checks that a member access `e.m` is treated as an invocation +/// of the inline member `m` on the receiver `e` according to the inline type +/// `Inline` and with the actual type arguments `T1, ..., Ts` and no actual +/// argument part +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/static_type_helper.dart"; + +inline class V1 { + final T id; + V1(this.id); + + (Map, T) get asMap => ({}, id); +} + +main() { + V1 v1 = V1(42); + v1.asMap.expectStaticType, num)>>(); + + V1 v2 = V1("42"); + v2.asMap.expectStaticType, String)>>(); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t01.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t01.dart new file mode 100644 index 0000000000..4025348668 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t01.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and V has no member whose basename is the basename of m, +/// a member access like e.m(args) may be an extension member access, following +/// the normal rules about applicability and accessibility of extensions, in +/// particular that V must match the on-type of the extension. +/// +/// @description Checks that if `V` has no member with the name `m`, but there +/// is an extension member `m` then it is invoked +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/expect.dart"; + +extension Ex1 on V { + String foo() => "Ex1.foo()"; +} + +extension Ex2 on int { + String bar() => "Ex2.bar()"; +} + +inline class V { + final int id; + V(this.id); +} + +main() { + V v = V(42); + Expect.equals("Ex1.foo()", v.foo()); + Expect.equals("Ex2.bar()", v.id.bar()); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t02.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t02.dart new file mode 100644 index 0000000000..e7ae01d60d --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t02.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and V has no member whose basename is the basename of m, +/// a member access like e.m(args) may be an extension member access, following +/// the normal rules about applicability and accessibility of extensions, in +/// particular that V must match the on-type of the extension. +/// +/// @description Checks that it is a compile-time error if `V` has no member +/// with name `m` and there is no extension member with the name `m` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +extension Ex1 on V { + String foo() => "Ex1.foo()"; +} + +extension Ex2 on int { + String bar() => "Ex2.bar()"; +} + +inline class V { + final int id; + V(this.id); +} + +main() { + V v = V(42); + v.bar(); +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v.id.foo(); +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t03.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t03.dart new file mode 100644 index 0000000000..884534d6a5 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t03.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and V has no member whose basename is the basename of m, +/// a member access like e.m(args) may be an extension member access, following +/// the normal rules about applicability and accessibility of extensions, in +/// particular that V must match the on-type of the extension. +/// +/// @description Checks that if `V` has no member with the name `m`, but there +/// is an extension member `m` then it is invoked +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/expect.dart"; + +extension Ex1 on V { + String foo() => "Ex1.foo()"; +} + +extension Ex2 on V { + String foo() => "Ex2.foo()"; +} + +extension Ex3 on int { + String foo() => "Ex3.foo()"; +} + +inline class V { + final T id; + V(this.id); +} + +main() { + V v1 = V("42"); + Expect.equals("Ex1.foo()", v1.foo()); + + V v2 = V(42); + Expect.equals("Ex2.foo()", v2.foo()); + Expect.equals("Ex3.foo()", v2.id.foo()); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t04.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t04.dart new file mode 100644 index 0000000000..324877e9ed --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t04.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and V has no member whose basename is the basename of m, +/// a member access like e.m(args) may be an extension member access, following +/// the normal rules about applicability and accessibility of extensions, in +/// particular that V must match the on-type of the extension. +/// +/// @description Checks that it is a compile-time error if `V` has no member +/// with name `m` and there is no extension member with the name `m` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +extension Ex1 on V { + String fooString() => "fooString"; +} + +extension Ex2 on V { + String fooInt() => "fooInt"; +} + +extension Ex3 on String { + String barString() => "barString"; +} + +extension Ex4 on int { + String barInt() => "barInt"; +} + +inline class V { + final T id; + V(this.id); +} + +main() { + V v1 = V("42"); + v1.fooInt(); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v1.id.fooString(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v1.barString(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v1.barInt(); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + V v2 = V(42); + v2.fooString(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v2.id.fooInt(); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v2.barString(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + v2.barInt(); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t05.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t05.dart new file mode 100644 index 0000000000..c8314ffb05 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t05.dart @@ -0,0 +1,50 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 If e is an expression whose static type V is the inline type +/// Inline and V has no member whose basename is the basename of m, +/// a member access like e.m(args) may be an extension member access, following +/// the normal rules about applicability and accessibility of extensions, in +/// particular that V must match the on-type of the extension. +/// +/// @description Checks that if a declaration named `m` is found in the body of +/// inline class then that invocation is treated as an invocation of the inline +/// member `m` on the receiver this according to its inline type +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "../../Utils/expect.dart"; + +extension E1 on int { + String foo() => "E1.foo"; +} + +inline class V1 { + final int it; + V1(this.it); + String foo() => "V1.foo"; + String baz() => "V1.baz"; + String qux() => "V1.qux"; +} + +String qux() => "qux"; + +inline class V2 { + final V1 it; + V2(this.it); + String foo() => "V2.foo"; + void test() { + Expect.equals("V2.foo", foo()); + Expect.equals("V1.foo",it.foo()); + Expect.equals("V1.baz",it.baz()); + Expect.equals("E1.foo", 1.foo()); + Expect.equals("qux", qux()); + } +} + +main() { + V2 v2 = V2(V1(42)); + v2.test(); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t01.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t01.dart new file mode 100644 index 0000000000..9ded2d3b59 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t01.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Let DV be an inline class declaration named Inline with type +/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final +/// instance variable with name id and type R. +/// +/// We say that the declared representation type of Inline is R, and the +/// instantiated representation type corresponding to Inline is +/// [T1/X1, .. Ts/Xs]R. +/// ... +/// Let V be an inline type of the form Inline, and let R be the +/// corresponding instantiated representation type. If R is non-nullable then V +/// is a proper subtype of Object, and V is non-nullable. Otherwise, V is a +/// proper subtype of Object?, and V is potentially nullable. +/// +/// @description Checks that if an instantiated representation type `R` is +/// non-nullable then an inline type `V` is non-nullable and it is a +/// compile-time error to assign null to it +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +inline class V1 { + final int it; + V1(this.it); +} + +inline class V2 { + final num id; + V2(this.id); +} + +main() { + V1 v1 = V1(42); + v1 = null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + V2 v2 = V2(3.14); + v2 = null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t02.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t02.dart new file mode 100644 index 0000000000..d16230f98f --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t02.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Let DV be an inline class declaration named Inline with type +/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final +/// instance variable with name id and type R. +/// +/// We say that the declared representation type of Inline is R, and the +/// instantiated representation type corresponding to Inline is +/// [T1/X1, .. Ts/Xs]R. +/// ... +/// Let V be an inline type of the form Inline, and let R be the +/// corresponding instantiated representation type. If R is non-nullable then V +/// is a proper subtype of Object, and V is non-nullable. Otherwise, V is a +/// proper subtype of Object?, and V is potentially nullable. +/// +/// @description Checks that if an instantiated representation type `R` is +/// non-nullable then it is a proper subtype of `Object` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +inline class V1 { + final int? id; + V1(this.id); +} + +inline class V2 { + final num? id; + V2(this.id); +} + +main() { + Object v1 = V1(42); + V1 v1_2 = v1 as V1; + Object v2 = V2(3.14); + V2 v2_2 = v2 as V2; +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t03.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t03.dart new file mode 100644 index 0000000000..45b124b479 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t03.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Let DV be an inline class declaration named Inline with type +/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final +/// instance variable with name id and type R. +/// +/// We say that the declared representation type of Inline is R, and the +/// instantiated representation type corresponding to Inline is +/// [T1/X1, .. Ts/Xs]R. +/// ... +/// Let V be an inline type of the form Inline, and let R be the +/// corresponding instantiated representation type. If R is non-nullable then V +/// is a proper subtype of Object, and V is non-nullable. Otherwise, V is a +/// proper subtype of Object?, and V is potentially nullable. +/// +/// @description Checks that if an instantiated representation type `R` is +/// not non-nullable then it is a proper subtype of `Object?` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +inline class V1 { + final int? id; + V1(this.id); +} + +inline class V2 { + final num? id; + V2(this.id); +} + +test1(X x) { + Object? o = x; + x?.id; +} + +test2?>(X x) { + Object? o = x; + x?.id; +} + +main() { + test1(V1(42)); + test2>(V2(42)); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t04.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t04.dart new file mode 100644 index 0000000000..b85e9e53c8 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t04.dart @@ -0,0 +1,61 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Let DV be an inline class declaration named Inline with type +/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final +/// instance variable with name id and type R. +/// +/// We say that the declared representation type of Inline is R, and the +/// instantiated representation type corresponding to Inline is +/// [T1/X1, .. Ts/Xs]R. +/// ... +/// Let V be an inline type of the form Inline, and let R be the +/// corresponding instantiated representation type. If R is non-nullable then V +/// is a proper subtype of Object, and V is non-nullable. Otherwise, V is a +/// proper subtype of Object?, and V is potentially nullable. +/// +/// @description Checks that if an instantiated representation type `R` is +/// not non-nullable then an inline type `V` is potentially nullable +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +inline class V1 { + final int it; + V1(this.it); +} + +inline class V2 { + final num id; + V2(this.id); +} + +test1(X x) { + Object o = x; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + x.id; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test2?>(X x) { + Object o = x; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + x.id; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + test1(V1(42)); + test2>(V2(42)); +} diff --git a/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t05.dart b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t05.dart new file mode 100644 index 0000000000..b10f89bb62 --- /dev/null +++ b/LanguageFeatures/Inline-classes/static_analysis_inline_class_A12_t05.dart @@ -0,0 +1,63 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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 Let DV be an inline class declaration named Inline with type +/// parameters X1 extends B1, .. Xs extends Bs. Assume that DV declares a final +/// instance variable with name id and type R. +/// +/// We say that the declared representation type of Inline is R, and the +/// instantiated representation type corresponding to Inline is +/// [T1/X1, .. Ts/Xs]R. +/// ... +/// Let V be an inline type of the form Inline, and let R be the +/// corresponding instantiated representation type. If R is non-nullable then V +/// is a proper subtype of Object, and V is non-nullable. Otherwise, V is a +/// proper subtype of Object?, and V is potentially nullable. +/// +/// @description Checks that it is a compile-time error to have an instance +/// variable whose type is an inline type, and then relying on implicit +/// initialization to null. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +inline class V1 { + final int it; + V1(this.it); +} + +inline class V2 { + final num id; + V2(this.id); +} + +test1() { + X x; + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test2?>() { + X x; + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + V1 v1; + print(v1); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + V2 v2; + print(v2); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +}