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

Side by Side Diff: lib/src/checker/checker.dart

Issue 1064933006: Enable downward inference on default params (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | test/checker/checker_test.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 dev_compiler.src.checker.checker; 5 library dev_compiler.src.checker.checker;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType; 10 import 'package:analyzer/src/generated/scanner.dart' show Token, TokenType;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 _rules.reportMissingType = callback; 358 _rules.reportMissingType = callback;
359 } 359 }
360 360
361 _visitMaybeConst(AstNode n, visitNode(AstNode n)) { 361 _visitMaybeConst(AstNode n, visitNode(AstNode n)) {
362 var o = _constantContext; 362 var o = _constantContext;
363 if (!o) { 363 if (!o) {
364 if (n is VariableDeclarationList) { 364 if (n is VariableDeclarationList) {
365 _constantContext = o || n.isConst; 365 _constantContext = o || n.isConst;
366 } else if (n is VariableDeclaration) { 366 } else if (n is VariableDeclaration) {
367 _constantContext = o || n.isConst; 367 _constantContext = o || n.isConst;
368 } else if (n is DefaultFormalParameter) {
369 _constantContext = true;
368 } else if (n is FormalParameter) { 370 } else if (n is FormalParameter) {
369 _constantContext = o || n.isConst; 371 _constantContext = o || n.isConst;
370 } else if (n is InstanceCreationExpression) { 372 } else if (n is InstanceCreationExpression) {
371 _constantContext = o || n.isConst; 373 _constantContext = o || n.isConst;
372 } else if (n is ConstructorDeclaration) { 374 } else if (n is ConstructorDeclaration) {
373 _constantContext = o || n.element.isConst; 375 _constantContext = o || n.element.isConst;
374 } 376 }
375 } 377 }
376 visitNode(n); 378 visitNode(n);
377 _constantContext = o; 379 _constantContext = o;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 node.visitChildren(this); 593 node.visitChildren(this);
592 } 594 }
593 595
594 @override visitDefaultFormalParameter(DefaultFormalParameter node) { 596 @override visitDefaultFormalParameter(DefaultFormalParameter node) {
595 _visitMaybeConst(node, (node) { 597 _visitMaybeConst(node, (node) {
596 // Check that defaults have the proper subtype. 598 // Check that defaults have the proper subtype.
597 var parameter = node.parameter; 599 var parameter = node.parameter;
598 var parameterType = _rules.elementType(parameter.element); 600 var parameterType = _rules.elementType(parameter.element);
599 assert(parameterType != null); 601 assert(parameterType != null);
600 var defaultValue = node.defaultValue; 602 var defaultValue = node.defaultValue;
601 var defaultType;
602 if (defaultValue == null) { 603 if (defaultValue == null) {
603 // TODO(vsm): Should this be null? 604 if (_rules.maybeNonNullableType(parameterType)) {
604 defaultType = _rules.provider.bottomType; 605 var staticInfo = new InvalidVariableDeclaration(
606 _rules, node.identifier, parameterType);
607 _recordMessage(staticInfo);
608 }
605 } else { 609 } else {
606 defaultType = _rules.getStaticType(defaultValue); 610 var staticInfo = checkAssignment(defaultValue, parameterType);
611 if (staticInfo is! StaticError) node.defaultValue = staticInfo;
607 } 612 }
608 613
609 // If defaultType is bottom, this enforces that parameterType is not
610 // non-nullable.
611 if (!_rules.isSubTypeOf(defaultType, parameterType)) {
612 var staticInfo = (defaultValue == null)
613 ? new InvalidVariableDeclaration(
614 _rules, node.identifier, parameterType)
615 : new StaticTypeError(_rules, defaultValue, parameterType);
616 _recordMessage(staticInfo);
617 }
618 node.visitChildren(this); 614 node.visitChildren(this);
619 }); 615 });
620 } 616 }
621 617
622 visitFieldFormalParameter(FieldFormalParameter node) { 618 visitFieldFormalParameter(FieldFormalParameter node) {
623 var element = node.element; 619 var element = node.element;
624 var typeName = node.type; 620 var typeName = node.type;
625 if (typeName != null) { 621 if (typeName != null) {
626 var type = _rules.elementType(element); 622 var type = _rules.elementType(element);
627 var fieldElement = 623 var fieldElement =
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 void _recordDynamicInvoke(AstNode node) { 797 void _recordDynamicInvoke(AstNode node) {
802 _reporter.log(new DynamicInvoke(_rules, node)); 798 _reporter.log(new DynamicInvoke(_rules, node));
803 } 799 }
804 800
805 void _recordMessage(StaticInfo info) { 801 void _recordMessage(StaticInfo info) {
806 if (info == null) return; 802 if (info == null) return;
807 if (info.level >= logger.Level.SEVERE) _failure = true; 803 if (info.level >= logger.Level.SEVERE) _failure = true;
808 _reporter.log(info); 804 _reporter.log(info);
809 } 805 }
810 } 806 }
OLDNEW
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698