Skip to content

Commit 69a5970

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Use InterfaceTypeImpl.getNamedConstructor(), avoid all constructors dependency.
Not ideal, though. For linking elements this helps, but during resolution when we check for presence of generative constructors we still ask all constructors of the superclass. Change-Id: Ia642d6aa5ba40b23bfc1d9c37d5925da6bf7d708 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444385 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 865ccd3 commit 69a5970

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,13 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
908908
return getMethod(methodName);
909909
}
910910

911+
InternalConstructorElement? getNamedConstructor(String name) {
912+
var base = element.getNamedConstructor(name);
913+
return base != null
914+
? SubstitutedConstructorElementImpl.from2(base, this)
915+
: null;
916+
}
917+
911918
@override
912919
InternalSetterElement? getSetter(String setterName) {
913920
var element = this.element.getSetter(setterName);

pkg/analyzer/lib/src/summary2/super_constructor_resolver.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,17 @@ class SuperConstructorResolver {
4747
} else if (initializer is SuperConstructorInvocation) {
4848
invokesDefaultSuperConstructor = false;
4949
var name = initializer.constructorName?.name ?? 'new';
50-
element.superConstructor =
51-
classElement.supertype?.constructors
52-
.where((element) => element.name == name)
53-
.firstOrNull;
50+
element.superConstructor = classElement.supertype
51+
?.getNamedConstructor(name);
5452
}
5553
}
5654
}
5755
}
5856

5957
if (invokesDefaultSuperConstructor) {
60-
element.superConstructor =
61-
classElement.supertype?.constructors
62-
.where((element) => element.name == 'new')
63-
.firstOrNull;
58+
element.superConstructor = classElement.supertype?.getNamedConstructor(
59+
'new',
60+
);
6461
}
6562
}
6663
}

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5760,7 +5760,8 @@ class B extends A {}
57605760
package:test/a.dart
57615761
A
57625762
interfaceId: #M3
5763-
allDeclaredConstructors: #M7
5763+
constructors
5764+
new: #M7
57645765
[status] idle
57655766
''',
57665767
updatedA: r'''
@@ -5820,7 +5821,8 @@ class A {
58205821
package:test/a.dart
58215822
A
58225823
interfaceId: #M10
5823-
allDeclaredConstructors: #M7
5824+
constructors
5825+
new: #M7
58245826
[status] idle
58255827
''',
58265828
);
@@ -6022,7 +6024,8 @@ class B extends A {}
60226024
package:test/a.dart
60236025
A
60246026
interfaceId: #M4
6025-
allDeclaredConstructors: #M8
6027+
constructors
6028+
new: #M8
60266029
[operation] analyzeFile
60276030
file: /home/test/lib/test.dart
60286031
library: /home/test/lib/test.dart
@@ -6105,7 +6108,8 @@ class A {
61056108
package:test/a.dart
61066109
A
61076110
interfaceId: #M11
6108-
allDeclaredConstructors: #M8
6111+
constructors
6112+
new: #M8
61096113
[operation] getErrorsCannotReuse
61106114
instanceFieldIdMismatch
61116115
libraryUri: package:test/a.dart
@@ -7438,7 +7442,8 @@ class B extends A {}
74387442
package:test/a.dart
74397443
A
74407444
interfaceId: #M2
7441-
allDeclaredConstructors: #M5
7445+
constructors
7446+
new: #M5
74427447
[status] idle
74437448
''',
74447449
updatedA: r'''
@@ -7492,7 +7497,8 @@ class A {
74927497
package:test/a.dart
74937498
A
74947499
interfaceId: #M7
7495-
allDeclaredConstructors: #M5
7500+
constructors
7501+
new: #M5
74967502
[status] idle
74977503
''',
74987504
);
@@ -7797,7 +7803,8 @@ class B extends A {}
77977803
package:test/a.dart
77987804
A
77997805
interfaceId: #M3
7800-
allDeclaredConstructors: #M6
7806+
constructors
7807+
new: #M6
78017808
[operation] analyzeFile
78027809
file: /home/test/lib/test.dart
78037810
library: /home/test/lib/test.dart
@@ -7873,7 +7880,8 @@ class A {
78737880
package:test/a.dart
78747881
A
78757882
interfaceId: #M8
7876-
allDeclaredConstructors: #M6
7883+
constructors
7884+
new: #M6
78777885
[operation] getErrorsCannotReuse
78787886
instanceChildrenIdsMismatch
78797887
libraryUri: package:test/a.dart
@@ -7977,7 +7985,8 @@ class X extends C {}
79777985
package:test/a.dart
79787986
C
79797987
interfaceId: #M7
7980-
allDeclaredConstructors: #M11
7988+
constructors
7989+
new: #M11
79817990
[operation] analyzeFile
79827991
file: /home/test/lib/test.dart
79837992
library: /home/test/lib/test.dart
@@ -8071,7 +8080,8 @@ class C extends A implements B {}
80718080
package:test/a.dart
80728081
C
80738082
interfaceId: #M14
8074-
allDeclaredConstructors: #M11
8083+
constructors
8084+
new: #M11
80758085
[operation] getErrorsCannotReuse
80768086
instanceChildrenIdsMismatch
80778087
libraryUri: package:test/a.dart
@@ -13071,7 +13081,6 @@ class B extends A {
1307113081
package:test/a.dart
1307213082
A
1307313083
interfaceId: #M2
13074-
allDeclaredConstructors: #M1
1307513084
constructors
1307613085
named: #M1
1307713086
[operation] analyzeFile
@@ -13122,12 +13131,12 @@ class A {
1312213131
uri: package:test/test.dart
1312313132
flags: isLibrary
1312413133
[operation] cannotReuseLinkedBundle
13125-
interfaceChildrenIdsMismatch
13134+
interfaceConstructorIdMismatch
1312613135
libraryUri: package:test/a.dart
1312713136
interfaceName: A
13128-
childrenPropertyName: constructors
13129-
expectedIds: #M1
13130-
actualIds: #M7
13137+
constructorName: named
13138+
expectedId: #M1
13139+
actualId: #M7
1313113140
[operation] linkLibraryCycle
1313213141
package:test/test.dart
1313313142
declaredClasses
@@ -13147,7 +13156,6 @@ class A {
1314713156
package:test/a.dart
1314813157
A
1314913158
interfaceId: #M2
13150-
allDeclaredConstructors: #M7
1315113159
constructors
1315213160
named: #M7
1315313161
[operation] getErrorsCannotReuse

0 commit comments

Comments
 (0)