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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 2983293002: Remove toplevel inference restriction hints, and restore as much (Closed)
Patch Set: Keep error filter Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/task/strong/checker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 3137 matching lines...) Expand 10 before | Expand all | Expand 10 after
3148 3148
3149 @override 3149 @override
3150 void internalPerform() { 3150 void internalPerform() {
3151 // 3151 //
3152 // Prepare inputs. 3152 // Prepare inputs.
3153 // 3153 //
3154 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 3154 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3155 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 3155 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3156 3156
3157 // 3157 //
3158 // Prepare fields for which inference should be disabled.
3159 //
3160 Set<FieldElement> fieldsWithDisabledInference = new Set<FieldElement>();
3161 for (CompilationUnitMember classDeclaration in unit.declarations) {
3162 if (classDeclaration is ClassDeclaration) {
3163 for (ClassMember fieldDeclaration in classDeclaration.members) {
3164 if (fieldDeclaration is FieldDeclaration) {
3165 if (!fieldDeclaration.isStatic) {
3166 for (VariableDeclaration field
3167 in fieldDeclaration.fields.variables) {
3168 Expression initializer = field.initializer;
3169 if (initializer != null &&
3170 !isValidForTypeInference(initializer)) {
3171 fieldsWithDisabledInference.add(field.element);
3172 }
3173 }
3174 }
3175 }
3176 }
3177 }
3178 }
3179
3180 //
3181 // Infer instance members. 3158 // Infer instance members.
3182 // 3159 //
3183 if (context.analysisOptions.strongMode) { 3160 if (context.analysisOptions.strongMode) {
3184 var inheritanceManager = new InheritanceManager( 3161 var inheritanceManager = new InheritanceManager(
3185 resolutionMap.elementDeclaredByCompilationUnit(unit).library); 3162 resolutionMap.elementDeclaredByCompilationUnit(unit).library);
3186 InstanceMemberInferrer inferrer = new InstanceMemberInferrer( 3163 InstanceMemberInferrer inferrer = new InstanceMemberInferrer(
3187 typeProvider, (_) => inheritanceManager, fieldsWithDisabledInference, 3164 typeProvider, (_) => inheritanceManager,
3188 typeSystem: context.typeSystem); 3165 typeSystem: context.typeSystem);
3189 inferrer.inferCompilationUnit(unit.element); 3166 inferrer.inferCompilationUnit(unit.element);
3190 } 3167 }
3191 // 3168 //
3192 // Record outputs. 3169 // Record outputs.
3193 // 3170 //
3194 outputs[RESOLVED_UNIT10] = unit; 3171 outputs[RESOLVED_UNIT10] = unit;
3195 outputs[CREATED_RESOLVED_UNIT10] = true; 3172 outputs[CREATED_RESOLVED_UNIT10] = true;
3196 } 3173 }
3197 3174
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 List<AnalysisError> errors = AnalysisError.NO_ERRORS; 3416 List<AnalysisError> errors = AnalysisError.NO_ERRORS;
3440 if (dependencyCycle == null && variable.hasImplicitType) { 3417 if (dependencyCycle == null && variable.hasImplicitType) {
3441 VariableDeclaration declaration = getDeclaration(unit); 3418 VariableDeclaration declaration = getDeclaration(unit);
3442 // 3419 //
3443 // Re-resolve the variable's initializer so that the inferred types 3420 // Re-resolve the variable's initializer so that the inferred types
3444 // of other variables will be propagated. 3421 // of other variables will be propagated.
3445 // 3422 //
3446 RecordingErrorListener errorListener = new RecordingErrorListener(); 3423 RecordingErrorListener errorListener = new RecordingErrorListener();
3447 Expression initializer = declaration.initializer; 3424 Expression initializer = declaration.initializer;
3448 3425
3449 DartType newType; 3426 ResolutionContext resolutionContext =
3450 if (!isValidForTypeInference(initializer)) { 3427 ResolutionContextBuilder.contextFor(initializer);
3428 ResolverVisitor visitor = new ResolverVisitor(
3429 variable.library, variable.source, typeProvider, errorListener,
3430 nameScope: resolutionContext.scope);
3431 if (resolutionContext.enclosingClassDeclaration != null) {
3432 visitor.prepareToResolveMembersInClass(
3433 resolutionContext.enclosingClassDeclaration);
3434 }
3435 visitor.initForIncrementalResolution();
3436 initializer.accept(visitor);
3437 DartType newType = initializer.staticType;
3438 if (newType == null || newType.isBottom || newType.isDartCoreNull) {
3451 newType = typeProvider.dynamicType; 3439 newType = typeProvider.dynamicType;
3452 } else {
3453 ResolutionContext resolutionContext =
3454 ResolutionContextBuilder.contextFor(initializer);
3455 ResolverVisitor visitor = new ResolverVisitor(
3456 variable.library, variable.source, typeProvider, errorListener,
3457 nameScope: resolutionContext.scope);
3458 if (resolutionContext.enclosingClassDeclaration != null) {
3459 visitor.prepareToResolveMembersInClass(
3460 resolutionContext.enclosingClassDeclaration);
3461 }
3462 visitor.initForIncrementalResolution();
3463 initializer.accept(visitor);
3464 newType = initializer.staticType;
3465 if (newType == null || newType.isBottom || newType.isDartCoreNull) {
3466 newType = typeProvider.dynamicType;
3467 }
3468 } 3440 }
3469 3441
3470 // 3442 //
3471 // Record the type of the variable. 3443 // Record the type of the variable.
3472 // 3444 //
3473 setFieldType(variable, newType); 3445 setFieldType(variable, newType);
3474 errors = getUniqueErrors(errorListener.errors); 3446 errors = getUniqueErrors(errorListener.errors);
3475 } else { 3447 } else {
3476 // TODO(brianwilkerson) For now we simply don't infer any type for 3448 // TODO(brianwilkerson) For now we simply don't infer any type for
3477 // variables or fields involved in a cycle. We could try to be smarter 3449 // variables or fields involved in a cycle. We could try to be smarter
(...skipping 2390 matching lines...) Expand 10 before | Expand all | Expand 10 after
5868 5840
5869 @override 5841 @override
5870 bool moveNext() { 5842 bool moveNext() {
5871 if (_newSources.isEmpty) { 5843 if (_newSources.isEmpty) {
5872 return false; 5844 return false;
5873 } 5845 }
5874 currentTarget = _newSources.removeLast(); 5846 currentTarget = _newSources.removeLast();
5875 return true; 5847 return true;
5876 } 5848 }
5877 } 5849 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/task/strong/checker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698