Skip to content

Commit af1a31d

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Skip addSuperParameterDefaultValueCloners when the constructor has no super initializing formals
Initializers are created for outlines for const constructors and for constructors with super initializing formals. This led the addSuperParameterDefaultValueCloners method to process the initializers even when the constructor has no super initializing formals; crashing in the case of const redirecting generative constructors. The addSuperParameterDefaultValueCloners method now stops early if the constructor has no super initializing formals. Change-Id: I2d640b20ac3fb281705b61362157e1fd09eed3f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490081 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
1 parent 618d608 commit af1a31d

8 files changed

Lines changed: 100 additions & 0 deletions

pkg/front_end/lib/src/fragment/constructor/declaration.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ mixin _ConstructorDeclarationMixin
475475
} else if (lastInitializer is InternalSuperInitializer) {
476476
superTarget = lastInitializer.target;
477477
} else if (lastInitializer is InvalidInitializer &&
478+
// Coverage-ignore(suite): Not run.
478479
lastInitializer.isSuperInitializer) {
479480
// Erroneous super initializer.
480481
return null;
@@ -529,6 +530,8 @@ mixin _ConstructorDeclarationMixin
529530
DeclarationBuilder declarationBuilder,
530531
List<DelayedDefaultValueCloner> delayedDefaultValueCloners,
531532
) {
533+
if (!_hasSuperInitializingFormals) return;
534+
532535
if (_beginInitializers != null && initializers.isNotEmpty) {
533536
// If the initializers aren't built yet, we can't compute the super
534537
// target. The synthetic initializers should be excluded, since they can
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class A {
6+
const A.named();
7+
}
8+
9+
class B extends A {
10+
const B() : super.named();
11+
12+
const B.named() : this();
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
const constructor named() → self::A
7+
: super core::Object::•()
8+
;
9+
}
10+
class B extends self::A /*hasConstConstructor*/ {
11+
const constructor •() → self::B
12+
: super self::A::named()
13+
;
14+
const constructor named() → self::B
15+
: this self::B::•()
16+
;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
const constructor named() → self::A
7+
: super core::Object::•()
8+
;
9+
}
10+
class B extends self::A /*hasConstConstructor*/ {
11+
const constructor •() → self::B
12+
: super self::A::named()
13+
;
14+
const constructor named() → self::B
15+
: this self::B::•()
16+
;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
const constructor named() → self::A
7+
: super core::Object::•()
8+
;
9+
}
10+
class B extends self::A /*hasConstConstructor*/ {
11+
const constructor •() → self::B
12+
: super self::A::named()
13+
;
14+
const constructor named() → self::B
15+
: this self::B::•()
16+
;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
const constructor named() → self::A
7+
: super core::Object::•()
8+
;
9+
}
10+
class B extends self::A /*hasConstConstructor*/ {
11+
const constructor •() → self::B
12+
: super self::A::named()
13+
;
14+
const constructor named() → self::B
15+
: this self::B::•()
16+
;
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
const A.named();
3+
}
4+
5+
class B extends A {
6+
const B() : super.named();
7+
const B.named() : this();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
const A.named();
3+
}
4+
5+
class B extends A {
6+
const B() : super.named();
7+
const B.named() : this();
8+
}

0 commit comments

Comments
 (0)