Skip to content

Commit 32559d3

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Analyzer: Do not forward factory constructors to mixin applications
Fixes #38306 Change-Id: I1424425ad6b04f1b611661cfca6ff5113b2cf0df Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150681 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 9f6510b commit 32559d3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ class ClassElementImpl extends AbstractClassElementImpl
993993
/// Compute a list of constructors for this class, which is a mixin
994994
/// application. If specified, [visitedClasses] is a list of the other mixin
995995
/// application classes which have been visited on the way to reaching this
996-
/// one (this is used to detect circularities).
996+
/// one (this is used to detect cycles).
997997
List<ConstructorElement> _computeMixinAppConstructors(
998998
[List<ClassElementImpl> visitedClasses]) {
999999
if (supertype == null) {
@@ -1012,7 +1012,8 @@ class ClassElementImpl extends AbstractClassElementImpl
10121012
if (!superElement.isMixinApplication) {
10131013
var library = this.library;
10141014
constructorsToForward = superElement.constructors
1015-
.where((constructor) => constructor.isAccessibleIn(library));
1015+
.where((constructor) => constructor.isAccessibleIn(library))
1016+
.where((constructor) => !constructor.isFactory);
10161017
} else {
10171018
if (visitedClasses == null) {
10181019
visitedClasses = <ClassElementImpl>[this];

pkg/analyzer/test/src/diagnostics/undefined_method_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,25 @@ f() { A?.m(); }
179179
''');
180180
}
181181

182+
test_static_mixinApplication_superConstructorIsFactory() async {
183+
await assertErrorsInCode(r'''
184+
mixin M {}
185+
186+
class A {
187+
A();
188+
factory A.named() = A;
189+
}
190+
191+
class B = A with M;
192+
193+
void main() {
194+
B.named();
195+
}
196+
''', [
197+
error(StaticTypeWarningCode.UNDEFINED_METHOD, 96, 5),
198+
]);
199+
}
200+
182201
test_withExtension() async {
183202
await assertErrorsInCode(r'''
184203
class C {}

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ class alias MixinApp extends Base with M {
308308
synthetic MixinApp.requiredArg(dynamic x) = Base.requiredArg;
309309
synthetic MixinApp.positionalArg([bool x = true]) = Base.positionalArg;
310310
synthetic MixinApp.namedArg({int x: 42}) = Base.namedArg;
311-
synthetic MixinApp.fact() = Base.fact;
312-
synthetic MixinApp.fact2() = Base.fact2;
313311
}
314312
''');
315313
}

0 commit comments

Comments
 (0)