diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index af89434c91d..05ba30747a7 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -6177,6 +6177,9 @@ class BodyBuilder extends StackListenerImpl fasta.messageForInLoopWithConstVariable, lvalue.fileOffset, lvalue.name!.length); + // As a recovery step, remove the const flag, to not confuse the + // constant evaluator further in the pipeline. + lvalue.isConst = false; } } else { VariableDeclaration variable = elements.syntheticVariableDeclaration = diff --git a/pkg/front_end/testcases/general/issue48808.dart b/pkg/front_end/testcases/general/issue48808.dart new file mode 100644 index 00000000000..b955652985f --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2022, 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. + +foo() { + for (const x in [1, 2, 3]) print(x); +} + +main() {} diff --git a/pkg/front_end/testcases/general/issue48808.dart.textual_outline.expect b/pkg/front_end/testcases/general/issue48808.dart.textual_outline.expect new file mode 100644 index 00000000000..d530fa8d4d7 --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.textual_outline.expect @@ -0,0 +1,2 @@ +foo() {} +main() {} diff --git a/pkg/front_end/testcases/general/issue48808.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/general/issue48808.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..d530fa8d4d7 --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.textual_outline_modelled.expect @@ -0,0 +1,2 @@ +foo() {} +main() {} diff --git a/pkg/front_end/testcases/general/issue48808.dart.weak.expect b/pkg/front_end/testcases/general/issue48808.dart.weak.expect new file mode 100644 index 00000000000..10ba349118d --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.weak.expect @@ -0,0 +1,23 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +// Try removing the 'const' modifier. +// for (const x in [1, 2, 3]) print(x); +// ^ +// +import self as self; +import "dart:core" as core; + +static method foo() → dynamic { + { + invalid-expression "pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +Try removing the 'const' modifier. + for (const x in [1, 2, 3]) print(x); + ^"; + for (core::int x in [1, 2, 3]) + core::print(x); + } +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/issue48808.dart.weak.modular.expect b/pkg/front_end/testcases/general/issue48808.dart.weak.modular.expect new file mode 100644 index 00000000000..10ba349118d --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.weak.modular.expect @@ -0,0 +1,23 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +// Try removing the 'const' modifier. +// for (const x in [1, 2, 3]) print(x); +// ^ +// +import self as self; +import "dart:core" as core; + +static method foo() → dynamic { + { + invalid-expression "pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +Try removing the 'const' modifier. + for (const x in [1, 2, 3]) print(x); + ^"; + for (core::int x in [1, 2, 3]) + core::print(x); + } +} +static method main() → dynamic {} diff --git a/pkg/front_end/testcases/general/issue48808.dart.weak.outline.expect b/pkg/front_end/testcases/general/issue48808.dart.weak.outline.expect new file mode 100644 index 00000000000..8570841fbe3 --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.weak.outline.expect @@ -0,0 +1,7 @@ +library /*isNonNullableByDefault*/; +import self as self; + +static method foo() → dynamic + ; +static method main() → dynamic + ; diff --git a/pkg/front_end/testcases/general/issue48808.dart.weak.transformed.expect b/pkg/front_end/testcases/general/issue48808.dart.weak.transformed.expect new file mode 100644 index 00000000000..4a8424fb871 --- /dev/null +++ b/pkg/front_end/testcases/general/issue48808.dart.weak.transformed.expect @@ -0,0 +1,28 @@ +library /*isNonNullableByDefault*/; +// +// Problems in library: +// +// pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +// Try removing the 'const' modifier. +// for (const x in [1, 2, 3]) print(x); +// ^ +// +import self as self; +import "dart:core" as core; + +static method foo() → dynamic { + { + invalid-expression "pkg/front_end/testcases/general/issue48808.dart:6:14: Error: A for-in loop-variable can't be 'const'. +Try removing the 'const' modifier. + for (const x in [1, 2, 3]) print(x); + ^"; + { + core::Iterator :sync-for-iterator = core::_GrowableList::_literal3(1, 2, 3).{core::Iterable::iterator}{core::Iterator}; + for (; :sync-for-iterator.{core::Iterator::moveNext}(){() → core::bool}; ) { + core::int x = :sync-for-iterator.{core::Iterator::current}{core::int}; + core::print(x); + } + } + } +} +static method main() → dynamic {}