diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index 3b5b4a11aae..4c1ef400b5a 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -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)); } diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart new file mode 100644 index 00000000000..24c3553eb77 --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart @@ -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; +} diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.expect new file mode 100644 index 00000000000..919601c2bd8 --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.expect @@ -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}; +} diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.modular.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.modular.expect new file mode 100644 index 00000000000..919601c2bd8 --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.modular.expect @@ -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}; +} diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.outline.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.outline.expect new file mode 100644 index 00000000000..92e8530060c --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.outline.expect @@ -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 + ; diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.transformed.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.transformed.expect new file mode 100644 index 00000000000..919601c2bd8 --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.strong.transformed.expect @@ -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}; +} diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline.expect new file mode 100644 index 00000000000..3a285573d77 --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline.expect @@ -0,0 +1,7 @@ +class Color { + final int x; + Color get red => Color(1); + Color(this.x); +} + +void main() {} diff --git a/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..2a811d1e10b --- /dev/null +++ b/pkg/front_end/testcases/dot_shorthands/shorthand_context_generator.dart.textual_outline_modelled.expect @@ -0,0 +1,7 @@ +class Color { + Color(this.x); + Color get red => Color(1); + final int x; +} + +void main() {} diff --git a/tests/language/dot_shorthands/multiple/type_alias_test.dart b/tests/language/dot_shorthands/multiple/type_alias_test.dart index 510c3989932..dd8ee6e7e5d 100644 --- a/tests/language/dot_shorthands/multiple/type_alias_test.dart +++ b/tests/language/dot_shorthands/multiple/type_alias_test.dart @@ -41,13 +41,13 @@ extension type AExt(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; }