Skip to content

Commit 9625d07

Browse files
authored
Correct invalid member linkage (#2191)
* First pass at repro attempt * Fix bug and add test
1 parent 3cba934 commit 9625d07

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

lib/src/markdown_processor.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,14 @@ class _MarkdownCommentReference {
744744
// [thing], a member of this class
745745
_addCanonicalResult(modelElement, tryClass);
746746
}
747-
membersToCheck = (c.allModelElementsByNamePart[codeRefChompedParts.last] ??
748-
<ModelElement>[])
749-
.map(_convertConstructors);
750-
membersToCheck.forEach((m) => _addCanonicalResult(m, tryClass));
747+
if (codeRefChompedParts.length < 2 ||
748+
codeRefChompedParts[codeRefChompedParts.length - 2] == c.name) {
749+
membersToCheck =
750+
(c.allModelElementsByNamePart[codeRefChompedParts.last] ??
751+
<ModelElement>[])
752+
.map(_convertConstructors);
753+
membersToCheck.forEach((m) => _addCanonicalResult(m, tryClass));
754+
}
751755
results.remove(null);
752756
if (results.isNotEmpty) return;
753757
if (c.fullyQualifiedNameWithoutLibrary == codeRefChomped) {

test/model_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,23 @@ void main() {
13891389
});
13901390

13911391
group('Class edge cases', () {
1392+
test('Factories from unrelated classes are linked correctly', () {
1393+
Class A = packageGraph.localPublicLibraries
1394+
.firstWhere((l) => l.name == 'unrelated_factories')
1395+
.allClasses
1396+
.firstWhere((c) => c.name == 'A');
1397+
Constructor fromMap =
1398+
A.constructors.firstWhere((c) => c.name == 'A.fromMap');
1399+
expect(fromMap.documentationAsHtml,
1400+
contains(r'unrelated_factories/AB/AB.fromMap.html">AB.fromMap</a>'));
1401+
expect(fromMap.documentationAsHtml,
1402+
contains(r'A/A.fromMap.html">fromMap</a>'));
1403+
expect(fromMap.documentationAsHtml,
1404+
contains(r'unrelated_factories/AB-class.html">AB</a>'));
1405+
expect(fromMap.documentationAsHtml,
1406+
contains(r'unrelated_factories/A-class.html">A</a>'));
1407+
});
1408+
13921409
test('Inherit from private class across private library to public library',
13931410
() {
13941411
Class GadgetExtender = packageGraph.localPublicLibraries

test/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:path/path.dart' as path;
1717
/// The number of public libraries in testing/test_package, minus 2 for
1818
/// the excluded libraries listed in the initializers for _testPackageGraphMemo
1919
/// and minus 1 for the <nodoc> tag in the 'excluded' library.
20-
const int kTestPackagePublicLibraries = 16;
20+
const int kTestPackagePublicLibraries = 17;
2121

2222
final RegExp quotables = RegExp(r'[ "\r\n\$]');
2323
final RegExp observatoryPortRegexp =
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class A {
2+
/// A link to [AB.fromMap], [fromMap], and [AB] and [A].
3+
factory A.fromMap(Map<String, dynamic> map) => A._A();
4+
5+
A._A();
6+
}
7+
8+
class AB {
9+
factory AB.fromMap(Map<String, dynamic> map) => AB._AB();
10+
11+
AB._AB();
12+
}

0 commit comments

Comments
 (0)