diff --git a/Language/Functions/element_type_A01_t01.dart b/Language/Functions/element_type_A01_t01.dart new file mode 100644 index 0000000000..f453a4f53a --- /dev/null +++ b/Language/Functions/element_type_A01_t01.dart @@ -0,0 +1,56 @@ +// 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 We define the union-free type of a type `T` as follows: +/// If `T` is of the form `S?` or the form `FutureOr` then the union-free +/// type of `T` is the union-free type of `S`. Otherwise, the union-free type +/// of `T` is T. +/// +/// We define the element type of a generator function `f` as follows: +/// Let `S` be the union-free type of the declared return type of `f`. If `f` is +/// a synchronous generator and `S` implements `Iterable` for some `U` then +/// the element type of `f` is `U`. +/// +/// @description Check that element type of a synchronous generator function `f` +/// is `U`, where `S` is a union-free type of the declared return type of `f` +/// and `S` implements `Iterable` +/// @author sgrekhov22@gmail.com + +import "dart:async"; + +Iterable? f1() sync* { + yield 1; + yield 3.14; + yield null; // Ok, element type is `num?` +} + +Iterable? f2() sync* { + yield 1; + yield null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +FutureOr?> f3() sync* { + yield 1; + yield null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + yield Future.value(null); +// ^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + yield Future.value(1); +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + f1(); + f2(); + f3(); +} diff --git a/Language/Functions/element_type_A02_t01.dart b/Language/Functions/element_type_A02_t01.dart new file mode 100644 index 0000000000..4edbfa35e3 --- /dev/null +++ b/Language/Functions/element_type_A02_t01.dart @@ -0,0 +1,57 @@ +// 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 We define the union-free type of a type `T` as follows: +/// If `T` is of the form `S?` or the form `FutureOr` then the union-free +/// type of `T` is the union-free type of `S`. Otherwise, the union-free type +/// of `T` is T. +/// +/// We define the element type of a generator function `f` as follows: +/// Let `S` be the union-free type of the declared return type of `f`. +/// ... +/// If `f` is an asynchronous generator and `S` implements `Stream` for some +/// `U` then the element type of `f` is `U`. +/// +/// @description Check that element type of an asynchronous generator function +/// `f` is `U`, where `S` is a union-free type of the declared return type of +/// `f` and `S` implements `Stream` +/// @author sgrekhov22@gmail.com + +import "dart:async"; + +Stream? f1() async* { + yield 1; + yield 3.14; + yield null; // Ok, element type is `num?` +} + +Stream? f2() async* { + yield 1; + yield null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +FutureOr?> f3() async* { + yield 1; + yield null; +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + yield Future.value(null); +// ^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + yield Future.value(1); +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + f1(); + f2(); + f3(); +} diff --git a/Language/Functions/element_type_A03_t01.dart b/Language/Functions/element_type_A03_t01.dart new file mode 100644 index 0000000000..49ba5052a3 --- /dev/null +++ b/Language/Functions/element_type_A03_t01.dart @@ -0,0 +1,54 @@ +// 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 We define the union-free type of a type `T` as follows: +/// If `T` is of the form `S?` or the form `FutureOr` then the union-free +/// type of `T` is the union-free type of `S`. Otherwise, the union-free type +/// of `T` is T. +/// +/// We define the element type of a generator function `f` as follows: +/// Let `S` be the union-free type of the declared return type of `f`. +/// ... +/// Otherwise, if `f` is a generator (synchronous or asynchronous) and `S` is a +/// supertype of `Object` then the element type of `f` is dynamic +/// +/// @description Check that element type of a synchronous generator function `f` +/// is `dynamic`, if `S` is a union-free type of the declared return type of `f` +/// and `S` is a supertype of `Object` +/// @author sgrekhov22@gmail.com + +import "dart:async"; + +Object? f1() sync* { + yield 1; + yield 3.14; + yield null; + yield "42"; +} + +Object f2() sync* { + yield 1; + yield null; +} + +FutureOr f3() sync* { + yield 1; + yield null; + yield Future.value(null); + yield Future.value(1); +} + +FutureOr? f4() sync* { + yield 1; + yield null; + yield Future.value(null); + yield Future.value(1); +} + +main() { + f1(); + f2(); + f3(); + f4(); +} diff --git a/Language/Functions/element_type_A03_t02.dart b/Language/Functions/element_type_A03_t02.dart new file mode 100644 index 0000000000..745894a009 --- /dev/null +++ b/Language/Functions/element_type_A03_t02.dart @@ -0,0 +1,54 @@ +// 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 We define the union-free type of a type `T` as follows: +/// If `T` is of the form `S?` or the form `FutureOr` then the union-free +/// type of `T` is the union-free type of `S`. Otherwise, the union-free type +/// of `T` is T. +/// +/// We define the element type of a generator function `f` as follows: +/// Let `S` be the union-free type of the declared return type of `f`. +/// ... +/// Otherwise, if `f` is a generator (synchronous or asynchronous) and `S` is a +/// supertype of Object then the element type of `f` is dynamic +/// +/// @description Check that element type of an asynchronous generator function +/// `f` is `dynamic`, if `S` is a union-free type of the declared return type of +/// `f` and `S` is a supertype of `Object` +/// @author sgrekhov22@gmail.com + +import "dart:async"; + +Object? f1() sync* { + yield 1; + yield 3.14; + yield null; + yield "42"; +} + +Object f2() sync* { + yield 1; + yield null; +} + +FutureOr f3() sync* { + yield 1; + yield null; + yield Future.value(null); + yield Future.value(1); +} + +FutureOr? f4() sync* { + yield 1; + yield null; + yield Future.value(null); + yield Future.value(1); +} + +main() { + f1(); + f2(); + f3(); + f4(); +}