diff --git a/pkg/front_end/lib/src/source/source_loader.dart b/pkg/front_end/lib/src/source/source_loader.dart index 5b644013dba..946cd79fa72 100644 --- a/pkg/front_end/lib/src/source/source_loader.dart +++ b/pkg/front_end/lib/src/source/source_loader.dart @@ -2948,6 +2948,13 @@ severity: $severity if (redirectingFactoryBuilders != null) { for (RedirectingFactoryBuilder redirectingFactoryBuilder in redirectingFactoryBuilders) { + if (redirectingFactoryBuilder.parent.isExtension) { + // Extensions don't build their redirecting factories so we can't + // process them. Once they are added in + // [DeclarationNameSpaceBuilder.buildNameSpace] this skipping can + // likely be removed. + continue; + } redirectingFactoryBuilder.buildOutlineExpressions( classHierarchy, delayedDefaultValueCloners); } diff --git a/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart b/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart index aa32e32a087..bb98b9f499e 100644 --- a/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart +++ b/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart @@ -1459,6 +1459,10 @@ class DeclarationNameSpaceBuilder { // TODO(johnniwinther): Handle constructors in extensions consistently. // Currently they are not part of the name space but still processed // for instance when inferring redirecting factories. + // They are part of the name space for extension types though. + // Note that we have to remove [RedirectingFactoryBuilder]s in + // [SourceLoader.inferRedirectingFactories] as we don't build them + // because we don't add them here. constructors: includeConstructors ? constructors : null); } } diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart new file mode 100644 index 00000000000..12cd3816df2 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart @@ -0,0 +1,7 @@ +// 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. + +extension Foo on String { + factory Foo({ this.fooX }) = Foobar; +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.expect new file mode 100644 index 00000000000..c426da08db2 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.expect @@ -0,0 +1,14 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart:6:3: Error: Extensions can't declare constructors. +// Try removing the constructor declaration. +// factory Foo({ this.fooX }) = Foobar; +// ^^^^^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::String { +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.modular.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.modular.expect new file mode 100644 index 00000000000..c426da08db2 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.modular.expect @@ -0,0 +1,14 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart:6:3: Error: Extensions can't declare constructors. +// Try removing the constructor declaration. +// factory Foo({ this.fooX }) = Foobar; +// ^^^^^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::String { +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.outline.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.outline.expect new file mode 100644 index 00000000000..c426da08db2 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.outline.expect @@ -0,0 +1,14 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart:6:3: Error: Extensions can't declare constructors. +// Try removing the constructor declaration. +// factory Foo({ this.fooX }) = Foobar; +// ^^^^^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::String { +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.transformed.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.transformed.expect new file mode 100644 index 00000000000..c426da08db2 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.strong.transformed.expect @@ -0,0 +1,14 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart:6:3: Error: Extensions can't declare constructors. +// Try removing the constructor declaration. +// factory Foo({ this.fooX }) = Foobar; +// ^^^^^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::String { +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline.expect new file mode 100644 index 00000000000..fe43f4db413 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline.expect @@ -0,0 +1,3 @@ +extension Foo on String { + factory Foo({ this.fooX }) = Foobar; +} diff --git a/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..fe43f4db413 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_with_redirecting_factory.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +extension Foo on String { + factory Foo({ this.fooX }) = Foobar; +}