Skip to content

Commit f1a6d1c

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Make LinkedElementFactory.getElementId() more strict.
Now we check for specific kinds of InstanceElement members, and require that we find the corresponding ID in a library outside the current cycle. Add a few tests to trigger corresponding paths. Change-Id: I0bcd7eb6ad3009e637b849017b4dfeac8308b21f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443904 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent a5502f9 commit f1a6d1c

File tree

2 files changed

+677
-30
lines changed

2 files changed

+677
-30
lines changed

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,15 @@ extension LinkedElementFactoryExtension on LinkedElementFactory {
370370
case MixinElement():
371371
topLevelItem = manifest.declaredMixins[topLevelName];
372372
case GetterElement():
373-
return manifest.declaredGetters[topLevelName]?.id;
373+
return manifest.declaredGetters[topLevelName]!.id;
374374
case SetterElement():
375-
return manifest.declaredSetters[topLevelName]?.id;
375+
return manifest.declaredSetters[topLevelName]!.id;
376376
case TopLevelFunctionElement():
377-
return manifest.declaredFunctions[topLevelName]?.id;
377+
return manifest.declaredFunctions[topLevelName]!.id;
378378
case TopLevelVariableElement():
379-
return manifest.declaredVariables[topLevelName]?.id;
379+
return manifest.declaredVariables[topLevelName]!.id;
380380
case TypeAliasElement():
381-
return manifest.declaredTypeAliases[topLevelName]?.id;
381+
return manifest.declaredTypeAliases[topLevelName]!.id;
382382
}
383383

384384
if (topLevelItem == null) {
@@ -392,17 +392,42 @@ extension LinkedElementFactoryExtension on LinkedElementFactory {
392392
return topLevelItem.id;
393393
}
394394

395-
// TODO(scheglov): When implementation is complete, cast unconditionally.
396-
if (topLevelItem is InterfaceItem) {
397-
var memberName = memberElement.lookupName!.asLookupName;
398-
if (element is ConstructorElement) {
399-
return topLevelItem.getConstructorId(memberName);
400-
}
401-
var methodId = topLevelItem.getInterfaceMethodId(memberName);
402-
// TODO(scheglov): When implementation is complete, null assert.
403-
return methodId;
395+
// If not top-level element, then a member in [InstanceElement].
396+
var memberName = memberElement.lookupName!.asLookupName;
397+
topLevelItem as InstanceItem;
398+
399+
switch (element) {
400+
case FieldElement():
401+
if (topLevelItem.getDeclaredFieldId(memberName) case var result?) {
402+
return result;
403+
}
404+
case GetterElement():
405+
if (topLevelItem.getDeclaredGetterId(memberName) case var result?) {
406+
return result;
407+
}
408+
case SetterElement():
409+
if (topLevelItem.getDeclaredSetterId(memberName) case var result?) {
410+
return result;
411+
}
412+
case MethodElement():
413+
if (topLevelItem.getDeclaredMethodId(memberName) case var result?) {
414+
return result;
415+
}
416+
}
417+
418+
// If we get here, the top-level container is not [ExtensionElement].
419+
// So, it must be [InterfaceElement].
420+
topLevelItem as InterfaceItem;
421+
422+
if (element is ConstructorElement) {
423+
return topLevelItem.getConstructorId(memberName)!;
404424
}
405425

406-
return null;
426+
// In rare cases the member is not declared by the element, but added
427+
// to the interface as a result of top-merge.
428+
return topLevelItem.getInterfaceMethodId(memberName) ??
429+
(throw '[runtimeType: ${element.runtimeType}]'
430+
'[topLevelName: $topLevelName]'
431+
'[memberName: $memberName]');
407432
}
408433
}

0 commit comments

Comments
 (0)