mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:54:55 +00:00
Move void to top of type hierarchy
Fixes #33341 Change-Id: Ib2b7b5542b702a04b38dee5261fc80664a7fcc18 Reviewed-on: https://dart-review.googlesource.com/59822 Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
This commit is contained in:
parent
305c166154
commit
ebc30fd0da
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -4,6 +4,22 @@
|
|||
|
||||
### Language
|
||||
|
||||
Inference chooses `void` when combining `Object` or `dynamic` and `void` ([issue
|
||||
3341]). When combining with other top types, inference now prefers `void`. So
|
||||
for example, given:
|
||||
|
||||
```dart
|
||||
void foo() {};
|
||||
dynamic bar() {};
|
||||
var a = [foo(), bar()];
|
||||
```
|
||||
|
||||
the variable `a` would previously have been inferred as `dynamic`, and will now
|
||||
be inferred as `void`.
|
||||
|
||||
[issue 3341]: https://github.com/dart-lang/sdk/issues/33341
|
||||
|
||||
|
||||
#### Strong Mode
|
||||
|
||||
### Dart VM
|
||||
|
|
|
@ -35,9 +35,9 @@ int _getTopiness(DartType t) {
|
|||
assert(_isTop(t), 'only Top types have a topiness');
|
||||
|
||||
// Highest top
|
||||
if (t.isDynamic) return 3;
|
||||
if (t.isObject) return 2;
|
||||
if (t.isVoid) return 1;
|
||||
if (t.isVoid) return 3;
|
||||
if (t.isDynamic) return 2;
|
||||
if (t.isObject) return 1;
|
||||
if (t.isDartAsyncFutureOr)
|
||||
return -3 + _getTopiness((t as InterfaceType).typeArguments[0]);
|
||||
// Lowest top
|
||||
|
|
|
@ -637,7 +637,7 @@ abstract class LeastUpperBoundTestBase extends BoundTestBase {
|
|||
|
||||
void test_dynamic_void() {
|
||||
// Note: _checkLeastUpperBound tests `LUB(x, y)` as well as `LUB(y, x)`
|
||||
_checkLeastUpperBound(dynamicType, voidType, dynamicType);
|
||||
_checkLeastUpperBound(dynamicType, voidType, voidType);
|
||||
}
|
||||
|
||||
void test_functionsDifferentRequiredArity() {
|
||||
|
@ -1553,15 +1553,15 @@ class StrongGreatestLowerBoundTest extends BoundTestBase {
|
|||
|
||||
final orderedTops = [
|
||||
// Lower index, so lower Top
|
||||
voidType,
|
||||
dynamicType,
|
||||
objectType,
|
||||
voidType,
|
||||
futureOrVoidType,
|
||||
futureOrDynamicType,
|
||||
futureOrObjectType,
|
||||
futureOrVoidType,
|
||||
futureOrFutureOrVoidType,
|
||||
futureOrFutureOrDynamicType,
|
||||
futureOrFutureOrObjectType,
|
||||
futureOrFutureOrVoidType,
|
||||
// Higher index, higher Top
|
||||
];
|
||||
|
||||
|
@ -1593,7 +1593,7 @@ class StrongGreatestLowerBoundTest extends BoundTestBase {
|
|||
// Sanity check specific cases of top for GLB/LUB.
|
||||
_checkLeastUpperBound(objectType, dynamicType, dynamicType);
|
||||
_checkGreatestLowerBound(objectType, dynamicType, objectType);
|
||||
_checkLeastUpperBound(objectType, voidType, objectType);
|
||||
_checkLeastUpperBound(objectType, voidType, voidType);
|
||||
_checkLeastUpperBound(futureOrDynamicType, dynamicType, dynamicType);
|
||||
_checkGreatestLowerBound(
|
||||
futureOrDynamicType, objectType, futureOrDynamicType);
|
||||
|
@ -1644,7 +1644,7 @@ class StrongGreatestLowerBoundTest extends BoundTestBase {
|
|||
|
||||
void test_dynamic_void() {
|
||||
// Note: _checkGreatestLowerBound tests `GLB(x, y)` as well as `GLB(y, x)`
|
||||
_checkGreatestLowerBound(dynamicType, voidType, voidType);
|
||||
_checkGreatestLowerBound(dynamicType, voidType, dynamicType);
|
||||
}
|
||||
|
||||
void test_functionsDifferentNamedTakeUnion() {
|
||||
|
|
Loading…
Reference in a new issue