[cfe] Dot shorthands - Allow 'handleDotShorthandContext' to handle non-expressions.

Update the parser handler for the dot shorthand wrapper to handle more than just expressions. Needed for selector chains.

Additionally, fixing a type alias test that would now work, but has a typo.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: Ifaf61b3ee32e315ecb284a8f81ef875e8af6023a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414662
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Kallen Tu
2025-03-12 07:09:06 -07:00
parent f25a2b4d22
commit bc9723ffce
9 changed files with 94 additions and 5 deletions
@@ -9991,9 +9991,13 @@ class BodyBuilder extends StackListenerImpl
return;
}
// TODO(kallentu): Possibly could be ProblemBuilder? Testing needed.
assert(checkState(token, [ValueKinds.Expression]));
Expression value = pop() as Expression;
assert(checkState(token, [
unionOfKinds([
ValueKinds.Expression,
ValueKinds.Generator,
]),
]));
Expression value = popForValue();
push(forest.createDotShorthandContext(token.charOffset, value));
}
@@ -0,0 +1,13 @@
// Copyright (c) 2025, 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 Color {
final int x;
Color get red => Color(1);
Color(this.x);
}
void main() {
Color c = .new(1).red;
}
@@ -0,0 +1,15 @@
library;
import self as self;
import "dart:core" as core;
class Color extends core::Object {
final field core::int x;
constructor •(core::int x) → self::Color
: self::Color::x = x, super core::Object::•()
;
get red() → self::Color
return new self::Color::•(1);
}
static method main() → void {
self::Color c = new self::Color::•(1).{self::Color::red}{self::Color};
}
@@ -0,0 +1,15 @@
library;
import self as self;
import "dart:core" as core;
class Color extends core::Object {
final field core::int x;
constructor •(core::int x) → self::Color
: self::Color::x = x, super core::Object::•()
;
get red() → self::Color
return new self::Color::•(1);
}
static method main() → void {
self::Color c = new self::Color::•(1).{self::Color::red}{self::Color};
}
@@ -0,0 +1,13 @@
library;
import self as self;
import "dart:core" as core;
class Color extends core::Object {
final field core::int x;
constructor •(core::int x) → self::Color
;
get red() → self::Color
;
}
static method main() → void
;
@@ -0,0 +1,15 @@
library;
import self as self;
import "dart:core" as core;
class Color extends core::Object {
final field core::int x;
constructor •(core::int x) → self::Color
: self::Color::x = x, super core::Object::•()
;
get red() → self::Color
return new self::Color::•(1);
}
static method main() → void {
self::Color c = new self::Color::•(1).{self::Color::red}{self::Color};
}
@@ -0,0 +1,7 @@
class Color {
final int x;
Color get red => Color(1);
Color(this.x);
}
void main() {}
@@ -0,0 +1,7 @@
class Color {
Color(this.x);
Color get red => Color(1);
final int x;
}
void main() {}
@@ -41,13 +41,13 @@ extension type AExt<T>(T t) {
void main() {
// Class
ClassAlias classAlias = .alias;
ClassAlias classAlias2 = .new('s').aliasGetter;
ClassAlias classAlias2 = .new(1).aliasGetter;
ClassAlias classAliasMethod = .method();
const ClassAlias constClassAlias = .constAlias;
// Extension type
ExtensionAlias extensionAlias = .alias;
ExtensionAlias extensionAliasCtor = .new('s').aliasGetter;
ExtensionAlias extensionAliasCtor = .new(1).aliasGetter;
ExtensionAlias extensionAliasMethod = .method();
const ExtensionAlias constExtensionAlias = .constAlias;
}