From dd1c3a3233be91a53eb4b5c6e05f878f6610816c Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Wed, 3 Mar 2021 11:58:08 +0000 Subject: [PATCH] [vm] Make async transform resilient in context of invalid type and never type of iterables The CFE can invoke transformations despite having compile-time errors. The async transform was crashing the compiler if it hits for-in iterables that have an invalid type or never type. In case of an invalid type, the program has a compile-time error and won't be able to run propertly. So we'll replace the entire for-in with an invalid expression statement if the iterable is an invalid expression. In case of a never type, the program should compile fine, which this CL also fixes. This makes the newly added tests no longer result in DartkCrash but rather in a compile-time error (invalid expression) or runtime-error (never type). Closes https://github.com/dart-lang/sdk/issues/45014 Change-Id: Ic50f68400b67b57dd4a2c0a125b08f0f3e0d8dd6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/188463 Commit-Queue: Johnni Winther Reviewed-by: Johnni Winther --- .../async_method_with_invalid_type.dart | 6 +- ...h_invalid_type.dart.textual_outline.expect | 1 + ..._type.dart.textual_outline_modelled.expect | 1 + ..._method_with_invalid_type.dart.weak.expect | 3 +- ...with_invalid_type.dart.weak.outline.expect | 2 + ..._invalid_type.dart.weak.transformed.expect | 46 +++ .../testcases/general/invalid_cast.dart | 2 + .../general/invalid_cast.dart.weak.expect | 36 +- .../invalid_cast.dart.weak.transformed.expect | 36 +- .../general/invalid_for_in_iterable.dart | 22 ++ ...or_in_iterable.dart.textual_outline.expect | 8 + ...rable.dart.textual_outline_modelled.expect | 8 + .../invalid_for_in_iterable.dart.weak.expect | 56 +++ ...d_for_in_iterable.dart.weak.outline.expect | 18 + ...r_in_iterable.dart.weak.transformed.expect | 86 +++++ .../issue39817.dart.weak.transformed.expect | 8 +- .../issue43495.dart.strong.transformed.expect | 348 ++++++++++++------ .../issue43495.dart.weak.transformed.expect | 348 ++++++++++++------ .../testcases/text_serialization.status | 1 - pkg/front_end/testcases/weak.status | 1 - pkg/kernel/lib/ast.dart | 19 +- .../lib/transformations/continuation.dart | 40 +- runtime/tests/vm/dart/regress_45014_test.dart | 20 + .../tests/vm/dart_2/regress_45014_test.dart | 20 + 24 files changed, 850 insertions(+), 286 deletions(-) create mode 100644 pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.transformed.expect create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.expect create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.outline.expect create mode 100644 pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.transformed.expect create mode 100644 runtime/tests/vm/dart/regress_45014_test.dart create mode 100644 runtime/tests/vm/dart_2/regress_45014_test.dart diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart index f5b5a243cff..1d6d5992633 100644 --- a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart @@ -1,8 +1,12 @@ // Copyright (c) 2020, 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.md file. + // @dart=2.9 + foo() async { Bar x; for (dynamic y in x.z) {} -} \ No newline at end of file +} + +main() {} \ No newline at end of file diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline.expect b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline.expect index 8c23a0856d4..675b31efc8f 100644 --- a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline.expect +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline.expect @@ -1,2 +1,3 @@ // @dart = 2.9 foo() async {} +main() {} diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline_modelled.expect index 8c23a0856d4..675b31efc8f 100644 --- a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline_modelled.expect +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.textual_outline_modelled.expect @@ -1,2 +1,3 @@ // @dart = 2.9 foo() async {} +main() {} diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.expect b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.expect index 1309bf1d778..92b2ed2769a 100644 --- a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.expect +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.expect @@ -2,7 +2,7 @@ library; // // Problems in library: // -// pkg/front_end/testcases/general/async_method_with_invalid_type.dart:6:3: Error: 'Bar' isn't a type. +// pkg/front_end/testcases/general/async_method_with_invalid_type.dart:8:3: Error: 'Bar' isn't a type. // Bar x; // ^^^ // @@ -13,3 +13,4 @@ static method foo() → dynamic async { for (dynamic y in x.z) { } } +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.outline.expect b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.outline.expect index 4a9b82e9d4f..b69505357a9 100644 --- a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.outline.expect +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.outline.expect @@ -3,3 +3,5 @@ import self as self; static method foo() → dynamic async ; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.transformed.expect b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.transformed.expect new file mode 100644 index 00000000000..c6b4aa6aa37 --- /dev/null +++ b/pkg/front_end/testcases/general/async_method_with_invalid_type.dart.weak.transformed.expect @@ -0,0 +1,46 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/general/async_method_with_invalid_type.dart:8:3: Error: 'Bar' isn't a type. +// Bar x; +// ^^^ +// +import self as self; +import "dart:async" as asy; +import "dart:core" as core; + +static method foo() → dynamic /* originally async */ { + final asy::_Future* :async_future = new asy::_Future::•(); + core::bool* :is_sync = false; + FutureOr* :return_value; + (dynamic) →* dynamic :async_op_then; + (core::Object*, core::StackTrace*) →* dynamic :async_op_error; + core::int* :await_jump_var = 0; + dynamic :await_ctx_var; + function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding + try { + #L1: + { + invalid-type x; + { + core::Iterator* :sync-for-iterator = x.z.{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic y = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + } + asy::_completeOnAsyncReturn(:async_future, :return_value, :is_sync); + return; + } + on dynamic catch(dynamic exception, core::StackTrace* stack_trace) { + asy::_completeOnAsyncError(:async_future, exception, stack_trace, :is_sync); + } + :async_op_then = asy::_asyncThenWrapperHelper(:async_op); + :async_op_error = asy::_asyncErrorWrapperHelper(:async_op); + :async_op.call(); + :is_sync = true; + return :async_future; +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/invalid_cast.dart b/pkg/front_end/testcases/general/invalid_cast.dart index 1aff128d5aa..81d1797c371 100644 --- a/pkg/front_end/testcases/general/invalid_cast.dart +++ b/pkg/front_end/testcases/general/invalid_cast.dart @@ -1,7 +1,9 @@ // Copyright (c) 2017, 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. + // @dart=2.9 + class C { C(); factory C.fact() => null; diff --git a/pkg/front_end/testcases/general/invalid_cast.dart.weak.expect b/pkg/front_end/testcases/general/invalid_cast.dart.weak.expect index f5d1183366d..95af46803b9 100644 --- a/pkg/front_end/testcases/general/invalid_cast.dart.weak.expect +++ b/pkg/front_end/testcases/general/invalid_cast.dart.weak.expect @@ -2,60 +2,60 @@ library; // // Problems in library: // -// pkg/front_end/testcases/general/invalid_cast.dart:20:25: Error: The list literal type 'List' isn't of expected type 'List'. +// pkg/front_end/testcases/general/invalid_cast.dart:22:25: Error: The list literal type 'List' isn't of expected type 'List'. // - 'List' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the list literal or the context in which it is used. // List a = []; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:21:40: Error: The map literal type 'Map' isn't of expected type 'Map'. +// pkg/front_end/testcases/general/invalid_cast.dart:23:40: Error: The map literal type 'Map' isn't of expected type 'Map'. // - 'Map' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the map literal or the context in which it is used. // Map b = {}; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:22:37: Error: The map literal type 'Map' isn't of expected type 'Map'. +// pkg/front_end/testcases/general/invalid_cast.dart:24:37: Error: The map literal type 'Map' isn't of expected type 'Map'. // - 'Map' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the map literal or the context in which it is used. // Map c = {}; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:23:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:25:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function expression or the context in which it is used. // int Function(Object) d = (int i) => i; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:26:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. +// pkg/front_end/testcases/general/invalid_cast.dart:28:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. // - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // Change the type of the object being constructed or the context in which it is used. // D g = new C.nonFact(); // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:27:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. +// pkg/front_end/testcases/general/invalid_cast.dart:29:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. // - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // Change the type of the object being constructed or the context in which it is used. // D h = new C.nonFact2(); // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:28:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:30:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the method or the context in which it is used. // void Function(Object) i = C.staticFunction; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:29:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:31:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function or the context in which it is used. // void Function(Object) j = topLevelFunction; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:30:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:32:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function or the context in which it is used. // void Function(Object) k = localFunction; @@ -99,54 +99,54 @@ class D extends self::C { static method topLevelFunction(core::int* i) → void {} static method bad() → dynamic { function localFunction(core::int* i) → void {} - core::List* a = let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:20:25: Error: The list literal type 'List' isn't of expected type 'List'. + core::List* a = let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:22:25: Error: The list literal type 'List' isn't of expected type 'List'. - 'List' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the list literal or the context in which it is used. List a = []; ^" in []; - core::Map* b = let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:21:40: Error: The map literal type 'Map' isn't of expected type 'Map'. + core::Map* b = let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:23:40: Error: The map literal type 'Map' isn't of expected type 'Map'. - 'Map' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the map literal or the context in which it is used. Map b = {}; ^" in {}; - core::Map* c = let final Never* #t3 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:22:37: Error: The map literal type 'Map' isn't of expected type 'Map'. + core::Map* c = let final Never* #t3 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:24:37: Error: The map literal type 'Map' isn't of expected type 'Map'. - 'Map' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the map literal or the context in which it is used. Map c = {}; ^" in {}; - (core::Object*) →* core::int* d = let final Never* #t4 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:23:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. + (core::Object*) →* core::int* d = let final Never* #t4 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:25:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function expression or the context in which it is used. int Function(Object) d = (int i) => i; ^" in (core::int* i) → core::int* => i; self::D* e = self::C::fact() as{TypeError} self::D*; self::D* f = new self::D::•() as{TypeError} self::D*; - self::D* g = let final Never* #t5 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:26:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. + self::D* g = let final Never* #t5 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:28:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. Change the type of the object being constructed or the context in which it is used. D g = new C.nonFact(); ^" in new self::C::nonFact(); - self::D* h = let final Never* #t6 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:27:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. + self::D* h = let final Never* #t6 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:29:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. Change the type of the object being constructed or the context in which it is used. D h = new C.nonFact2(); ^" in new self::C::nonFact2(); - (core::Object*) →* void i = let final Never* #t7 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:28:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void i = let final Never* #t7 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:30:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the method or the context in which it is used. void Function(Object) i = C.staticFunction; ^" in #C1; - (core::Object*) →* void j = let final Never* #t8 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:29:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void j = let final Never* #t8 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:31:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function or the context in which it is used. void Function(Object) j = topLevelFunction; ^" in #C2; - (core::Object*) →* void k = let final Never* #t9 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:30:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void k = let final Never* #t9 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:32:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function or the context in which it is used. void Function(Object) k = localFunction; diff --git a/pkg/front_end/testcases/general/invalid_cast.dart.weak.transformed.expect b/pkg/front_end/testcases/general/invalid_cast.dart.weak.transformed.expect index ba11f4f7cbe..7cd74f4f70b 100644 --- a/pkg/front_end/testcases/general/invalid_cast.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/general/invalid_cast.dart.weak.transformed.expect @@ -2,60 +2,60 @@ library; // // Problems in library: // -// pkg/front_end/testcases/general/invalid_cast.dart:20:25: Error: The list literal type 'List' isn't of expected type 'List'. +// pkg/front_end/testcases/general/invalid_cast.dart:22:25: Error: The list literal type 'List' isn't of expected type 'List'. // - 'List' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the list literal or the context in which it is used. // List a = []; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:21:40: Error: The map literal type 'Map' isn't of expected type 'Map'. +// pkg/front_end/testcases/general/invalid_cast.dart:23:40: Error: The map literal type 'Map' isn't of expected type 'Map'. // - 'Map' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the map literal or the context in which it is used. // Map b = {}; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:22:37: Error: The map literal type 'Map' isn't of expected type 'Map'. +// pkg/front_end/testcases/general/invalid_cast.dart:24:37: Error: The map literal type 'Map' isn't of expected type 'Map'. // - 'Map' is from 'dart:core'. // - 'Object' is from 'dart:core'. // Change the type of the map literal or the context in which it is used. // Map c = {}; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:23:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:25:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function expression or the context in which it is used. // int Function(Object) d = (int i) => i; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:26:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. +// pkg/front_end/testcases/general/invalid_cast.dart:28:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. // - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // Change the type of the object being constructed or the context in which it is used. // D g = new C.nonFact(); // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:27:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. +// pkg/front_end/testcases/general/invalid_cast.dart:29:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. // - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. // Change the type of the object being constructed or the context in which it is used. // D h = new C.nonFact2(); // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:28:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:30:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the method or the context in which it is used. // void Function(Object) i = C.staticFunction; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:29:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:31:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function or the context in which it is used. // void Function(Object) j = topLevelFunction; // ^ // -// pkg/front_end/testcases/general/invalid_cast.dart:30:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. +// pkg/front_end/testcases/general/invalid_cast.dart:32:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. // - 'Object' is from 'dart:core'. // Change the type of the function or the context in which it is used. // void Function(Object) k = localFunction; @@ -99,54 +99,54 @@ class D extends self::C { static method topLevelFunction(core::int* i) → void {} static method bad() → dynamic { function localFunction(core::int* i) → void {} - core::List* a = let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:20:25: Error: The list literal type 'List' isn't of expected type 'List'. + core::List* a = let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:22:25: Error: The list literal type 'List' isn't of expected type 'List'. - 'List' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the list literal or the context in which it is used. List a = []; ^" in core::_GrowableList::•(0); - core::Map* b = let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:21:40: Error: The map literal type 'Map' isn't of expected type 'Map'. + core::Map* b = let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:23:40: Error: The map literal type 'Map' isn't of expected type 'Map'. - 'Map' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the map literal or the context in which it is used. Map b = {}; ^" in {}; - core::Map* c = let final Never* #t3 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:22:37: Error: The map literal type 'Map' isn't of expected type 'Map'. + core::Map* c = let final Never* #t3 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:24:37: Error: The map literal type 'Map' isn't of expected type 'Map'. - 'Map' is from 'dart:core'. - 'Object' is from 'dart:core'. Change the type of the map literal or the context in which it is used. Map c = {}; ^" in {}; - (core::Object*) →* core::int* d = let final Never* #t4 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:23:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. + (core::Object*) →* core::int* d = let final Never* #t4 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:25:28: Error: The function expression type 'int Function(int)' isn't of expected type 'int Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function expression or the context in which it is used. int Function(Object) d = (int i) => i; ^" in (core::int* i) → core::int* => i; self::D* e = self::C::fact() as{TypeError} self::D*; self::D* f = new self::D::•(); - self::D* g = let final Never* #t5 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:26:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. + self::D* g = let final Never* #t5 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:28:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. Change the type of the object being constructed or the context in which it is used. D g = new C.nonFact(); ^" in new self::C::nonFact(); - self::D* h = let final Never* #t6 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:27:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. + self::D* h = let final Never* #t6 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:29:13: Error: The constructor returns type 'C' that isn't of expected type 'D'. - 'C' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. - 'D' is from 'pkg/front_end/testcases/general/invalid_cast.dart'. Change the type of the object being constructed or the context in which it is used. D h = new C.nonFact2(); ^" in new self::C::nonFact2(); - (core::Object*) →* void i = let final Never* #t7 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:28:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void i = let final Never* #t7 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:30:31: Error: The static method has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the method or the context in which it is used. void Function(Object) i = C.staticFunction; ^" in #C1; - (core::Object*) →* void j = let final Never* #t8 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:29:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void j = let final Never* #t8 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:31:29: Error: The top level function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function or the context in which it is used. void Function(Object) j = topLevelFunction; ^" in #C2; - (core::Object*) →* void k = let final Never* #t9 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:30:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. + (core::Object*) →* void k = let final Never* #t9 = invalid-expression "pkg/front_end/testcases/general/invalid_cast.dart:32:29: Error: The local function has type 'void Function(int)' that isn't of expected type 'void Function(Object)'. - 'Object' is from 'dart:core'. Change the type of the function or the context in which it is used. void Function(Object) k = localFunction; diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart new file mode 100644 index 00000000000..d982b0cca2f --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2017, 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. + +// @dart=2.9 + +Iterable takesNoArg() => null; +void returnVoid() {} +int returnInt() => 42; +dynamic returnDynamic() => []; +Object returnObject() => 0; + +test() { + for (var v in takesNoArg(0)) {} + for (var v in returnVoid()) {} + for (var v in returnInt()) {} + for (var v in returnDynamic()) {} + for (var v in returnObject()) {} + for (var v in throw '') {} +} + +main() {} diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline.expect b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline.expect new file mode 100644 index 00000000000..271c64ce26f --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline.expect @@ -0,0 +1,8 @@ +// @dart = 2.9 +Iterable takesNoArg() => null; +void returnVoid() {} +int returnInt() => 42; +dynamic returnDynamic() => []; +Object returnObject() => 0; +test() {} +main() {} diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..a23b7406505 --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.textual_outline_modelled.expect @@ -0,0 +1,8 @@ +// @dart = 2.9 +Iterable takesNoArg() => null; +Object returnObject() => 0; +dynamic returnDynamic() => []; +int returnInt() => 42; +main() {} +test() {} +void returnVoid() {} diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.expect b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.expect new file mode 100644 index 00000000000..b53be814af3 --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.expect @@ -0,0 +1,56 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:14:27: Error: Too many positional arguments: 0 allowed, but 1 found. +// Try removing the extra positional arguments. +// for (var v in takesNoArg(0)) {} +// ^ +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:7:10: Context: Found this candidate, but the arguments don't match. +// Iterable takesNoArg() => null; +// ^^^^^^^^^^ +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:15:17: Error: This expression has type 'void' and can't be used. +// for (var v in returnVoid()) {} +// ^ +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:16:17: Error: The type 'int' used in the 'for' loop must implement 'Iterable'. +// - 'Iterable' is from 'dart:core'. +// for (var v in returnInt()) {} +// ^ +// +import self as self; +import "dart:core" as core; + +static method takesNoArg() → core::Iterable* + return null; +static method returnVoid() → void {} +static method returnInt() → core::int* + return 42; +static method returnDynamic() → dynamic + return []; +static method returnObject() → core::Object* + return 0; +static method test() → dynamic { + for (dynamic v in invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:14:27: Error: Too many positional arguments: 0 allowed, but 1 found. +Try removing the extra positional arguments. + for (var v in takesNoArg(0)) {} + ^" as{TypeError,ForDynamic} core::Iterable*) { + } + for (dynamic v in let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:15:17: Error: This expression has type 'void' and can't be used. + for (var v in returnVoid()) {} + ^" in self::returnVoid()) { + } + for (dynamic v in let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:16:17: Error: The type 'int' used in the 'for' loop must implement 'Iterable'. + - 'Iterable' is from 'dart:core'. + for (var v in returnInt()) {} + ^" in self::returnInt() as{TypeError} core::Iterable*) { + } + for (dynamic v in self::returnDynamic() as{TypeError,ForDynamic} core::Iterable*) { + } + for (dynamic v in self::returnObject() as{TypeError} core::Iterable*) { + } + for (dynamic v in throw "") { + } +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.outline.expect b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.outline.expect new file mode 100644 index 00000000000..8b7863d01d3 --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.outline.expect @@ -0,0 +1,18 @@ +library; +import self as self; +import "dart:core" as core; + +static method takesNoArg() → core::Iterable* + ; +static method returnVoid() → void + ; +static method returnInt() → core::int* + ; +static method returnDynamic() → dynamic + ; +static method returnObject() → core::Object* + ; +static method test() → dynamic + ; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.transformed.expect b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.transformed.expect new file mode 100644 index 00000000000..927eae08d8e --- /dev/null +++ b/pkg/front_end/testcases/general/invalid_for_in_iterable.dart.weak.transformed.expect @@ -0,0 +1,86 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:14:27: Error: Too many positional arguments: 0 allowed, but 1 found. +// Try removing the extra positional arguments. +// for (var v in takesNoArg(0)) {} +// ^ +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:7:10: Context: Found this candidate, but the arguments don't match. +// Iterable takesNoArg() => null; +// ^^^^^^^^^^ +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:15:17: Error: This expression has type 'void' and can't be used. +// for (var v in returnVoid()) {} +// ^ +// +// pkg/front_end/testcases/general/invalid_for_in_iterable.dart:16:17: Error: The type 'int' used in the 'for' loop must implement 'Iterable'. +// - 'Iterable' is from 'dart:core'. +// for (var v in returnInt()) {} +// ^ +// +import self as self; +import "dart:core" as core; + +static method takesNoArg() → core::Iterable* + return null; +static method returnVoid() → void {} +static method returnInt() → core::int* + return 42; +static method returnDynamic() → dynamic + return core::_GrowableList::•(0); +static method returnObject() → core::Object* + return 0; +static method test() → dynamic { + { + core::Iterator* :sync-for-iterator = invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:14:27: Error: Too many positional arguments: 0 allowed, but 1 found. +Try removing the extra positional arguments. + for (var v in takesNoArg(0)) {} + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + { + core::Iterator* :sync-for-iterator = (let final Never* #t1 = invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:15:17: Error: This expression has type 'void' and can't be used. + for (var v in returnVoid()) {} + ^" in self::returnVoid()).{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + { + core::Iterator* :sync-for-iterator = (let final Never* #t2 = invalid-expression "pkg/front_end/testcases/general/invalid_for_in_iterable.dart:16:17: Error: The type 'int' used in the 'for' loop must implement 'Iterable'. + - 'Iterable' is from 'dart:core'. + for (var v in returnInt()) {} + ^" in self::returnInt() as{TypeError} core::Iterable*).{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + { + core::Iterator* :sync-for-iterator = (self::returnDynamic() as{TypeError,ForDynamic} core::Iterable*).{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + { + core::Iterator* :sync-for-iterator = (self::returnObject() as{TypeError} core::Iterable*).{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } + { + core::Iterator* :sync-for-iterator = (throw "").{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic v = :sync-for-iterator.{core::Iterator::current}; + {} + } + } +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/issue39817.dart.weak.transformed.expect b/pkg/front_end/testcases/general/issue39817.dart.weak.transformed.expect index cad4f5178ea..5dfdb2c24d5 100644 --- a/pkg/front_end/testcases/general/issue39817.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/general/issue39817.dart.weak.transformed.expect @@ -1,9 +1,15 @@ library; import self as self; +import "dart:core" as core; static method foo() → dynamic { Null _null; - for (dynamic i in _null) { + { + core::Iterator* :sync-for-iterator = _null.{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + dynamic i = :sync-for-iterator.{core::Iterator::current}; + {} + } } ; } diff --git a/pkg/front_end/testcases/nnbd/issue43495.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue43495.dart.strong.transformed.expect index e3ffc572386..3162d813177 100644 --- a/pkg/front_end/testcases/nnbd/issue43495.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/nnbd/issue43495.dart.strong.transformed.expect @@ -171,27 +171,45 @@ import "dart:collection" as col; static method foo(core::bool condition, core::Iterable iterable, core::List? a, core::Set? b, core::Iterable? c, core::Map? d) → dynamic { return [ block { final core::Set #t1 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t2 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:8:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:8:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...a}, // Error. - ^") { - final core::int #t3 = #t2 as{TypeError,ForNonNullableByDefault} core::int; - #t1.{core::Set::add}{Invariant}(#t3); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t2 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t3 = #t2 as{TypeError,ForNonNullableByDefault} core::int; + #t1.{core::Set::add}{Invariant}(#t3); + } + } } } =>#t1, block { final core::Set #t4 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t5 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:9:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:9:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...b}, // Error. - ^") { - final core::int #t6 = #t5 as{TypeError,ForNonNullableByDefault} core::int; - #t4.{core::Set::add}{Invariant}(#t6); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t5 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t6 = #t5 as{TypeError,ForNonNullableByDefault} core::int; + #t4.{core::Set::add}{Invariant}(#t6); + } + } } } =>#t4, block { final core::Set #t7 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t8 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:10:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:10:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...c}, // Error. - ^") { - final core::int #t9 = #t8 as{TypeError,ForNonNullableByDefault} core::int; - #t7.{core::Set::add}{Invariant}(#t9); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t8 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t9 = #t8 as{TypeError,ForNonNullableByDefault} core::int; + #t7.{core::Set::add}{Invariant}(#t9); + } + } } } =>#t7, {invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:11:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...d}, // Error. @@ -206,31 +224,46 @@ static method foo(core::bool condition, core::Iterable iterable, core:: ^"); } =>#t10, block { final core::Set #t11 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t12 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:14:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:14:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...a}, // Error. - ^") { - final core::int #t13 = #t12 as{TypeError,ForNonNullableByDefault} core::int; - #t11.{core::Set::add}{Invariant}(#t13); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t12 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t13 = #t12 as{TypeError,ForNonNullableByDefault} core::int; + #t11.{core::Set::add}{Invariant}(#t13); + } } + } } =>#t11, block { final core::Set #t14 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t15 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:15:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:15:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...b}, // Error. - ^") { - final core::int #t16 = #t15 as{TypeError,ForNonNullableByDefault} core::int; - #t14.{core::Set::add}{Invariant}(#t16); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t15 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t16 = #t15 as{TypeError,ForNonNullableByDefault} core::int; + #t14.{core::Set::add}{Invariant}(#t16); + } } + } } =>#t14, block { final core::Set #t17 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t18 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:16:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:16:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...c}, // Error. - ^") { - final core::int #t19 = #t18 as{TypeError,ForNonNullableByDefault} core::int; - #t17.{core::Set::add}{Invariant}(#t19); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t18 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t19 = #t18 as{TypeError,ForNonNullableByDefault} core::int; + #t17.{core::Set::add}{Invariant}(#t19); + } } + } } =>#t17, block { final core::Map #t20 = {}; if(condition) @@ -243,11 +276,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t22 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:18:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:18:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...a}, // Error. - ^") { - final core::int #t23 = #t22 as{TypeError,ForNonNullableByDefault} core::int; - #t21.{core::Set::add}{Invariant}(#t23); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t22 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t23 = #t22 as{TypeError,ForNonNullableByDefault} core::int; + #t21.{core::Set::add}{Invariant}(#t23); + } + } } } } @@ -257,11 +296,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t25 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:19:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:19:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...b}, // Error. - ^") { - final core::int #t26 = #t25 as{TypeError,ForNonNullableByDefault} core::int; - #t24.{core::Set::add}{Invariant}(#t26); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t25 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t26 = #t25 as{TypeError,ForNonNullableByDefault} core::int; + #t24.{core::Set::add}{Invariant}(#t26); + } + } } } } @@ -271,11 +316,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t28 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:20:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:20:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...c}, // Error. - ^") { - final core::int #t29 = #t28 as{TypeError,ForNonNullableByDefault} core::int; - #t27.{core::Set::add}{Invariant}(#t29); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t28 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t29 = #t28 as{TypeError,ForNonNullableByDefault} core::int; + #t27.{core::Set::add}{Invariant}(#t29); + } + } } } } @@ -292,31 +343,46 @@ static method foo(core::bool condition, core::Iterable iterable, core:: } } =>#t30, block { final core::Set #t31 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t32 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:22:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:22:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...a}, // Error. - ^") { - final core::int #t33 = #t32 as{TypeError,ForNonNullableByDefault} core::int; - #t31.{core::Set::add}{Invariant}(#t33); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t32 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t33 = #t32 as{TypeError,ForNonNullableByDefault} core::int; + #t31.{core::Set::add}{Invariant}(#t33); + } } + } } =>#t31, block { final core::Set #t34 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t35 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:23:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:23:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...b}, // Error. - ^") { - final core::int #t36 = #t35 as{TypeError,ForNonNullableByDefault} core::int; - #t34.{core::Set::add}{Invariant}(#t36); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t35 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t36 = #t35 as{TypeError,ForNonNullableByDefault} core::int; + #t34.{core::Set::add}{Invariant}(#t36); + } } + } } =>#t34, block { final core::Set #t37 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t38 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:24:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:24:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...c}, // Error. - ^") { - final core::int #t39 = #t38 as{TypeError,ForNonNullableByDefault} core::int; - #t37.{core::Set::add}{Invariant}(#t39); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t38 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t39 = #t38 as{TypeError,ForNonNullableByDefault} core::int; + #t37.{core::Set::add}{Invariant}(#t39); + } } + } } =>#t37, block { final core::Map #t40 = {}; for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) @@ -572,27 +638,45 @@ static method foo(core::bool condition, core::Iterable iterable, core:: static method bar? = core::List?, Y extends core::Set? = core::Set?, Z extends core::Iterable? = core::Iterable?, W extends core::Map? = core::Map?>(core::bool condition, core::Iterable iterable, self::bar::X% x, self::bar::Y% y, self::bar::Z% z, self::bar::W% w) → dynamic { return [ block { final core::Set #t101 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t102 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:50:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:50:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...x}, // Error. - ^") { - final core::int #t103 = #t102 as{TypeError,ForNonNullableByDefault} core::int; - #t101.{core::Set::add}{Invariant}(#t103); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t102 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t103 = #t102 as{TypeError,ForNonNullableByDefault} core::int; + #t101.{core::Set::add}{Invariant}(#t103); + } + } } } =>#t101, block { final core::Set #t104 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t105 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:51:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:51:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...y}, // Error. - ^") { - final core::int #t106 = #t105 as{TypeError,ForNonNullableByDefault} core::int; - #t104.{core::Set::add}{Invariant}(#t106); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t105 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t106 = #t105 as{TypeError,ForNonNullableByDefault} core::int; + #t104.{core::Set::add}{Invariant}(#t106); + } + } } } =>#t104, block { final core::Set #t107 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t108 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:52:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:52:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...z}, // Error. - ^") { - final core::int #t109 = #t108 as{TypeError,ForNonNullableByDefault} core::int; - #t107.{core::Set::add}{Invariant}(#t109); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t108 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t109 = #t108 as{TypeError,ForNonNullableByDefault} core::int; + #t107.{core::Set::add}{Invariant}(#t109); + } + } } } =>#t107, {invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:53:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...w}, // Error. @@ -605,31 +689,46 @@ static method bar? = core::List?, Y e ^"); } =>#t110, block { final core::Set #t111 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t112 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:56:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:56:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...x}, // Error. - ^") { - final core::int #t113 = #t112 as{TypeError,ForNonNullableByDefault} core::int; - #t111.{core::Set::add}{Invariant}(#t113); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t112 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t113 = #t112 as{TypeError,ForNonNullableByDefault} core::int; + #t111.{core::Set::add}{Invariant}(#t113); + } } + } } =>#t111, block { final core::Set #t114 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t115 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:57:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:57:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...y}, // Error. - ^") { - final core::int #t116 = #t115 as{TypeError,ForNonNullableByDefault} core::int; - #t114.{core::Set::add}{Invariant}(#t116); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t115 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t116 = #t115 as{TypeError,ForNonNullableByDefault} core::int; + #t114.{core::Set::add}{Invariant}(#t116); + } } + } } =>#t114, block { final core::Set #t117 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t118 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:58:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:58:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...z}, // Error. - ^") { - final core::int #t119 = #t118 as{TypeError,ForNonNullableByDefault} core::int; - #t117.{core::Set::add}{Invariant}(#t119); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t118 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t119 = #t118 as{TypeError,ForNonNullableByDefault} core::int; + #t117.{core::Set::add}{Invariant}(#t119); + } } + } } =>#t117, block { final core::Map #t120 = {}; if(condition) @@ -642,11 +741,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t122 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:60:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:60:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...x}, // Error. - ^") { - final core::int #t123 = #t122 as{TypeError,ForNonNullableByDefault} core::int; - #t121.{core::Set::add}{Invariant}(#t123); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t122 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t123 = #t122 as{TypeError,ForNonNullableByDefault} core::int; + #t121.{core::Set::add}{Invariant}(#t123); + } + } } } } @@ -656,11 +761,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t125 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:61:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:61:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...y}, // Error. - ^") { - final core::int #t126 = #t125 as{TypeError,ForNonNullableByDefault} core::int; - #t124.{core::Set::add}{Invariant}(#t126); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t125 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t126 = #t125 as{TypeError,ForNonNullableByDefault} core::int; + #t124.{core::Set::add}{Invariant}(#t126); + } + } } } } @@ -670,11 +781,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t128 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:62:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:62:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...z}, // Error. - ^") { - final core::int #t129 = #t128 as{TypeError,ForNonNullableByDefault} core::int; - #t127.{core::Set::add}{Invariant}(#t129); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t128 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t129 = #t128 as{TypeError,ForNonNullableByDefault} core::int; + #t127.{core::Set::add}{Invariant}(#t129); + } + } } } } @@ -691,31 +808,46 @@ static method bar? = core::List?, Y e } } =>#t130, block { final core::Set #t131 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t132 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:64:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:64:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...x}, // Error. - ^") { - final core::int #t133 = #t132 as{TypeError,ForNonNullableByDefault} core::int; - #t131.{core::Set::add}{Invariant}(#t133); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t132 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t133 = #t132 as{TypeError,ForNonNullableByDefault} core::int; + #t131.{core::Set::add}{Invariant}(#t133); + } } + } } =>#t131, block { final core::Set #t134 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t135 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:65:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:65:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...y}, // Error. - ^") { - final core::int #t136 = #t135 as{TypeError,ForNonNullableByDefault} core::int; - #t134.{core::Set::add}{Invariant}(#t136); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t135 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t136 = #t135 as{TypeError,ForNonNullableByDefault} core::int; + #t134.{core::Set::add}{Invariant}(#t136); + } } + } } =>#t134, block { final core::Set #t137 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t138 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:66:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:66:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...z}, // Error. - ^") { - final core::int #t139 = #t138 as{TypeError,ForNonNullableByDefault} core::int; - #t137.{core::Set::add}{Invariant}(#t139); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t138 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t139 = #t138 as{TypeError,ForNonNullableByDefault} core::int; + #t137.{core::Set::add}{Invariant}(#t139); + } } + } } =>#t137, block { final core::Map #t140 = {}; for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) diff --git a/pkg/front_end/testcases/nnbd/issue43495.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue43495.dart.weak.transformed.expect index e3ffc572386..3162d813177 100644 --- a/pkg/front_end/testcases/nnbd/issue43495.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/nnbd/issue43495.dart.weak.transformed.expect @@ -171,27 +171,45 @@ import "dart:collection" as col; static method foo(core::bool condition, core::Iterable iterable, core::List? a, core::Set? b, core::Iterable? c, core::Map? d) → dynamic { return [ block { final core::Set #t1 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t2 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:8:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:8:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...a}, // Error. - ^") { - final core::int #t3 = #t2 as{TypeError,ForNonNullableByDefault} core::int; - #t1.{core::Set::add}{Invariant}(#t3); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t2 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t3 = #t2 as{TypeError,ForNonNullableByDefault} core::int; + #t1.{core::Set::add}{Invariant}(#t3); + } + } } } =>#t1, block { final core::Set #t4 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t5 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:9:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:9:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...b}, // Error. - ^") { - final core::int #t6 = #t5 as{TypeError,ForNonNullableByDefault} core::int; - #t4.{core::Set::add}{Invariant}(#t6); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t5 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t6 = #t5 as{TypeError,ForNonNullableByDefault} core::int; + #t4.{core::Set::add}{Invariant}(#t6); + } + } } } =>#t4, block { final core::Set #t7 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t8 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:10:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:10:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...c}, // Error. - ^") { - final core::int #t9 = #t8 as{TypeError,ForNonNullableByDefault} core::int; - #t7.{core::Set::add}{Invariant}(#t9); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t8 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t9 = #t8 as{TypeError,ForNonNullableByDefault} core::int; + #t7.{core::Set::add}{Invariant}(#t9); + } + } } } =>#t7, {invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:11:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...d}, // Error. @@ -206,31 +224,46 @@ static method foo(core::bool condition, core::Iterable iterable, core:: ^"); } =>#t10, block { final core::Set #t11 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t12 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:14:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:14:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...a}, // Error. - ^") { - final core::int #t13 = #t12 as{TypeError,ForNonNullableByDefault} core::int; - #t11.{core::Set::add}{Invariant}(#t13); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t12 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t13 = #t12 as{TypeError,ForNonNullableByDefault} core::int; + #t11.{core::Set::add}{Invariant}(#t13); + } } + } } =>#t11, block { final core::Set #t14 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t15 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:15:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:15:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...b}, // Error. - ^") { - final core::int #t16 = #t15 as{TypeError,ForNonNullableByDefault} core::int; - #t14.{core::Set::add}{Invariant}(#t16); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t15 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t16 = #t15 as{TypeError,ForNonNullableByDefault} core::int; + #t14.{core::Set::add}{Invariant}(#t16); + } } + } } =>#t14, block { final core::Set #t17 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t18 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:16:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:16:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...c}, // Error. - ^") { - final core::int #t19 = #t18 as{TypeError,ForNonNullableByDefault} core::int; - #t17.{core::Set::add}{Invariant}(#t19); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t18 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t19 = #t18 as{TypeError,ForNonNullableByDefault} core::int; + #t17.{core::Set::add}{Invariant}(#t19); + } } + } } =>#t17, block { final core::Map #t20 = {}; if(condition) @@ -243,11 +276,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t22 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:18:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:18:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...a}, // Error. - ^") { - final core::int #t23 = #t22 as{TypeError,ForNonNullableByDefault} core::int; - #t21.{core::Set::add}{Invariant}(#t23); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t22 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t23 = #t22 as{TypeError,ForNonNullableByDefault} core::int; + #t21.{core::Set::add}{Invariant}(#t23); + } + } } } } @@ -257,11 +296,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t25 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:19:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:19:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...b}, // Error. - ^") { - final core::int #t26 = #t25 as{TypeError,ForNonNullableByDefault} core::int; - #t24.{core::Set::add}{Invariant}(#t26); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t25 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t26 = #t25 as{TypeError,ForNonNullableByDefault} core::int; + #t24.{core::Set::add}{Invariant}(#t26); + } + } } } } @@ -271,11 +316,17 @@ static method foo(core::bool condition, core::Iterable iterable, core:: core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t28 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:20:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:20:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...c}, // Error. - ^") { - final core::int #t29 = #t28 as{TypeError,ForNonNullableByDefault} core::int; - #t27.{core::Set::add}{Invariant}(#t29); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t28 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t29 = #t28 as{TypeError,ForNonNullableByDefault} core::int; + #t27.{core::Set::add}{Invariant}(#t29); + } + } } } } @@ -292,31 +343,46 @@ static method foo(core::bool condition, core::Iterable iterable, core:: } } =>#t30, block { final core::Set #t31 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t32 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:22:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:22:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...a}, // Error. - ^") { - final core::int #t33 = #t32 as{TypeError,ForNonNullableByDefault} core::int; - #t31.{core::Set::add}{Invariant}(#t33); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t32 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t33 = #t32 as{TypeError,ForNonNullableByDefault} core::int; + #t31.{core::Set::add}{Invariant}(#t33); + } } + } } =>#t31, block { final core::Set #t34 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t35 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:23:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:23:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...b}, // Error. - ^") { - final core::int #t36 = #t35 as{TypeError,ForNonNullableByDefault} core::int; - #t34.{core::Set::add}{Invariant}(#t36); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t35 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t36 = #t35 as{TypeError,ForNonNullableByDefault} core::int; + #t34.{core::Set::add}{Invariant}(#t36); + } } + } } =>#t34, block { final core::Set #t37 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t38 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:24:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:24:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...c}, // Error. - ^") { - final core::int #t39 = #t38 as{TypeError,ForNonNullableByDefault} core::int; - #t37.{core::Set::add}{Invariant}(#t39); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t38 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t39 = #t38 as{TypeError,ForNonNullableByDefault} core::int; + #t37.{core::Set::add}{Invariant}(#t39); + } } + } } =>#t37, block { final core::Map #t40 = {}; for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) @@ -572,27 +638,45 @@ static method foo(core::bool condition, core::Iterable iterable, core:: static method bar? = core::List?, Y extends core::Set? = core::Set?, Z extends core::Iterable? = core::Iterable?, W extends core::Map? = core::Map?>(core::bool condition, core::Iterable iterable, self::bar::X% x, self::bar::Y% y, self::bar::Z% z, self::bar::W% w) → dynamic { return [ block { final core::Set #t101 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t102 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:50:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:50:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...x}, // Error. - ^") { - final core::int #t103 = #t102 as{TypeError,ForNonNullableByDefault} core::int; - #t101.{core::Set::add}{Invariant}(#t103); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t102 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t103 = #t102 as{TypeError,ForNonNullableByDefault} core::int; + #t101.{core::Set::add}{Invariant}(#t103); + } + } } } =>#t101, block { final core::Set #t104 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t105 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:51:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:51:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...y}, // Error. - ^") { - final core::int #t106 = #t105 as{TypeError,ForNonNullableByDefault} core::int; - #t104.{core::Set::add}{Invariant}(#t106); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t105 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t106 = #t105 as{TypeError,ForNonNullableByDefault} core::int; + #t104.{core::Set::add}{Invariant}(#t106); + } + } } } =>#t104, block { final core::Set #t107 = new col::_CompactLinkedHashSet::•(); - for (final dynamic #t108 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:52:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:52:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...z}, // Error. - ^") { - final core::int #t109 = #t108 as{TypeError,ForNonNullableByDefault} core::int; - #t107.{core::Set::add}{Invariant}(#t109); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t108 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t109 = #t108 as{TypeError,ForNonNullableByDefault} core::int; + #t107.{core::Set::add}{Invariant}(#t109); + } + } } } =>#t107, {invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:53:9: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {...w}, // Error. @@ -605,31 +689,46 @@ static method bar? = core::List?, Y e ^"); } =>#t110, block { final core::Set #t111 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t112 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:56:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:56:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...x}, // Error. - ^") { - final core::int #t113 = #t112 as{TypeError,ForNonNullableByDefault} core::int; - #t111.{core::Set::add}{Invariant}(#t113); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t112 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t113 = #t112 as{TypeError,ForNonNullableByDefault} core::int; + #t111.{core::Set::add}{Invariant}(#t113); + } } + } } =>#t111, block { final core::Set #t114 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t115 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:57:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:57:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...y}, // Error. - ^") { - final core::int #t116 = #t115 as{TypeError,ForNonNullableByDefault} core::int; - #t114.{core::Set::add}{Invariant}(#t116); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t115 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t116 = #t115 as{TypeError,ForNonNullableByDefault} core::int; + #t114.{core::Set::add}{Invariant}(#t116); + } } + } } =>#t114, block { final core::Set #t117 = new col::_CompactLinkedHashSet::•(); - if(condition) - for (final dynamic #t118 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:58:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + if(condition) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:58:24: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {if (condition) ...z}, // Error. - ^") { - final core::int #t119 = #t118 as{TypeError,ForNonNullableByDefault} core::int; - #t117.{core::Set::add}{Invariant}(#t119); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t118 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t119 = #t118 as{TypeError,ForNonNullableByDefault} core::int; + #t117.{core::Set::add}{Invariant}(#t119); + } } + } } =>#t117, block { final core::Map #t120 = {}; if(condition) @@ -642,11 +741,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t122 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:60:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:60:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...x}, // Error. - ^") { - final core::int #t123 = #t122 as{TypeError,ForNonNullableByDefault} core::int; - #t121.{core::Set::add}{Invariant}(#t123); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t122 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t123 = #t122 as{TypeError,ForNonNullableByDefault} core::int; + #t121.{core::Set::add}{Invariant}(#t123); + } + } } } } @@ -656,11 +761,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t125 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:61:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:61:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...y}, // Error. - ^") { - final core::int #t126 = #t125 as{TypeError,ForNonNullableByDefault} core::int; - #t124.{core::Set::add}{Invariant}(#t126); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t125 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t126 = #t125 as{TypeError,ForNonNullableByDefault} core::int; + #t124.{core::Set::add}{Invariant}(#t126); + } + } } } } @@ -670,11 +781,17 @@ static method bar? = core::List?, Y e core::Iterator :sync-for-iterator = iterable.{core::Iterable::iterator}; for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { dynamic e = :sync-for-iterator.{core::Iterator::current}; - for (final dynamic #t128 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:62:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:62:37: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (dynamic e in iterable) ...z}, // Error. - ^") { - final core::int #t129 = #t128 as{TypeError,ForNonNullableByDefault} core::int; - #t127.{core::Set::add}{Invariant}(#t129); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t128 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t129 = #t128 as{TypeError,ForNonNullableByDefault} core::int; + #t127.{core::Set::add}{Invariant}(#t129); + } + } } } } @@ -691,31 +808,46 @@ static method bar? = core::List?, Y e } } =>#t130, block { final core::Set #t131 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t132 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:64:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:64:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...x}, // Error. - ^") { - final core::int #t133 = #t132 as{TypeError,ForNonNullableByDefault} core::int; - #t131.{core::Set::add}{Invariant}(#t133); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t132 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t133 = #t132 as{TypeError,ForNonNullableByDefault} core::int; + #t131.{core::Set::add}{Invariant}(#t133); + } } + } } =>#t131, block { final core::Set #t134 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t135 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:65:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:65:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...y}, // Error. - ^") { - final core::int #t136 = #t135 as{TypeError,ForNonNullableByDefault} core::int; - #t134.{core::Set::add}{Invariant}(#t136); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t135 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t136 = #t135 as{TypeError,ForNonNullableByDefault} core::int; + #t134.{core::Set::add}{Invariant}(#t136); + } } + } } =>#t134, block { final core::Set #t137 = new col::_CompactLinkedHashSet::•(); - for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) - for (final dynamic #t138 in invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:66:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. + for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) { + core::Iterator :sync-for-iterator = invalid-expression "pkg/front_end/testcases/nnbd/issue43495.dart:66:38: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. {for (int i = 0; i < 42; ++i) ...z}, // Error. - ^") { - final core::int #t139 = #t138 as{TypeError,ForNonNullableByDefault} core::int; - #t137.{core::Set::add}{Invariant}(#t139); + ^".{core::Iterable::iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) { + final dynamic #t138 = :sync-for-iterator.{core::Iterator::current}; + { + final core::int #t139 = #t138 as{TypeError,ForNonNullableByDefault} core::int; + #t137.{core::Set::add}{Invariant}(#t139); + } } + } } =>#t137, block { final core::Map #t140 = {}; for (core::int i = 0; i.{core::num::<}(42); i = i.{core::num::+}(1)) diff --git a/pkg/front_end/testcases/text_serialization.status b/pkg/front_end/testcases/text_serialization.status index bd4dc726927..91180e91ae3 100644 --- a/pkg/front_end/testcases/text_serialization.status +++ b/pkg/front_end/testcases/text_serialization.status @@ -18,7 +18,6 @@ extensions/static_access_of_instance: RuntimeError general/abstract_members: TypeCheckError general/accessors: RuntimeError general/ambiguous_exports: RuntimeError -general/async_method_with_invalid_type: Crash general/await_in_non_async: RuntimeError general/bug21938: TypeCheckError general/bug30695: TypeCheckError diff --git a/pkg/front_end/testcases/weak.status b/pkg/front_end/testcases/weak.status index 10873287aed..95656fe68ae 100644 --- a/pkg/front_end/testcases/weak.status +++ b/pkg/front_end/testcases/weak.status @@ -21,7 +21,6 @@ extensions/static_access_of_instance: RuntimeError general/abstract_members: TypeCheckError general/accessors: RuntimeError general/ambiguous_exports: RuntimeError # Expected, this file exports two main methods. -general/async_method_with_invalid_type: Crash general/await_in_non_async: RuntimeError # Expected. general/bug21938: TypeCheckError general/bug30695: TypeCheckError diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart index 5690ddb540b..7e38523d8c4 100644 --- a/pkg/kernel/lib/ast.dart +++ b/pkg/kernel/lib/ast.dart @@ -9119,15 +9119,26 @@ class ForInStatement extends Statement { TypeParameterType typeParameterType = iterableType; iterableType = typeParameterType.bound; } + if (iterableType is NeverType) { + return iterableType; + } + if (iterableType is InvalidType) { + return iterableType; + } + if (iterableType is! InterfaceType) { + // TODO(johnniwinther): Change this to an assert once the CFE correctly + // inserts casts for all invalid iterable types. + return const InvalidType(); + } if (isAsync) { List typeArguments = context.typeEnvironment - .getTypeArgumentsAsInstanceOf(iterableType as InterfaceType, - context.typeEnvironment.coreTypes.streamClass)!; + .getTypeArgumentsAsInstanceOf( + iterableType, context.typeEnvironment.coreTypes.streamClass)!; return typeArguments.single; } else { List typeArguments = context.typeEnvironment - .getTypeArgumentsAsInstanceOf(iterableType as InterfaceType, - context.typeEnvironment.coreTypes.iterableClass)!; + .getTypeArgumentsAsInstanceOf( + iterableType, context.typeEnvironment.coreTypes.iterableClass)!; return typeArguments.single; } } diff --git a/pkg/kernel/lib/transformations/continuation.dart b/pkg/kernel/lib/transformations/continuation.dart index 24ed26c3b82..5b8e4b00ff5 100644 --- a/pkg/kernel/lib/transformations/continuation.dart +++ b/pkg/kernel/lib/transformations/continuation.dart @@ -175,29 +175,18 @@ class RecursiveContinuationRewriter extends Transformer { // } final CoreTypes coreTypes = staticTypeContext.typeEnvironment.coreTypes; - DartType iterableType = stmt.iterable.getStaticType(staticTypeContext); - while (iterableType is TypeParameterType) { - TypeParameterType typeParameterType = iterableType; - iterableType = - typeParameterType.promotedBound ?? typeParameterType.parameter.bound; - } - // The CFE might invoke this transformation despite the program having // compile-time errors. So we will not transform this [stmt] if the - // `stmt.iterable` is not a subtype of non-nullable/legacy Iterable. - if (iterableType is! InterfaceType || - !staticTypeContext.typeEnvironment.isSubtypeOf( - iterableType, - coreTypes.iterableRawType(staticTypeContext.nonNullable), - staticTypeContext.isNonNullableByDefault - ? SubtypeCheckMode.withNullabilities - : SubtypeCheckMode.ignoringNullabilities)) { - return super.visitForInStatement(stmt); + // `stmt.iterable` is an invalid expression or has an invalid type and + // instead eliminate the entire for-in and replace it with a invalid + // expression statement. + final iterable = stmt.iterable; + final iterableType = iterable.getStaticType(staticTypeContext); + if (iterableType is InvalidType) { + return ExpressionStatement( + InvalidExpression('Invalid iterable type in for-in')); } - final DartType iterationType = staticTypeContext.typeEnvironment - .forInElementType(stmt, (iterableType as InterfaceType)); - // The NNBD sdk declares that Iterable.get:iterator returns a non-nullable // `Iterator`. assert(const [ @@ -205,20 +194,21 @@ class RecursiveContinuationRewriter extends Transformer { Nullability.legacy ].contains(coreTypes.iterableGetIterator.function.returnType.nullability)); - final iteratorType = InterfaceType(coreTypes.iteratorClass, - staticTypeContext.nonNullable, [iterationType]); + final DartType elementType = stmt.getElementType(staticTypeContext); + final iteratorType = InterfaceType( + coreTypes.iteratorClass, staticTypeContext.nonNullable, [elementType]); final syncForIterator = VariableDeclaration( ContinuationVariables.syncForIterator, initializer: PropertyGet( - stmt.iterable, Name('iterator'), coreTypes.iterableGetIterator) - ..fileOffset = stmt.iterable.fileOffset, + iterable, Name('iterator'), coreTypes.iterableGetIterator) + ..fileOffset = iterable.fileOffset, type: iteratorType) - ..fileOffset = stmt.iterable.fileOffset; + ..fileOffset = iterable.fileOffset; final condition = MethodInvocation(VariableGet(syncForIterator), Name('moveNext'), Arguments([]), coreTypes.iteratorMoveNext) - ..fileOffset = stmt.iterable.fileOffset; + ..fileOffset = iterable.fileOffset; final variable = stmt.variable ..initializer = (PropertyGet(VariableGet(syncForIterator), diff --git a/runtime/tests/vm/dart/regress_45014_test.dart b/runtime/tests/vm/dart/regress_45014_test.dart new file mode 100644 index 00000000000..31ccddc6eb1 --- /dev/null +++ b/runtime/tests/vm/dart/regress_45014_test.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2011, 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. + +main() { + neverForInExpressionType(); //# 01: runtime error +} + +neverForInExpressionType() async { //# 01: continued + return { //# 01: continued + for (var y in throw '') ...y, //# 01: continued + }; //# 01: continued +} //# 01: continued + +invalidForInExpressionType(X x) async { //# 02: compile-time error + return { //# 02: continued + for (var y in x) ...y, //# 02: continued + }; //# 02: continued +} //# 02: continued + diff --git a/runtime/tests/vm/dart_2/regress_45014_test.dart b/runtime/tests/vm/dart_2/regress_45014_test.dart new file mode 100644 index 00000000000..31ccddc6eb1 --- /dev/null +++ b/runtime/tests/vm/dart_2/regress_45014_test.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2011, 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. + +main() { + neverForInExpressionType(); //# 01: runtime error +} + +neverForInExpressionType() async { //# 01: continued + return { //# 01: continued + for (var y in throw '') ...y, //# 01: continued + }; //# 01: continued +} //# 01: continued + +invalidForInExpressionType(X x) async { //# 02: compile-time error + return { //# 02: continued + for (var y in x) ...y, //# 02: continued + }; //# 02: continued +} //# 02: continued +