Skip to content

Correct invalid member linkage #2191

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 2 commits into from
Apr 24, 2020
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
12 changes: 8 additions & 4 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,14 @@ class _MarkdownCommentReference {
// [thing], a member of this class
_addCanonicalResult(modelElement, tryClass);
}
membersToCheck = (c.allModelElementsByNamePart[codeRefChompedParts.last] ??
<ModelElement>[])
.map(_convertConstructors);
membersToCheck.forEach((m) => _addCanonicalResult(m, tryClass));
if (codeRefChompedParts.length < 2 ||
codeRefChompedParts[codeRefChompedParts.length - 2] == c.name) {
membersToCheck =
(c.allModelElementsByNamePart[codeRefChompedParts.last] ??
<ModelElement>[])
.map(_convertConstructors);
membersToCheck.forEach((m) => _addCanonicalResult(m, tryClass));
}
results.remove(null);
if (results.isNotEmpty) return;
if (c.fullyQualifiedNameWithoutLibrary == codeRefChomped) {
Expand Down
17 changes: 17 additions & 0 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,23 @@ void main() {
});

group('Class edge cases', () {
test('Factories from unrelated classes are linked correctly', () {
Class A = packageGraph.localPublicLibraries
.firstWhere((l) => l.name == 'unrelated_factories')
.allClasses
.firstWhere((c) => c.name == 'A');
Constructor fromMap =
A.constructors.firstWhere((c) => c.name == 'A.fromMap');
expect(fromMap.documentationAsHtml,
contains(r'unrelated_factories/AB/AB.fromMap.html">AB.fromMap</a>'));
expect(fromMap.documentationAsHtml,
contains(r'A/A.fromMap.html">fromMap</a>'));
expect(fromMap.documentationAsHtml,
contains(r'unrelated_factories/AB-class.html">AB</a>'));
expect(fromMap.documentationAsHtml,
contains(r'unrelated_factories/A-class.html">A</a>'));
});

test('Inherit from private class across private library to public library',
() {
Class GadgetExtender = packageGraph.localPublicLibraries
Expand Down
2 changes: 1 addition & 1 deletion test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:path/path.dart' as path;
/// The number of public libraries in testing/test_package, minus 2 for
/// the excluded libraries listed in the initializers for _testPackageGraphMemo
/// and minus 1 for the <nodoc> tag in the 'excluded' library.
const int kTestPackagePublicLibraries = 16;
const int kTestPackagePublicLibraries = 17;

final RegExp quotables = RegExp(r'[ "\r\n\$]');
final RegExp observatoryPortRegexp =
Expand Down
12 changes: 12 additions & 0 deletions testing/test_package/lib/unrelated_factories.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class A {
/// A link to [AB.fromMap], [fromMap], and [AB] and [A].
factory A.fromMap(Map<String, dynamic> map) => A._A();

A._A();
}

class AB {
factory AB.fromMap(Map<String, dynamic> map) => AB._AB();

AB._AB();
}