Skip to content

Commit 8e89041

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Fix crash in AmbiguousBuilder in ForIn
Change-Id: I944b6dfc26fb294f7fbf9b2df12df7eac378ae45 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395540 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent e4c8b49 commit 8e89041

8 files changed

+174
-0
lines changed

pkg/front_end/lib/src/kernel/body_builder.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7712,6 +7712,8 @@ class BodyBuilder extends StackListenerImpl
77127712
lvalue,
77137713
new VariableGetImpl(variable, forNullGuardedAccess: false),
77147714
isFinal: false);
7715+
} else if (lvalue is AmbiguousBuilder) {
7716+
elements.expressionProblem = toValue(lvalue);
77157717
} else {
77167718
Message message = forest.isVariablesDeclaration(lvalue)
77177719
? fasta.messageForInLoopExactlyOneVariable
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class Foo {
6+
int? x;
7+
8+
void foo() {
9+
for(x in [42]) {
10+
print(x);
11+
}
12+
}
13+
14+
void x() { }
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:14:8: Error: 'x' is already declared in this scope.
6+
// void x() { }
7+
// ^
8+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:6:8: Context: Previous declaration of 'x'.
9+
// int? x;
10+
// ^
11+
//
12+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
13+
// print(x);
14+
// ^
15+
//
16+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
17+
// for(x in [42]) {
18+
// ^
19+
//
20+
import self as self;
21+
import "dart:core" as core;
22+
23+
class Foo extends core::Object {
24+
field core::int? x = null;
25+
synthetic constructor •() → self::Foo
26+
: super core::Object::•()
27+
;
28+
method foo() → void {
29+
{
30+
invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
31+
for(x in [42]) {
32+
^";
33+
for (final core::int #t1 in <core::int>[42]) {
34+
core::print(invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
35+
print(x);
36+
^");
37+
}
38+
}
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:14:8: Error: 'x' is already declared in this scope.
6+
// void x() { }
7+
// ^
8+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:6:8: Context: Previous declaration of 'x'.
9+
// int? x;
10+
// ^
11+
//
12+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
13+
// print(x);
14+
// ^
15+
//
16+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
17+
// for(x in [42]) {
18+
// ^
19+
//
20+
import self as self;
21+
import "dart:core" as core;
22+
23+
class Foo extends core::Object {
24+
field core::int? x = null;
25+
synthetic constructor •() → self::Foo
26+
: super core::Object::•()
27+
;
28+
method foo() → void {
29+
{
30+
invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
31+
for(x in [42]) {
32+
^";
33+
for (final core::int #t1 in <core::int>[42]) {
34+
core::print(invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
35+
print(x);
36+
^");
37+
}
38+
}
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:14:8: Error: 'x' is already declared in this scope.
6+
// void x() { }
7+
// ^
8+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:6:8: Context: Previous declaration of 'x'.
9+
// int? x;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
class Foo extends core::Object {
16+
field core::int? x;
17+
synthetic constructor •() → self::Foo
18+
;
19+
method foo() → void
20+
;
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:14:8: Error: 'x' is already declared in this scope.
6+
// void x() { }
7+
// ^
8+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:6:8: Context: Previous declaration of 'x'.
9+
// int? x;
10+
// ^
11+
//
12+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
13+
// print(x);
14+
// ^
15+
//
16+
// pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
17+
// for(x in [42]) {
18+
// ^
19+
//
20+
import self as self;
21+
import "dart:core" as core;
22+
23+
class Foo extends core::Object {
24+
field core::int? x = null;
25+
synthetic constructor •() → self::Foo
26+
: super core::Object::•()
27+
;
28+
method foo() → void {
29+
{
30+
invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:9:9: Error: Can't use 'x' because it is declared more than once.
31+
for(x in [42]) {
32+
^";
33+
{
34+
synthesized core::Iterator<core::int> :sync-for-iterator = core::_GrowableList::_literal1<core::int>(42).{core::Iterable::iterator}{core::Iterator<core::int>};
35+
for (; :sync-for-iterator.{core::Iterator::moveNext}(){() → core::bool}; ) {
36+
final core::int #t1 = :sync-for-iterator.{core::Iterator::current}{core::int};
37+
{
38+
core::print(invalid-expression "pkg/front_end/testcases/regress/ambiguous_builder_04.dart:10:13: Error: Can't use 'x' because it is declared more than once.
39+
print(x);
40+
^");
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo {
2+
int? x;
3+
void foo() {}
4+
void x() {}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo {
2+
int? x;
3+
void foo() {}
4+
void x() {}
5+
}

0 commit comments

Comments
 (0)