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

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

Issue 2782533002: Report errors for the new top-level inference rules. (Closed)
Patch Set: Update language_strong status for analyzer. Created 3 years, 9 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 | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index ea2830a0c310c5a57327e72902da86c53332e132..f56e5c388901df83c3ff0c6ebdff775ec1241c3f 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -5022,6 +5022,12 @@ class ResolverVisitor extends ScopedVisitor {
bool resolveOnlyCommentInFunctionBody = false;
/**
+ * This flag is set to `true` while the type of a top-level variable or a
+ * class field is being inferred using its initializer.
+ */
+ bool isTopLevelInference;
+
+ /**
* Body of the function currently being analyzed, if any.
*/
FunctionBody _currentFunctionBody;
@@ -5050,7 +5056,7 @@ class ResolverVisitor extends ScopedVisitor {
*/
ResolverVisitor(LibraryElement definingLibrary, Source source,
TypeProvider typeProvider, AnalysisErrorListener errorListener,
- {Scope nameScope})
+ {Scope nameScope, this.isTopLevelInference: false})
: super(definingLibrary, source, typeProvider, errorListener,
nameScope: nameScope) {
AnalysisOptions options = definingLibrary.context.analysisOptions;
@@ -5550,11 +5556,14 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitBlockFunctionBody(BlockFunctionBody node) {
+ bool wasTopLevelInference = isTopLevelInference;
+ isTopLevelInference = false;
_overrideManager.enterScope();
try {
inferenceContext.pushReturnContext(node);
super.visitBlockFunctionBody(node);
} finally {
+ isTopLevelInference = wasTopLevelInference;
_overrideManager.exitScope();
inferenceContext.popReturnContext(node);
}
@@ -5873,10 +5882,13 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitFieldDeclaration(FieldDeclaration node) {
+ bool wasTopLevelInference = isTopLevelInference;
+ isTopLevelInference = node.fields.type == null;
_overrideManager.enterScope();
try {
super.visitFieldDeclaration(node);
} finally {
+ isTopLevelInference = wasTopLevelInference;
Map<VariableElement, DartType> overrides =
_overrideManager.captureOverrides(node.fields);
_overrideManager.exitScope();
@@ -6379,10 +6391,13 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
+ bool wasTopLevelInference = isTopLevelInference;
+ isTopLevelInference = node.variables.type == null;
_overrideManager.enterScope();
try {
super.visitTopLevelVariableDeclaration(node);
} finally {
+ isTopLevelInference = wasTopLevelInference;
Map<VariableElement, DartType> overrides =
_overrideManager.captureOverrides(node.variables);
_overrideManager.exitScope();
@@ -6661,6 +6676,11 @@ class ResolverVisitor extends ScopedVisitor {
uninstantiatedType is FunctionType &&
uninstantiatedType.typeFormals.isNotEmpty &&
ts is StrongTypeSystemImpl) {
+ if (isTopLevelInference) {
+ if (uninstantiatedType.typeFormals.isNotEmpty) {
+ return null;
+ }
+ }
return ts.inferGenericFunctionOrType/*<FunctionType>*/(
uninstantiatedType,
ParameterElement.EMPTY_LIST,
« no previous file with comments | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698