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

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

Issue 2754423002: Fail inference when an instance field is referenced. (Closed)
Patch Set: Clean up and move tests. 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 unified diff | Download patch
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 3444 matching lines...) Expand 10 before | Expand all | Expand 10 after
3455 @override 3455 @override
3456 TaskDescriptor get descriptor => DESCRIPTOR; 3456 TaskDescriptor get descriptor => DESCRIPTOR;
3457 3457
3458 @override 3458 @override
3459 void internalPerform() { 3459 void internalPerform() {
3460 // 3460 //
3461 // Prepare inputs. 3461 // Prepare inputs.
3462 // 3462 //
3463 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 3463 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3464 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 3464 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3465
3466 //
3467 // Prepare fields for which inference should be disabled.
3468 //
3469 Set<FieldElement> fieldsWithDisabledInference = new Set<FieldElement>();
3470 for (CompilationUnitMember classDeclaration in unit.declarations) {
3471 if (classDeclaration is ClassDeclaration) {
3472 for (ClassMember fieldDeclaration in classDeclaration.members) {
3473 if (fieldDeclaration is FieldDeclaration) {
3474 if (!fieldDeclaration.isStatic) {
3475 for (VariableDeclaration field
3476 in fieldDeclaration.fields.variables) {
3477 Expression initializer = field.initializer;
3478 if (initializer != null &&
3479 !isValidForTypeInference(initializer)) {
3480 fieldsWithDisabledInference.add(field.element);
3481 }
3482 }
3483 }
3484 }
3485 }
3486 }
3487 }
3488
3465 // 3489 //
3466 // Infer instance members. 3490 // Infer instance members.
3467 // 3491 //
3468 if (context.analysisOptions.strongMode) { 3492 if (context.analysisOptions.strongMode) {
3469 InstanceMemberInferrer inferrer = new InstanceMemberInferrer( 3493 InstanceMemberInferrer inferrer = new InstanceMemberInferrer(
3470 typeProvider, 3494 typeProvider,
3471 new InheritanceManager( 3495 new InheritanceManager(
3472 resolutionMap.elementDeclaredByCompilationUnit(unit).library), 3496 resolutionMap.elementDeclaredByCompilationUnit(unit).library),
3497 fieldsWithDisabledInference,
3473 typeSystem: context.typeSystem); 3498 typeSystem: context.typeSystem);
3474 inferrer.inferCompilationUnit(unit.element); 3499 inferrer.inferCompilationUnit(unit.element);
3475 } 3500 }
3476 // 3501 //
3477 // Record outputs. 3502 // Record outputs.
3478 // 3503 //
3479 outputs[RESOLVED_UNIT10] = unit; 3504 outputs[RESOLVED_UNIT10] = unit;
3480 outputs[CREATED_RESOLVED_UNIT10] = true; 3505 outputs[CREATED_RESOLVED_UNIT10] = true;
3481 } 3506 }
3482 3507
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3735 ResolverVisitor visitor = new ResolverVisitor( 3760 ResolverVisitor visitor = new ResolverVisitor(
3736 variable.library, variable.source, typeProvider, errorListener, 3761 variable.library, variable.source, typeProvider, errorListener,
3737 nameScope: resolutionContext.scope); 3762 nameScope: resolutionContext.scope);
3738 if (resolutionContext.enclosingClassDeclaration != null) { 3763 if (resolutionContext.enclosingClassDeclaration != null) {
3739 visitor.prepareToResolveMembersInClass( 3764 visitor.prepareToResolveMembersInClass(
3740 resolutionContext.enclosingClassDeclaration); 3765 resolutionContext.enclosingClassDeclaration);
3741 } 3766 }
3742 visitor.initForIncrementalResolution(); 3767 visitor.initForIncrementalResolution();
3743 initializer.accept(visitor); 3768 initializer.accept(visitor);
3744 3769
3770 DartType newType;
3771 if (!isValidForTypeInference(initializer)) {
3772 newType = typeProvider.dynamicType;
3773 } else {
3774 newType = initializer.staticType;
3775 if (newType == null || newType.isBottom || newType.isDartCoreNull) {
3776 newType = typeProvider.dynamicType;
3777 }
3778 }
3779
3745 // 3780 //
3746 // Record the type of the variable. 3781 // Record the type of the variable.
3747 // 3782 //
3748 DartType newType = initializer.staticType;
3749 if (newType == null || newType.isBottom || newType.isDartCoreNull) {
3750 newType = typeProvider.dynamicType;
3751 }
3752 setFieldType(variable, newType); 3783 setFieldType(variable, newType);
3753 errors = getUniqueErrors(errorListener.errors); 3784 errors = getUniqueErrors(errorListener.errors);
3754 } else { 3785 } else {
3755 // TODO(brianwilkerson) For now we simply don't infer any type for 3786 // TODO(brianwilkerson) For now we simply don't infer any type for
3756 // variables or fields involved in a cycle. We could try to be smarter 3787 // variables or fields involved in a cycle. We could try to be smarter
3757 // by re-resolving the initializer in a context in which the types of all 3788 // by re-resolving the initializer in a context in which the types of all
3758 // of the variables in the cycle are assumed to be `null`, but it isn't 3789 // of the variables in the cycle are assumed to be `null`, but it isn't
3759 // clear to me that this would produce better results often enough to 3790 // clear to me that this would produce better results often enough to
3760 // warrant the extra effort. 3791 // warrant the extra effort.
3761 } 3792 }
(...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after
6556 6587
6557 @override 6588 @override
6558 bool moveNext() { 6589 bool moveNext() {
6559 if (_newSources.isEmpty) { 6590 if (_newSources.isEmpty) {
6560 return false; 6591 return false;
6561 } 6592 }
6562 currentTarget = _newSources.removeLast(); 6593 currentTarget = _newSources.removeLast();
6563 return true; 6594 return true;
6564 } 6595 }
6565 } 6596 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/lib/src/task/strong_mode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698