Skip to content

Commit b2c7d08

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Update name of private forwarding constructor tear-offs
This updates the synthesized name of the private forwarding constructor tear-offs to use the library of the target constructor instead of the library of the mixin application. Change-Id: I2a5fb62f2c572bb02db177e5bda5e222cc5818f8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434720 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
1 parent f1387e6 commit b2c7d08

17 files changed

+1200
-1
lines changed

pkg/front_end/lib/src/kernel/kernel_target.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,10 @@ class KernelTarget {
10391039
}
10401040

10411041
Procedure? constructorTearOff = createConstructorTearOffProcedure(
1042-
new MemberName(libraryBuilder.libraryName,
1042+
new MemberName(
1043+
superConstructor.name.isPrivate
1044+
? new LibraryName(superConstructor.name.libraryReference!)
1045+
: libraryBuilder.libraryName,
10431046
constructorTearOffName(superConstructor.name.text)),
10441047
libraryBuilder,
10451048
cls.fileUri,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2025, 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+
import 'private_lib.dart';
6+
7+
mixin M {}
8+
9+
class D = A with M;
10+
11+
class E = B with M; // TODO(johnniwinther): This should not be an error.
12+
13+
class F = C with M;
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private.dart:11:7: Error: The superclass, 'B', has no unnamed constructor that takes no arguments.
6+
// class E = B with M; // TODO(johnniwinther): This should not be an error.
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
import "private_lib.dart" as pri;
12+
13+
import "org-dartlang-testcase:///private_lib.dart";
14+
15+
abstract class M extends core::Object /*isMixinDeclaration*/ {
16+
}
17+
class D = pri::A with self::M {
18+
synthetic constructor pri::_() → self::D
19+
: super pri::A::_()
20+
;
21+
static synthetic method pri::_#_#tearOff() → self::D
22+
return new self::D::_();
23+
}
24+
class E = pri::B with self::M {
25+
synthetic constructor •() → self::E
26+
: invalid-initializer
27+
;
28+
static synthetic method _#new#tearOff() → self::E
29+
return new self::E::•();
30+
}
31+
class F = pri::C with self::M {
32+
synthetic constructor named() → self::F
33+
: super pri::C::named()
34+
;
35+
synthetic constructor pri::_() → self::F
36+
: super pri::C::_()
37+
;
38+
static synthetic method _#named#tearOff() → self::F
39+
return new self::F::named();
40+
static synthetic method pri::_#_#tearOff() → self::F
41+
return new self::F::_();
42+
}
43+
44+
library;
45+
//
46+
// Problems in library:
47+
//
48+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:27:11: Error: Superclass has no constructor named 'B._'.
49+
// H._() : super._(); // Error
50+
// ^^^^^
51+
//
52+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:36:5: Error: Member not found: 'D._'.
53+
// D._(); // Error
54+
// ^
55+
//
56+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:37:5: Error: Member not found: '_'.
57+
// D._; // Error
58+
// ^
59+
//
60+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:38:5: Error: Member not found: 'E._'.
61+
// E._(); // Error
62+
// ^
63+
//
64+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:39:5: Error: Member not found: '_'.
65+
// E._; // Error
66+
// ^
67+
//
68+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:40:5: Error: Member not found: 'F._'.
69+
// F._(); // Error
70+
// ^
71+
//
72+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:41:5: Error: Member not found: '_'.
73+
// F._; // Error
74+
// ^
75+
//
76+
import self as pri;
77+
import "dart:core" as core;
78+
import "private.dart" as self;
79+
80+
import "org-dartlang-testcase:///private.dart";
81+
82+
class A extends core::Object {
83+
constructor _() → pri::A
84+
: super core::Object::•()
85+
;
86+
static synthetic method _#_#tearOff() → pri::A
87+
return new pri::A::_();
88+
}
89+
class B extends core::Object {
90+
static factory _() → pri::B /* redirection-target: pri::_B::• */
91+
return new pri::_B::•();
92+
static synthetic method _#_#tearOff() → pri::B
93+
return new pri::_B::•();
94+
}
95+
class _B extends core::Object implements pri::B {
96+
synthetic constructor •() → pri::_B
97+
: super core::Object::•()
98+
;
99+
static synthetic method _#new#tearOff() → pri::_B
100+
return new pri::_B::•();
101+
}
102+
class C extends core::Object {
103+
constructor named() → pri::C
104+
: super core::Object::•()
105+
;
106+
constructor _() → pri::C
107+
: super core::Object::•()
108+
;
109+
static synthetic method _#named#tearOff() → pri::C
110+
return new pri::C::named();
111+
static synthetic method _#_#tearOff() → pri::C
112+
return new pri::C::_();
113+
}
114+
class G extends self::D {
115+
constructor _() → pri::G
116+
: super self::D::_()
117+
;
118+
static synthetic method _#_#tearOff() → pri::G
119+
return new pri::G::_();
120+
}
121+
class H extends self::E {
122+
constructor _() → pri::H
123+
: final dynamic #t1 = invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:27:11: Error: Superclass has no constructor named 'B._'.
124+
H._() : super._(); // Error
125+
^^^^^"
126+
;
127+
static synthetic method _#_#tearOff() → pri::H
128+
return new pri::H::_();
129+
}
130+
class I extends self::F {
131+
constructor named() → pri::I
132+
: super self::F::named()
133+
;
134+
constructor _() → pri::I
135+
: super self::F::_()
136+
;
137+
static synthetic method _#named#tearOff() → pri::I
138+
return new pri::I::named();
139+
static synthetic method _#_#tearOff() → pri::I
140+
return new pri::I::_();
141+
}
142+
static method method() → dynamic {
143+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:36:5: Error: Member not found: 'D._'.
144+
D._(); // Error
145+
^";
146+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:37:5: Error: Member not found: '_'.
147+
D._; // Error
148+
^";
149+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:38:5: Error: Member not found: 'E._'.
150+
E._(); // Error
151+
^";
152+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:39:5: Error: Member not found: '_'.
153+
E._; // Error
154+
^";
155+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:40:5: Error: Member not found: 'F._'.
156+
F._(); // Error
157+
^";
158+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:41:5: Error: Member not found: '_'.
159+
F._; // Error
160+
^";
161+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private.dart:11:7: Error: The superclass, 'B', has no unnamed constructor that takes no arguments.
6+
// class E = B with M; // TODO(johnniwinther): This should not be an error.
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
import "private_lib.dart" as pri;
12+
13+
import "org-dartlang-testcase:///private_lib.dart";
14+
15+
abstract class M extends core::Object /*isMixinDeclaration*/ {
16+
}
17+
class D = pri::A with self::M {
18+
synthetic constructor pri::_() → self::D
19+
: super pri::A::_()
20+
;
21+
static synthetic method pri::_#_#tearOff() → self::D
22+
return new self::D::_();
23+
}
24+
class E = pri::B with self::M {
25+
synthetic constructor •() → self::E
26+
: invalid-initializer
27+
;
28+
static synthetic method _#new#tearOff() → self::E
29+
return new self::E::•();
30+
}
31+
class F = pri::C with self::M {
32+
synthetic constructor named() → self::F
33+
: super pri::C::named()
34+
;
35+
synthetic constructor pri::_() → self::F
36+
: super pri::C::_()
37+
;
38+
static synthetic method _#named#tearOff() → self::F
39+
return new self::F::named();
40+
static synthetic method pri::_#_#tearOff() → self::F
41+
return new self::F::_();
42+
}
43+
44+
library;
45+
//
46+
// Problems in library:
47+
//
48+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:27:11: Error: Superclass has no constructor named 'B._'.
49+
// H._() : super._(); // Error
50+
// ^^^^^
51+
//
52+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:36:5: Error: Member not found: 'D._'.
53+
// D._(); // Error
54+
// ^
55+
//
56+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:37:5: Error: Member not found: '_'.
57+
// D._; // Error
58+
// ^
59+
//
60+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:38:5: Error: Member not found: 'E._'.
61+
// E._(); // Error
62+
// ^
63+
//
64+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:39:5: Error: Member not found: '_'.
65+
// E._; // Error
66+
// ^
67+
//
68+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:40:5: Error: Member not found: 'F._'.
69+
// F._(); // Error
70+
// ^
71+
//
72+
// pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:41:5: Error: Member not found: '_'.
73+
// F._; // Error
74+
// ^
75+
//
76+
import self as pri;
77+
import "dart:core" as core;
78+
import "private.dart" as self;
79+
80+
import "org-dartlang-testcase:///private.dart";
81+
82+
class A extends core::Object {
83+
constructor _() → pri::A
84+
: super core::Object::•()
85+
;
86+
static synthetic method _#_#tearOff() → pri::A
87+
return new pri::A::_();
88+
}
89+
class B extends core::Object {
90+
static factory _() → pri::B /* redirection-target: pri::_B::• */
91+
return new pri::_B::•();
92+
static synthetic method _#_#tearOff() → pri::B
93+
return new pri::_B::•();
94+
}
95+
class _B extends core::Object implements pri::B {
96+
synthetic constructor •() → pri::_B
97+
: super core::Object::•()
98+
;
99+
static synthetic method _#new#tearOff() → pri::_B
100+
return new pri::_B::•();
101+
}
102+
class C extends core::Object {
103+
constructor named() → pri::C
104+
: super core::Object::•()
105+
;
106+
constructor _() → pri::C
107+
: super core::Object::•()
108+
;
109+
static synthetic method _#named#tearOff() → pri::C
110+
return new pri::C::named();
111+
static synthetic method _#_#tearOff() → pri::C
112+
return new pri::C::_();
113+
}
114+
class G extends self::D {
115+
constructor _() → pri::G
116+
: super self::D::_()
117+
;
118+
static synthetic method _#_#tearOff() → pri::G
119+
return new pri::G::_();
120+
}
121+
class H extends self::E {
122+
constructor _() → pri::H
123+
: final dynamic #t1 = invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:27:11: Error: Superclass has no constructor named 'B._'.
124+
H._() : super._(); // Error
125+
^^^^^"
126+
;
127+
static synthetic method _#_#tearOff() → pri::H
128+
return new pri::H::_();
129+
}
130+
class I extends self::F {
131+
constructor named() → pri::I
132+
: super self::F::named()
133+
;
134+
constructor _() → pri::I
135+
: super self::F::_()
136+
;
137+
static synthetic method _#named#tearOff() → pri::I
138+
return new pri::I::named();
139+
static synthetic method _#_#tearOff() → pri::I
140+
return new pri::I::_();
141+
}
142+
static method method() → dynamic {
143+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:36:5: Error: Member not found: 'D._'.
144+
D._(); // Error
145+
^";
146+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:37:5: Error: Member not found: '_'.
147+
D._; // Error
148+
^";
149+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:38:5: Error: Member not found: 'E._'.
150+
E._(); // Error
151+
^";
152+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:39:5: Error: Member not found: '_'.
153+
E._; // Error
154+
^";
155+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:40:5: Error: Member not found: 'F._'.
156+
F._(); // Error
157+
^";
158+
invalid-expression "pkg/front_end/testcases/constructor_tearoffs/lowering/private_lib.dart:41:5: Error: Member not found: '_'.
159+
F._; // Error
160+
^";
161+
}

0 commit comments

Comments
 (0)