Skip to content

Fix unbound type reference in extension method problem #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/src/model/type_parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ class TypeParameter extends ModelElement {

@override
Map<String, CommentReferable> get referenceChildren {
return _referenceChildren ??= {
boundType.name: boundType,
};
if (_referenceChildren == null) {
_referenceChildren = {};
if (boundType != null) {
_referenceChildren[boundType.name] = boundType;
}
}
return _referenceChildren;
}

@override
Expand Down
13 changes: 12 additions & 1 deletion test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2257,13 +2257,19 @@ void main() {
Class TypeParameterThings,
TypeParameterThingsExtended,
TypeParameterThingsExtendedQ;
Field aName, aThing;
Extension UnboundTypeTargetExtension;
Field aName, aThing, doesNotCrash;
TypeParameter ATypeParam, BTypeParam, CTypeParam, DTypeParam, QTypeParam;
Method aMethod, aMethodExtended, aMethodExtendedQ;
Parameter aParam, anotherParam, typedParam;
ModelFunction aTopLevelTypeParameterFunction;

setUpAll(() {
UnboundTypeTargetExtension = fakeLibrary.extensions
.firstWhere((f) => f.name == 'UnboundTypeTargetExtension');
doesNotCrash = UnboundTypeTargetExtension.instanceFields
.firstWhere((f) => f.name == 'doesNotCrash');

aTopLevelTypeParameterFunction = fakeLibrary.functions
.firstWhere((f) => f.name == 'aTopLevelTypeParameterFunction');
// TODO(jcollins-g): dart-lang/dartdoc#2704, HTML and type parameters
Expand Down Expand Up @@ -2306,6 +2312,11 @@ void main() {
.firstWhere((p) => p.name == 'QTypeParam');
});

test('on extension targeting an unbound type', () {
expect(newLookup(UnboundTypeTargetExtension, 'doesNotCrash'),
equals(MatchingLinkResult(doesNotCrash)));
});

test('on inherited documentation', () {
expect(newLookup(aMethodExtended, 'ATypeParam'),
equals(MatchingLinkResult(ATypeParam)));
Expand Down
6 changes: 6 additions & 0 deletions testing/test_package/lib/fake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,12 @@ extension Leg on Megatron<String> {
bool get hasRightLeg => true;
}

/// Refer to [doesNotCrash] here.
extension UnboundTypeTargetExtension<T> on T {
/// We hope so!
bool get doesNotCrash => true;
}

class Megatron<T> {}

class SuperMegaTron<T extends String> extends Megatron<String> {}
Expand Down