Skip to content

Commit 2195fe3

Browse files
committed
Don't create artificial PrefixedIdentifierImpl to check for ignored undefined.
Change-Id: I8ef06680b4d87ba017abeb5b3a70999eed25fca0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155920 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 8de8a1c commit 2195fe3

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class MethodInvocationResolver {
9797
if (receiver is SimpleIdentifier) {
9898
var receiverElement = receiver.staticElement;
9999
if (receiverElement is PrefixElement) {
100-
_resolveReceiverPrefix(node, receiver, receiverElement, nameNode, name);
100+
_resolveReceiverPrefix(node, receiverElement, nameNode, name);
101101
return;
102102
}
103103
}
@@ -236,11 +236,13 @@ class MethodInvocationResolver {
236236
}
237237

238238
void _reportUndefinedFunction(
239-
MethodInvocation node, Identifier ignorableIdentifier) {
239+
MethodInvocation node, {
240+
@required String prefix,
241+
@required String name,
242+
}) {
240243
_setDynamicResolution(node);
241244

242-
// TODO(scheglov) This is duplication.
243-
if (nameScope.shouldIgnoreUndefined(ignorableIdentifier)) {
245+
if (nameScope.shouldIgnoreUndefined2(prefix: prefix, name: name)) {
244246
return;
245247
}
246248

@@ -513,7 +515,11 @@ class MethodInvocationResolver {
513515
} else if (_resolver.enclosingExtension != null) {
514516
receiverType = _resolver.enclosingExtension.extendedType;
515517
} else {
516-
return _reportUndefinedFunction(node, node.methodName);
518+
return _reportUndefinedFunction(
519+
node,
520+
prefix: null,
521+
name: node.methodName.name,
522+
);
517523
}
518524

519525
_resolveReceiverType(
@@ -526,8 +532,8 @@ class MethodInvocationResolver {
526532
);
527533
}
528534

529-
void _resolveReceiverPrefix(MethodInvocation node, SimpleIdentifier receiver,
530-
PrefixElement prefix, SimpleIdentifier nameNode, String name) {
535+
void _resolveReceiverPrefix(MethodInvocation node, PrefixElement prefix,
536+
SimpleIdentifier nameNode, String name) {
531537
// Note: prefix?.bar is reported as an error in ElementResolver.
532538

533539
if (name == FunctionElement.LOAD_LIBRARY_NAME) {
@@ -543,9 +549,6 @@ class MethodInvocationResolver {
543549
}
544550
}
545551

546-
// TODO(scheglov) I don't like how we resolve prefixed names.
547-
// But maybe this is the only one solution.
548-
var prefixedName = PrefixedIdentifierImpl.temp(receiver, nameNode);
549552
var element = prefix.scope.lookup2(name).getter;
550553
element = _resolver.toLegacyElement(element);
551554
nameNode.staticElement = element;
@@ -563,7 +566,11 @@ class MethodInvocationResolver {
563566
return _setResolution(node, element.type);
564567
}
565568

566-
_reportUndefinedFunction(node, prefixedName);
569+
_reportUndefinedFunction(
570+
node,
571+
prefix: prefix.name,
572+
name: name,
573+
);
567574
}
568575

569576
void _resolveReceiverSuper(MethodInvocation node, SuperExpression receiver,

pkg/analyzer/lib/src/dart/resolver/scope.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/element/element.dart';
1111
import 'package:analyzer/src/dart/element/scope.dart';
1212
import 'package:analyzer/src/dart/element/type.dart';
1313
import 'package:analyzer/src/generated/engine.dart';
14+
import 'package:meta/meta.dart';
1415

1516
/// The scope defined by a block.
1617
class BlockScope {
@@ -406,24 +407,34 @@ class PrefixedNamespace implements Namespace {
406407

407408
extension ScopeExtension on Scope {
408409
/// Return `true` if the fact that the given [node] is not defined should be
409-
/// ignored (from the perspective of error reporting). This will be the case
410-
/// if there is at least one import that defines the node's prefix, and if
411-
/// that import either has no show combinators or has a show combinator that
412-
/// explicitly lists the node's name.
410+
/// ignored (from the perspective of error reporting).
413411
bool shouldIgnoreUndefined(Identifier node) {
414412
if (node is PrefixedIdentifier) {
415-
return _enclosingLibraryScope.shouldIgnoreUndefined(
413+
return shouldIgnoreUndefined2(
416414
prefix: node.prefix.name,
417415
name: node.identifier.name,
418416
);
419417
}
420418

421-
return _enclosingLibraryScope.shouldIgnoreUndefined(
419+
return shouldIgnoreUndefined2(
422420
prefix: null,
423421
name: (node as SimpleIdentifier).name,
424422
);
425423
}
426424

425+
/// Return `true` if the fact that the identifier with the given [prefix]
426+
/// (might be `null`) and [name] is not defined should be ignored (from the
427+
/// perspective of error reporting).
428+
bool shouldIgnoreUndefined2({
429+
@required String prefix,
430+
@required String name,
431+
}) {
432+
return _enclosingLibraryScope.shouldIgnoreUndefined(
433+
prefix: prefix,
434+
name: name,
435+
);
436+
}
437+
427438
List<ExtensionElement> get extensions {
428439
return _enclosingLibraryScope.extensions;
429440
}

0 commit comments

Comments
 (0)