diff --git a/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t14.dart b/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t14.dart new file mode 100644 index 0000000000..078710127b --- /dev/null +++ b/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t14.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 A compile-time error occurs if an extension type has a +/// non-extension superinterface whose transitive alias expansion is a type +/// variable, a deferred type, any top type (including dynamic and void), the +/// type Null, any function type, the type Function, any record type, the type +/// Record, or any type of the form T? or FutureOr for any type T. +/// +/// @description Checks that it is not an error if an representation type of an +/// extension type is a top type, the type `Null`, a function type, the type +/// `Function`, a record type, the type `Record`, a type of the form `T?` or +/// `FutureOr` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +import "dart:async" show FutureOr; +import "../../Utils/expect.dart"; +import "../../Utils/static_type_helper.dart"; + +typedef void Foo(); + +extension type ET1(dynamic id) {} + +extension type ET2(Object id) {} + +extension type ET3(Object? id) {} + +extension type ET4(Null id) {} + +extension type ET5(Never id) {} + +extension type ET6(Foo id) {} + +extension type ET7(Function id) {} + +extension type ET8((int,) id) {} + +extension type ET9(Record id) {} + +extension type ET10(int? id) {} + +extension type ET11(FutureOr id) {} + +Never never() => throw Exception(); + +Foo foo = () {}; + +main() { + Expect.throws(() {ET1("42").id.whatever;}); + ET2(42).id.expectStaticType>(); + ET3(42).id.expectStaticType>(); + ET4(null).id.expectStaticType>(); + Expect.throws(() {ET5(never());}); + ET6(foo).id.expectStaticType>(); + ET7(() {}).id.expectStaticType>(); + ET8((42,)).id.expectStaticType>(); + ET9((42,)).id.expectStaticType>(); + ET10(null).id.expectStaticType>(); + ET11(42).id.expectStaticType>>(); +} diff --git a/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t15.dart b/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t15.dart new file mode 100644 index 0000000000..3434d309e9 --- /dev/null +++ b/LanguageFeatures/Extension-types/static_analysis_extension_types_A10_t15.dart @@ -0,0 +1,24 @@ +// 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 A compile-time error occurs if an extension type has a +/// non-extension superinterface whose transitive alias expansion is a type +/// variable, a deferred type, any top type (including dynamic and void), the +/// type Null, any function type, the type Function, any record type, the type +/// Record, or any type of the form T? or FutureOr for any type T. +/// +/// @description Checks that it is not an error if an representation type of an +/// extension type is a type `void` +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +extension type ET1(void id) {} + +main() { + print(ET1("42").id); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +}