Skip to content

Commit 0a9d14a

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
Dmitry Stefantsov
authored andcommitted
[cfe] Adjust computation of nullability in flatten
Closes #47057. Bug: #47057 Change-Id: Iad719192d0ecbe97461bfed868899072a6dd52e2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212467 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Dmitry Stefantsov <[email protected]>
1 parent ab508bb commit 0a9d14a

7 files changed

+91
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
Future<int> foo<X extends Object?>(X x) async {
8+
if (x is Future<int>) {
9+
return x;
10+
} else {
11+
throw 42;
12+
}
13+
}
14+
15+
main() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'dart:async';
2+
3+
Future<int> foo<X extends Object?>(X x) async {}
4+
main() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'dart:async';
2+
3+
Future<int> foo<X extends Object?>(X x) async {}
4+
main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method foo<X extends core::Object?>(self::foo::X% x) → asy::Future<core::int> async {
9+
if(x is{ForNonNullableByDefault} asy::Future<core::int>) {
10+
return x{self::foo::X% & asy::Future<core::int> /* '%' & '!' = '!' */};
11+
}
12+
else {
13+
throw 42;
14+
}
15+
}
16+
static method main() → dynamic {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method foo<X extends core::Object?>(self::foo::X% x) → asy::Future<core::int> async
9+
;
10+
static method main() → dynamic
11+
;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method foo<X extends core::Object?>(self::foo::X% x) → asy::Future<core::int> /* originally async */ {
9+
final asy::_Future<core::int> :async_future = new asy::_Future::•<core::int>();
10+
core::bool* :is_sync = false;
11+
FutureOr<core::int>? :return_value;
12+
(dynamic) → dynamic :async_op_then;
13+
(core::Object, core::StackTrace) → dynamic :async_op_error;
14+
core::int :await_jump_var = 0;
15+
dynamic :await_ctx_var;
16+
function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding
17+
try {
18+
#L1:
19+
{
20+
if(x is{ForNonNullableByDefault} asy::Future<core::int>) {
21+
:return_value = x{self::foo::X% & asy::Future<core::int> /* '%' & '!' = '!' */};
22+
break #L1;
23+
}
24+
else {
25+
throw 42;
26+
}
27+
}
28+
asy::_completeOnAsyncReturn(:async_future, :return_value, :is_sync);
29+
return;
30+
}
31+
on dynamic catch(dynamic exception, core::StackTrace stack_trace) {
32+
asy::_completeOnAsyncError(:async_future, exception, stack_trace, :is_sync);
33+
}
34+
:async_op_then = asy::_asyncThenWrapperHelper(:async_op);
35+
:async_op_error = asy::_asyncErrorWrapperHelper(:async_op);
36+
:async_op(){() → dynamic};
37+
:is_sync = true;
38+
return :async_future;
39+
}
40+
static method main() → dynamic {}

pkg/kernel/lib/type_environment.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ abstract class TypeEnvironment extends Types {
102102
List<DartType>? futureArguments =
103103
getTypeArgumentsAsInstanceOf(resolved, coreTypes.futureClass);
104104
if (futureArguments != null) {
105-
return _withDeclaredNullability(
106-
futureArguments.single, t.declaredNullability);
105+
return _withDeclaredNullability(futureArguments.single, t.nullability);
107106
}
108107
}
109108

0 commit comments

Comments
 (0)