Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Unified Diff: pkg/analyzer/lib/src/generated/element_resolver.dart

Issue 1173523002: Fix analyzer's handling of import prefixes not followed by '.'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/element_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 291ac5b3a1c5dd35763499be54d0cc46053d0aad..dcf6c51194f0f90b320188de3c9f826b0caa2826 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -609,10 +609,10 @@ class ElementResolver extends SimpleAstVisitor<Object> {
staticElement =
propagatedElement = _resolveElement(typeReference, methodName);
} else {
- staticElement =
- _resolveInvokedElementWithTarget(target, staticType, methodName);
+ staticElement = _resolveInvokedElementWithTarget(
+ target, staticType, methodName, isConditional);
propagatedElement = _resolveInvokedElementWithTarget(
- target, propagatedType, methodName);
+ target, propagatedType, methodName, isConditional);
}
}
staticElement = _convertSetterToGetter(staticElement);
@@ -1002,6 +1002,10 @@ class ElementResolver extends SimpleAstVisitor<Object> {
Annotation annotation = node.parent as Annotation;
_resolver.reportErrorForNode(
CompileTimeErrorCode.INVALID_ANNOTATION, annotation);
+ } else if (element is PrefixElement) {
+ _resolver.reportErrorForNode(
+ CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, node,
+ [element.name]);
} else {
_recordUndefinedNode(_resolver.enclosingClass,
StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]);
@@ -1355,6 +1359,22 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
+ * Return the best type of the given [expression] that is to be used for
+ * type analysis.
+ */
+ DartType _getBestType(Expression expression) {
+ DartType bestType = _resolveTypeParameter(expression.bestType);
+ if (bestType is FunctionType) {
+ //
+ // All function types are subtypes of 'Function', which is itself a
+ // subclass of 'Object'.
+ //
+ bestType = _resolver.typeProvider.functionType;
+ }
+ return bestType;
+ }
+
+ /**
* Assuming that the given [expression] is a prefix for a deferred import,
* return the library that is being imported.
*/
@@ -1392,22 +1412,6 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
- * Return the best type of the given [expression] that is to be used for
- * type analysis.
- */
- DartType _getBestType(Expression expression) {
- DartType bestType = _resolveTypeParameter(expression.bestType);
- if (bestType is FunctionType) {
- //
- // All function types are subtypes of 'Function', which is itself a
- // subclass of 'Object'.
- //
- bestType = _resolver.typeProvider.functionType;
- }
- return bestType;
- }
-
- /**
* Return the propagated type of the given [expression] that is to be used for
* type analysis.
*/
@@ -2333,7 +2337,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
// Look first in the lexical scope.
//
Element element = _resolver.nameScope.lookup(methodName, _definingLibrary);
- if (element == null) {
+ if (element == null || element is PrefixElement) {
//
// If it isn't defined in the lexical scope, and the invocation is within
// a class, then look in the inheritance scope.
@@ -2362,10 +2366,11 @@ class ElementResolver extends SimpleAstVisitor<Object> {
* invoked without arguments and the result of that invocation will then be
* invoked with the arguments. The [target] is the target of the invocation
* ('e'). The [targetType] is the type of the target. The [methodName] is th
- * name of the method being invoked ('m').
+ * name of the method being invoked ('m'). [isConditional] indicates
+ * whether the invocatoin uses a '?.' operator.
*/
- Element _resolveInvokedElementWithTarget(
- Expression target, DartType targetType, SimpleIdentifier methodName) {
+ Element _resolveInvokedElementWithTarget(Expression target,
+ DartType targetType, SimpleIdentifier methodName, bool isConditional) {
if (targetType is InterfaceType) {
Element element = _lookUpMethod(target, targetType, methodName.name);
if (element == null) {
@@ -2381,6 +2386,11 @@ class ElementResolver extends SimpleAstVisitor<Object> {
} else if (target is SimpleIdentifier) {
Element targetElement = target.staticElement;
if (targetElement is PrefixElement) {
+ if (isConditional) {
+ _resolver.reportErrorForNode(
+ CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
+ target, [target.name]);
+ }
//
// Look to see whether the name of the method is really part of a
// prefixed identifier for an imported top-level function or top-level
@@ -2582,6 +2592,10 @@ class ElementResolver extends SimpleAstVisitor<Object> {
element = _resolver.nameScope.lookup(
new SyntheticIdentifier("${identifier.name}=", identifier),
_definingLibrary);
+ } else if (element is PrefixElement && !identifier.inGetterContext()) {
+ element = _resolver.nameScope.lookup(
+ new SyntheticIdentifier("${identifier.name}=", identifier),
+ _definingLibrary);
}
ClassElement enclosingClass = _resolver.enclosingClass;
if (element == null && enclosingClass != null) {
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698