[CFE] Skip processing of redirecting factories inside extensions as it will crash the compiler

Change-Id: I58b8cc2e62bd182bfb5c5a6a5efb33297c7dd5a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395520
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Jens Johansen
2024-11-18 09:40:57 +00:00
committed by Commit Queue
parent 31e324bfdf
commit 54b3ca9ea0
9 changed files with 80 additions and 0 deletions
@@ -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);
}
@@ -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);
}
}
@@ -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;
}
@@ -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 {
}
@@ -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 {
}
@@ -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 {
}
@@ -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 {
}
@@ -0,0 +1,3 @@
extension Foo on String {
factory Foo({ this.fooX }) = Foobar;
}
@@ -0,0 +1,3 @@
extension Foo on String {
factory Foo({ this.fooX }) = Foobar;
}