forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2139. Add generator functions element type tests
- Loading branch information
Showing
4 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S>` 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<U>` 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<U>` | ||
/// @author [email protected] | ||
import "dart:async"; | ||
|
||
Iterable<num?>? f1() sync* { | ||
yield 1; | ||
yield 3.14; | ||
yield null; // Ok, element type is `num?` | ||
} | ||
|
||
Iterable<num>? f2() sync* { | ||
yield 1; | ||
yield null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<Iterable<num>?> f3() sync* { | ||
yield 1; | ||
yield null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield Future<Null>.value(null); | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield Future<num>.value(1); | ||
// ^^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
f3(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S>` 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<U>` 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<U>` | ||
/// @author [email protected] | ||
import "dart:async"; | ||
|
||
Stream<num?>? f1() async* { | ||
yield 1; | ||
yield 3.14; | ||
yield null; // Ok, element type is `num?` | ||
} | ||
|
||
Stream<num>? f2() async* { | ||
yield 1; | ||
yield null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<Stream<num>?> f3() async* { | ||
yield 1; | ||
yield null; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield Future<Null>.value(null); | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield Future<num>.value(1); | ||
// ^^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
f3(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S>` 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 [email protected] | ||
import "dart:async"; | ||
|
||
Object? f1() sync* { | ||
yield 1; | ||
yield 3.14; | ||
yield null; | ||
yield "42"; | ||
} | ||
|
||
Object f2() sync* { | ||
yield 1; | ||
yield null; | ||
} | ||
|
||
FutureOr<Object> f3() sync* { | ||
yield 1; | ||
yield null; | ||
yield Future<Null>.value(null); | ||
yield Future<num>.value(1); | ||
} | ||
|
||
FutureOr<Object?>? f4() sync* { | ||
yield 1; | ||
yield null; | ||
yield Future<Null>.value(null); | ||
yield Future<num>.value(1); | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
f3(); | ||
f4(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S>` 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 [email protected] | ||
import "dart:async"; | ||
|
||
Object? f1() sync* { | ||
yield 1; | ||
yield 3.14; | ||
yield null; | ||
yield "42"; | ||
} | ||
|
||
Object f2() sync* { | ||
yield 1; | ||
yield null; | ||
} | ||
|
||
FutureOr<Object> f3() sync* { | ||
yield 1; | ||
yield null; | ||
yield Future<Null>.value(null); | ||
yield Future<num>.value(1); | ||
} | ||
|
||
FutureOr<Object?>? f4() sync* { | ||
yield 1; | ||
yield null; | ||
yield Future<Null>.value(null); | ||
yield Future<num>.value(1); | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
f3(); | ||
f4(); | ||
} |