Skip to content

Commit

Permalink
[CFE] Fix crash on AmbiguousBuilder in handleUnaryPrefixExpression
Browse files Browse the repository at this point in the history
Change-Id: I76fb3f77f9ffbbe6a7ecb892d3a5a21019b66371
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394500
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Jens Johansen <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Nov 12, 2024
1 parent a0c4efd commit 65036c9
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/front_end/lib/src/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5826,9 +5826,11 @@ class BodyBuilder extends StackListenerImpl
Name name = new Name(operator);
if (receiver is Generator) {
push(receiver.buildUnaryOperation(token, name));
} else if (receiver is Expression) {
push(forest.createUnary(fileOffset, name, receiver));
} else {
assert(receiver is Expression);
push(forest.createUnary(fileOffset, name, receiver as Expression));
Expression value = toValue(receiver);
push(forest.createUnary(fileOffset, name, value));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/front_end/testcases/regress/ambiguous_builder_03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, 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.

class Bar {
get foo => 42;
get foo => ~foo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:7: Error: 'foo' is already declared in this scope.
// get foo => ~foo;
// ^^^
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:6:7: Context: Previous declaration of 'foo'.
// get foo => 42;
// ^^^
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:15: Error: Can't use 'foo' because it is declared more than once.
// get foo => ~foo;
// ^
//
import self as self;
import "dart:core" as core;

class Bar extends core::Object {
synthetic constructor •() → self::Bar
: super core::Object::•()
;
get foo() → dynamic
return 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:7: Error: 'foo' is already declared in this scope.
// get foo => ~foo;
// ^^^
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:6:7: Context: Previous declaration of 'foo'.
// get foo => 42;
// ^^^
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:15: Error: Can't use 'foo' because it is declared more than once.
// get foo => ~foo;
// ^
//
import self as self;
import "dart:core" as core;

class Bar extends core::Object {
synthetic constructor •() → self::Bar
: super core::Object::•()
;
get foo() → dynamic
return 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:7: Error: 'foo' is already declared in this scope.
// get foo => ~foo;
// ^^^
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:6:7: Context: Previous declaration of 'foo'.
// get foo => 42;
// ^^^
//
import self as self;
import "dart:core" as core;

class Bar extends core::Object {
synthetic constructor •() → self::Bar
;
get foo() → dynamic
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:7: Error: 'foo' is already declared in this scope.
// get foo => ~foo;
// ^^^
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:6:7: Context: Previous declaration of 'foo'.
// get foo => 42;
// ^^^
//
// pkg/front_end/testcases/regress/ambiguous_builder_03.dart:7:15: Error: Can't use 'foo' because it is declared more than once.
// get foo => ~foo;
// ^
//
import self as self;
import "dart:core" as core;

class Bar extends core::Object {
synthetic constructor •() → self::Bar
: super core::Object::•()
;
get foo() → dynamic
return 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Bar {
get foo => 42;
get foo => ~foo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Bar {
get foo => 42;
get foo => ~foo;
}

0 comments on commit 65036c9

Please sign in to comment.