-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add generator functions element type tests
- Loading branch information
Showing
21 changed files
with
819 additions
and
8 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,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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 if the declared return type of a synchronous | ||
/// generator function `f` is `T`, and `S` is the union-free type derived from | ||
/// `T`, and `S` is of the form `Iterable<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `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,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 We define the union-free type derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 if the declared return type of a synchronous | ||
/// generator function `f` is `T`, and `S` is the union-free type derived from | ||
/// `T`, and `S` is of the form `Iterable<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
import "dart:async"; | ||
|
||
Iterable<int>? f1() sync* { | ||
yield 1; | ||
yield 3.14; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield "2"; | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<Iterable<int>?> f2() sync* { | ||
yield 1; | ||
yield 3.14; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield "2"; | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
} |
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,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 We define the union-free type derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 a run-time type of a return value of a synchronous | ||
/// generator function | ||
/// @author [email protected] | ||
import "dart:async"; | ||
import "../../Utils/expect.dart"; | ||
|
||
FutureOr<Iterable<int>?> foo() sync* { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
main() { | ||
FutureOr<Iterable<int>?> o = foo() as dynamic; | ||
o as FutureOr<Iterable<int>>; | ||
Expect.isRuntimeTypeImplementsIterable<int>(o); | ||
} |
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,34 @@ | ||
// 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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 Let `f` be a synchronous generator function whose declared | ||
/// return type derives the union-free type `S`, and assume that `S` implements | ||
/// `Iterable<U>`. Then check that the element type of `f` is `U`. | ||
/// @author [email protected] | ||
import "dart:async"; | ||
import "../../Utils/expect.dart"; | ||
import "../../Utils/static_type_helper.dart"; | ||
|
||
FutureOr<Iterable<int>?> foo() sync* { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
main() { | ||
var o = foo(); | ||
o.expectStaticType<Exactly<FutureOr<Iterable<int>?>>>(); | ||
Expect.isRuntimeTypeImplementsIterable<int>(o); | ||
} |
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,37 @@ | ||
// 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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 Let `f` be a synchronous generator function whose declared | ||
/// return type derives the union-free type `S`, and assume that `S` implements | ||
/// `Iterable<U>`. Then check that the element type of `f` is `U`. | ||
/// @author [email protected] | ||
import "../../Utils/expect.dart"; | ||
|
||
Iterable<int?>? f1() sync* { | ||
yield 1; | ||
yield 2; | ||
yield null; | ||
} | ||
|
||
Iterable<int>? f2() sync* { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
main() { | ||
Expect.isRuntimeTypeImplementsIterable<int?>(f1()); | ||
Expect.isRuntimeTypeImplementsIterable<int>(f2()); | ||
} |
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,38 @@ | ||
// 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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 Let `f` be a synchronous generator function whose declared | ||
/// return type derives the union-free type `S`, and assume that `S` implements | ||
/// `Iterable<U>`. Then check that the element type of `f` is `U`. | ||
/// @author [email protected] | ||
import "dart:async"; | ||
import "../../Utils/expect.dart"; | ||
|
||
FutureOr<Iterable<int?>?> f1() sync* { | ||
yield 1; | ||
yield 2; | ||
yield null; | ||
} | ||
|
||
FutureOr<Iterable<int>?>? f2() sync* { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
main() { | ||
Expect.isRuntimeTypeImplementsIterable<int?>(f1()); | ||
Expect.isRuntimeTypeImplementsIterable<int>(f2()); | ||
} |
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,58 @@ | ||
// 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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 if the declared return type of an asynchronous | ||
/// generator function `f` is `T`, and `S` is the union-free type derived from | ||
/// `T`, and `S` is of the form `Stream<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `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,51 @@ | ||
// 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 derived from a type T as follows: | ||
/// If T is of the form S? or the form FutureOr<S> then the union-free type | ||
/// derived from T is the union-free type derived from S. Otherwise, the | ||
/// union-free type derived from T is T | ||
/// | ||
/// We define the element type of a generator function `f` as follows: | ||
/// Let S be the union-free type derived from 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 if the declared return type of an asynchronous | ||
/// generator function `f` is `T`, and `S` is the union-free type derived from | ||
/// `T`, and `S` is of the form `Stream<U>`, it is a compile-time error to | ||
/// yield an expression whose static type isn't assignable to `U`. | ||
/// @author [email protected] | ||
import "dart:async"; | ||
|
||
Stream<int>? f1() async* { | ||
yield 1; | ||
yield 3.14; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield "2"; | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<Stream<int>?> f2() async* { | ||
yield 1; | ||
yield 3.14; | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
yield "2"; | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
f1(); | ||
f2(); | ||
} |
Oops, something went wrong.