-
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 more tests for the type `void`
- Loading branch information
Showing
14 changed files
with
488 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,29 @@ | ||
// Copyright (c) 2024, 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 Finally, we need to address situations involving implicit usage | ||
/// of an object whose static type can be `void`. It is a compile-time error for | ||
/// a for-in statement to have an iterator expression of type `T` such that | ||
/// `Iterator<void>` is the most specific instantiation of `Iterator` that is a | ||
/// superinterface of `T`, unless the iteration variable has type `void`. | ||
/// | ||
/// @description Checks that it is a compile-time error if in a for-in loop type | ||
/// of the iterator expression is `Iterator<void>` and the type of the iteration | ||
/// variable is not `void`. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 57078 | ||
void main() { | ||
List<void> list = <void>[1, 2, 3]; | ||
for (Object? i in list) { | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
for (dynamic i in list) { | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} |
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,28 @@ | ||
// Copyright (c) 2024, 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 Finally, we need to address situations involving implicit usage | ||
/// of an object whose static type can be `void`. It is a compile-time error for | ||
/// a for-in statement to have an iterator expression of type `T` such that | ||
/// `Iterator<void>` is the most specific instantiation of `Iterator` that is a | ||
/// superinterface of `T`, unless the iteration variable has type `void`. | ||
/// | ||
/// @description Checks that it is not an error if in a for-in loop type of the | ||
/// iterator expression is `Iterator<void>` and the type of the iteration | ||
/// variable is `void`. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
List<void> list = <void>[1, 2, 3]; | ||
int j = 0; | ||
for (void i in list) { | ||
Expect.equals(++j, i as int); | ||
} | ||
j = 0; | ||
for (var i in list) { | ||
Expect.equals(++j, i as int); | ||
} | ||
} |
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,29 @@ | ||
// Copyright (c) 2024, 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 Finally, we need to address situations involving implicit usage | ||
/// of an object whose static type can be `void`. ... It is a compile-time error | ||
/// for an asynchronous for-in statement to have a stream expression of type `T` | ||
/// such that `Stream<void>` is the most specific instantiation of `Stream` that | ||
/// is a superinterface of `T`, unless the iteration variable has type `void`. | ||
/// | ||
/// @description Checks that it is a compile-time error if in an asynchronous | ||
/// for-in loop type of the iterator expression is `Stream<void>` and the type | ||
/// of the iteration variable is not `void`. | ||
/// @author sgrekhov22@gmail.com | ||
/// @issue 57078 | ||
void main() async { | ||
Stream<void> stream = Stream<void>.fromIterable([1, 2, 3]); | ||
await for (Object? i in stream) { | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
await for (dynamic i in stream) { | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} |
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,28 @@ | ||
// Copyright (c) 2024, 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 Finally, we need to address situations involving implicit usage | ||
/// of an object whose static type can be `void`. ... It is a compile-time error | ||
/// for an asynchronous for-in statement to have a stream expression of type `T` | ||
/// such that `Stream<void>` is the most specific instantiation of `Stream` that | ||
/// is a superinterface of `T`, unless the iteration variable has type `void`. | ||
/// | ||
/// @description Checks that it is not an error if in an asynchronous for-in | ||
/// loop type of the iterator expression is `Stream<void>` and the type of the | ||
/// iteration variable is `void`. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() async { | ||
Stream<void> stream = Stream<void>.fromIterable([1, 2, 3]); | ||
int j = 0; | ||
await for (void i in stream) { | ||
Expect.equals(++j, i as int); | ||
} | ||
j = 0; | ||
await for (var i in stream) { | ||
Expect.equals(++j, i as int); | ||
} | ||
} |
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,41 @@ | ||
// Copyright (c) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - An actual parameter expression corresponding to a formal parameter whose | ||
/// statically known type annotation is `void` may have type `void`. | ||
/// | ||
/// @description Checks that an actual parameter expression corresponding to a | ||
/// formal parameter whose statically known type annotation is `void` may have | ||
/// type `void`. Test a class. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
Object? f<X>(X x) => x; | ||
|
||
class C<X> { | ||
final X x; | ||
C(this.x); | ||
Object? foo(X x) => x; | ||
static Object? bar<T>(T t) => t; | ||
} | ||
|
||
void main() { | ||
void v = 42; | ||
Expect.equals(42, f(v)); | ||
Expect.equals(42, f<void>(v)); | ||
|
||
Expect.equals(42, C.bar(v)); | ||
Expect.equals(42, C.bar<void>(v)); | ||
|
||
Expect.equals(42, C<void>(v).x as int); | ||
Expect.equals(42, C(v).foo(v)); | ||
Expect.equals(42, C<void>("").foo(v)); | ||
} |
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) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - An actual parameter expression corresponding to a formal parameter whose | ||
/// statically known type annotation is `void` may have type `void`. | ||
/// | ||
/// @description Checks that an actual parameter expression corresponding to a | ||
/// formal parameter whose statically known type annotation is `void` may have | ||
/// type `void`. Test a mixin. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
mixin M<X> { | ||
Object? foo(X x) => x; | ||
static Object? bar<T>(T t) => t; | ||
} | ||
|
||
class MA = Object with M<void>; | ||
|
||
void main() { | ||
void v = 42; | ||
|
||
Expect.equals(42, M.bar(v)); | ||
Expect.equals(42, M.bar<void>(v)); | ||
Expect.equals(42, MA().foo(v)); | ||
} |
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) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - An actual parameter expression corresponding to a formal parameter whose | ||
/// statically known type annotation is `void` may have type `void`. | ||
/// | ||
/// @description Checks that an actual parameter expression corresponding to a | ||
/// formal parameter whose statically known type annotation is `void` may have | ||
/// type `void`. Test an enum. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
const void answer = 42; | ||
|
||
enum E<X> { | ||
e0<void>(answer); | ||
|
||
final X x; | ||
const E(this.x); | ||
Object? foo(X x) => x; | ||
static Object? bar<T>(T t) => t; | ||
} | ||
|
||
void main() { | ||
void v = 0; | ||
Expect.equals(42, E.e0.x as int); | ||
Expect.equals(0, E.bar<void>(v)); | ||
Expect.equals(0, E.e0.foo(v)); | ||
} |
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,33 @@ | ||
// Copyright (c) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - An actual parameter expression corresponding to a formal parameter whose | ||
/// statically known type annotation is `void` may have type `void`. | ||
/// | ||
/// @description Checks that an actual parameter expression corresponding to a | ||
/// formal parameter whose statically known type annotation is `void` may have | ||
/// type `void`. Test an extension. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
class C<T> { | ||
} | ||
|
||
extension Ext<X> on C<X> { | ||
Object? foo(X x) => x; | ||
static Object? bar<T>(T t) => t; | ||
} | ||
|
||
void main() { | ||
void v = 42; | ||
Expect.equals(42, C<void>().foo(v)); | ||
Expect.equals(42, Ext.bar<void>(v)); | ||
} |
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,31 @@ | ||
// Copyright (c) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - An actual parameter expression corresponding to a formal parameter whose | ||
/// statically known type annotation is `void` may have type `void`. | ||
/// | ||
/// @description Checks that an actual parameter expression corresponding to a | ||
/// formal parameter whose statically known type annotation is `void` may have | ||
/// type `void`. Test an extension type. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
extension type ET<X>(X x) { | ||
Object? foo(X x) => x; | ||
static Object? bar<T>(T t) => t; | ||
} | ||
|
||
void main() { | ||
void v = 42; | ||
Expect.equals(42, ET<void>(v).x as int); | ||
Expect.equals(42, ET<void>(v).foo(v)); | ||
Expect.equals(42, ET.bar<void>(v)); | ||
} |
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,35 @@ | ||
// Copyright (c) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - In an expression of the form `e1 = e2` where `e1` is an | ||
/// `⟨assignableExpression⟩` denoting a variable or formal parameter of type | ||
/// `void`, `e2` may have type `void`. | ||
/// | ||
/// @description Checks that in an expression of the form `e1 = e2` where `e1` | ||
/// is an `⟨assignableExpression⟩` denoting a variable of type `void`, `e2` may | ||
/// have type `void`. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
class C<T> { | ||
late final T t; | ||
C(); | ||
} | ||
|
||
void main() { | ||
void e1 = print(42); | ||
e1 = print("x"); | ||
|
||
void e2 = 42; | ||
C<void> c = C<void>(); | ||
c.t = e2; | ||
Expect.equals(42, c.t as int); | ||
} |
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,30 @@ | ||
// Copyright (c) 2024, 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 In support of the notion that the value of an expression with | ||
/// static type `void` should be discarded, such objects can only be used in | ||
/// specific situations: The occurrence of an expression of type `void` is a | ||
/// compile-time error unless it is permitted according to one of the following | ||
/// rules. | ||
/// ... | ||
/// - In an expression of the form `e1 = e2` where `e1` is an | ||
/// `⟨assignableExpression⟩` denoting a variable or formal parameter of type | ||
/// `void`, `e2` may have type `void`. | ||
/// | ||
/// @description Checks that in an expression of the form `e1 = e2` where `e1` | ||
/// is an `⟨assignableExpression⟩` denoting a formal parameter of type `void`, | ||
/// `e2` may have type `void`. | ||
/// @author sgrekhov22@gmail.com | ||
import '../../../Utils/expect.dart'; | ||
|
||
void foo(void e1) { | ||
void e2 = 42; | ||
e1 = e2; | ||
Expect.equals(42, e1 as int); | ||
} | ||
|
||
void main() { | ||
foo(0); | ||
} |
Oops, something went wrong.