From 98703700d991f2990950910069fe4ec33a9059dd Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 16 Aug 2021 10:18:29 -0700 Subject: [PATCH] Fix unbound type reference in extension method problem --- lib/src/model/type_parameter.dart | 10 +++++++--- test/end2end/model_test.dart | 13 ++++++++++++- testing/test_package/lib/fake.dart | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/src/model/type_parameter.dart b/lib/src/model/type_parameter.dart index f8843576fb..54056ed6e0 100644 --- a/lib/src/model/type_parameter.dart +++ b/lib/src/model/type_parameter.dart @@ -69,9 +69,13 @@ class TypeParameter extends ModelElement { @override Map get referenceChildren { - return _referenceChildren ??= { - boundType.name: boundType, - }; + if (_referenceChildren == null) { + _referenceChildren = {}; + if (boundType != null) { + _referenceChildren[boundType.name] = boundType; + } + } + return _referenceChildren; } @override diff --git a/test/end2end/model_test.dart b/test/end2end/model_test.dart index 5a64886e67..9959891cc5 100644 --- a/test/end2end/model_test.dart +++ b/test/end2end/model_test.dart @@ -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 @@ -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))); diff --git a/testing/test_package/lib/fake.dart b/testing/test_package/lib/fake.dart index 007b3196af..d6f62ae07a 100644 --- a/testing/test_package/lib/fake.dart +++ b/testing/test_package/lib/fake.dart @@ -1087,6 +1087,12 @@ extension Leg on Megatron { bool get hasRightLeg => true; } +/// Refer to [doesNotCrash] here. +extension UnboundTypeTargetExtension on T { + /// We hope so! + bool get doesNotCrash => true; +} + class Megatron {} class SuperMegaTron extends Megatron {}