Skip to content

Commit 19e9113

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Fine. Fix for requirements on instance/interface elements with missing names.
Change-Id: Ide320ccc1bd146aba60a0d2bced405fc2612a027 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430880 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 2545c3e commit 19e9113

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

pkg/analyzer/lib/src/fine/requirements.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,10 @@ class RequirementsManifest {
882882
return null;
883883
}
884884

885-
// SAFETY: we don't export elements without name.
886-
var instanceName = element.lookupName!.asLookupName;
885+
var instanceName = element.lookupName?.asLookupName;
886+
if (instanceName == null) {
887+
return null;
888+
}
887889

888890
var instancesMap = instances[libraryElement.uri] ??= {};
889891
var instanceItem =
@@ -916,8 +918,10 @@ class RequirementsManifest {
916918
return null;
917919
}
918920

919-
// SAFETY: we don't export elements without name.
920-
var interfaceName = element.lookupName!.asLookupName;
921+
var interfaceName = element.lookupName?.asLookupName;
922+
if (interfaceName == null) {
923+
return null;
924+
}
921925

922926
var interfacesMap = interfaces[libraryElement.uri] ??= {};
923927
var interfaceItem =

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44373,6 +44373,64 @@ int get b => 0;
4437344373
);
4437444374
}
4437544375

44376+
test_req_classElement_noName() async {
44377+
newFile(testFile.path, r'''
44378+
class {}
44379+
''');
44380+
44381+
_ManualRequirements.install((state) {
44382+
var e = state.singleUnit.libraryElement.classes.single;
44383+
e.getNamedConstructor2('foo');
44384+
});
44385+
44386+
await _runManualRequirementsRecording(
44387+
expectedEvents: r'''
44388+
[status] working
44389+
[operation] linkLibraryCycle SDK
44390+
[operation] linkLibraryCycle
44391+
package:test/test.dart
44392+
requirements
44393+
[operation] analyzedLibrary
44394+
file: /home/test/lib/test.dart
44395+
requirements
44396+
[status] idle
44397+
''',
44398+
);
44399+
}
44400+
44401+
test_req_extensionElement_noName() async {
44402+
newFile(testFile.path, r'''
44403+
extension on int {
44404+
void foo() {}
44405+
}
44406+
''');
44407+
44408+
_ManualRequirements.install((state) {
44409+
var e = state.singleUnit.libraryElement.extensions.single;
44410+
e.getMethod('foo');
44411+
});
44412+
44413+
await _runManualRequirementsRecording(
44414+
expectedEvents: r'''
44415+
[status] working
44416+
[operation] linkLibraryCycle SDK
44417+
[operation] linkLibraryCycle
44418+
package:test/test.dart
44419+
requirements
44420+
topLevels
44421+
dart:core
44422+
int: #M0
44423+
[operation] analyzedLibrary
44424+
file: /home/test/lib/test.dart
44425+
requirements
44426+
topLevels
44427+
dart:core
44428+
int: #M0
44429+
[status] idle
44430+
''',
44431+
);
44432+
}
44433+
4437644434
test_req_instanceElement_getField() async {
4437744435
newFile('$testPackageLibPath/a.dart', r'''
4437844436
class A {
@@ -45197,6 +45255,10 @@ class _ManualRequirementsUnit {
4519745255

4519845256
_ManualRequirementsUnit(this.unit);
4519945257

45258+
LibraryElementImpl get libraryElement {
45259+
return libraryFragment.element;
45260+
}
45261+
4520045262
LibraryFragmentImpl get libraryFragment {
4520145263
return unit.declaredFragment!;
4520245264
}

0 commit comments

Comments
 (0)