Skip to content

Commit 3b47834

Browse files
authored
Instantiate enclosing elements for anonymous functions (#1841)
* Instantiate enclosing elements for anonymous functions, even when they're not directly attached to libraries * Add test * Update test package docs
1 parent 585f0aa commit 3b47834

File tree

242 files changed

+739
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+739
-3
lines changed

lib/src/model.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,8 +3877,8 @@ abstract class ModelElement extends Canonicalization
38773877
return fqName;
38783878
}
38793879

3880-
ModelElement parent = (e as EnclosedElement).enclosingElement;
3881-
return _buildFullyQualifiedName(parent, '${parent.name}.$fqName');
3880+
return _buildFullyQualifiedName(
3881+
e.enclosingElement, '${e.enclosingElement.name}.$fqName');
38823882
}
38833883

38843884
String _calculateLinkedName() {
@@ -4455,6 +4455,13 @@ class ModelFunctionAnonymous extends ModelFunctionTyped {
44554455
FunctionTypedElement element, PackageGraph packageGraph)
44564456
: super(element, null, packageGraph) {}
44574457

4458+
@override
4459+
ModelElement get enclosingElement {
4460+
// These are not considered to be a part of libraries, so we can simply
4461+
// blindly instantiate a ModelElement for their enclosing element.
4462+
return new ModelElement.fromElement(element.enclosingElement, packageGraph);
4463+
}
4464+
44584465
@override
44594466
String get name => 'Function';
44604467

@@ -6040,7 +6047,9 @@ class Package extends LibraryContainer
60406047

60416048
/// Is this the package at the top of the list? We display the first
60426049
/// package specially (with "Libraries" rather than the package name).
6043-
bool get isFirstPackage => packageGraph.localPackages.isNotEmpty && identical(packageGraph.localPackages.first, this);
6050+
bool get isFirstPackage =>
6051+
packageGraph.localPackages.isNotEmpty &&
6052+
identical(packageGraph.localPackages.first, this);
60446053

60456054
@override
60466055
bool get isSdk => packageMeta.isSdk;

test/model_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
32083208
paramFromExportLib,
32093209
methodWithTypedefParam,
32103210
applyCovariantParams;
3211+
ModelFunction doAComplicatedThing;
32113212
Parameter intNumber, intCheckOptional;
32123213

32133214
setUpAll(() {
@@ -3231,6 +3232,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
32313232
.singleWhere((m) => m.name == 'methodWithGenericParam');
32323233
methodWithTypedefParam = c.instanceMethods
32333234
.singleWhere((m) => m.name == 'methodWithTypedefParam');
3235+
doAComplicatedThing = fakeLibrary.publicFunctions
3236+
.firstWhere((m) => m.name == 'doAComplicatedThing');
32343237
});
32353238

32363239
test('covariant parameters render correctly', () {
@@ -3239,6 +3242,13 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
32393242
contains('<span>covariant</span>'));
32403243
});
32413244

3245+
test(
3246+
'ambiguous reference to function parameter parameters resolves to nothing',
3247+
() {
3248+
expect(doAComplicatedThing.documentationAsHtml,
3249+
contains('<code>aThingParameter</code>'));
3250+
});
3251+
32423252
test('has parameters', () {
32433253
expect(isGreaterThan.parameters, hasLength(2));
32443254
});

testing/test_package/lib/fake.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ class HasGenerics<X, Y, Z> {
9797
Map<X, Y> convertToMap() => null;
9898
}
9999

100+
/// Coderef to ambiguous parameter of function parameter should not crash us.
101+
/// (#1835)
102+
///
103+
/// Here is a coderef: [aThingParameter]
104+
void doAComplicatedThing(int x,
105+
{void doSomething(int aThingParameter, String anotherThing),
106+
void doSomethingElse(int aThingParameter, double somethingElse)}) {}
107+
100108
/// Bullet point documentation.
101109
///
102110
/// This top level constant has bullet points.

testing/test_package_docs/fake/ABaseClass-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassUsingASuperMixin-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassUsingNewStyleMixin-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassWithFancyProperties-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AMixinCallingSuper-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/ATypeTakingClass-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/ATypeTakingClassMixedIn-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)