Skip to content

Commit fbd49b4

Browse files
authored
Fix unbound type reference in extension method problem (#2741)
1 parent b73bedc commit fbd49b4

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/src/model/type_parameter.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ class TypeParameter extends ModelElement {
6969

7070
@override
7171
Map<String, CommentReferable> get referenceChildren {
72-
return _referenceChildren ??= {
73-
boundType.name: boundType,
74-
};
72+
if (_referenceChildren == null) {
73+
_referenceChildren = {};
74+
if (boundType != null) {
75+
_referenceChildren[boundType.name] = boundType;
76+
}
77+
}
78+
return _referenceChildren;
7579
}
7680

7781
@override

test/end2end/model_test.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,19 @@ void main() {
22572257
Class TypeParameterThings,
22582258
TypeParameterThingsExtended,
22592259
TypeParameterThingsExtendedQ;
2260-
Field aName, aThing;
2260+
Extension UnboundTypeTargetExtension;
2261+
Field aName, aThing, doesNotCrash;
22612262
TypeParameter ATypeParam, BTypeParam, CTypeParam, DTypeParam, QTypeParam;
22622263
Method aMethod, aMethodExtended, aMethodExtendedQ;
22632264
Parameter aParam, anotherParam, typedParam;
22642265
ModelFunction aTopLevelTypeParameterFunction;
22652266

22662267
setUpAll(() {
2268+
UnboundTypeTargetExtension = fakeLibrary.extensions
2269+
.firstWhere((f) => f.name == 'UnboundTypeTargetExtension');
2270+
doesNotCrash = UnboundTypeTargetExtension.instanceFields
2271+
.firstWhere((f) => f.name == 'doesNotCrash');
2272+
22672273
aTopLevelTypeParameterFunction = fakeLibrary.functions
22682274
.firstWhere((f) => f.name == 'aTopLevelTypeParameterFunction');
22692275
// TODO(jcollins-g): dart-lang/dartdoc#2704, HTML and type parameters
@@ -2306,6 +2312,11 @@ void main() {
23062312
.firstWhere((p) => p.name == 'QTypeParam');
23072313
});
23082314

2315+
test('on extension targeting an unbound type', () {
2316+
expect(newLookup(UnboundTypeTargetExtension, 'doesNotCrash'),
2317+
equals(MatchingLinkResult(doesNotCrash)));
2318+
});
2319+
23092320
test('on inherited documentation', () {
23102321
expect(newLookup(aMethodExtended, 'ATypeParam'),
23112322
equals(MatchingLinkResult(ATypeParam)));

testing/test_package/lib/fake.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,12 @@ extension Leg on Megatron<String> {
10871087
bool get hasRightLeg => true;
10881088
}
10891089

1090+
/// Refer to [doesNotCrash] here.
1091+
extension UnboundTypeTargetExtension<T> on T {
1092+
/// We hope so!
1093+
bool get doesNotCrash => true;
1094+
}
1095+
10901096
class Megatron<T> {}
10911097

10921098
class SuperMegaTron<T extends String> extends Megatron<String> {}

0 commit comments

Comments
 (0)