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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/checker/checker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/checker/checker.dart
diff --git a/lib/src/checker/checker.dart b/lib/src/checker/checker.dart
index d3fb972535dcea74e31595e5d799b648cf7eaad0..fff7baea925fdfd60a76226826b43be256e0b83f 100644
--- a/lib/src/checker/checker.dart
+++ b/lib/src/checker/checker.dart
@@ -365,6 +365,8 @@ class CodeChecker extends RecursiveAstVisitor {
_constantContext = o || n.isConst;
} else if (n is VariableDeclaration) {
_constantContext = o || n.isConst;
+ } else if (n is DefaultFormalParameter) {
+ _constantContext = true;
} else if (n is FormalParameter) {
_constantContext = o || n.isConst;
} else if (n is InstanceCreationExpression) {
@@ -598,23 +600,17 @@ class CodeChecker extends RecursiveAstVisitor {
var parameterType = _rules.elementType(parameter.element);
assert(parameterType != null);
var defaultValue = node.defaultValue;
- var defaultType;
if (defaultValue == null) {
- // TODO(vsm): Should this be null?
- defaultType = _rules.provider.bottomType;
+ if (_rules.maybeNonNullableType(parameterType)) {
+ var staticInfo = new InvalidVariableDeclaration(
+ _rules, node.identifier, parameterType);
+ _recordMessage(staticInfo);
+ }
} else {
- defaultType = _rules.getStaticType(defaultValue);
+ var staticInfo = checkAssignment(defaultValue, parameterType);
+ if (staticInfo is! StaticError) node.defaultValue = staticInfo;
}
- // If defaultType is bottom, this enforces that parameterType is not
- // non-nullable.
- if (!_rules.isSubTypeOf(defaultType, parameterType)) {
- var staticInfo = (defaultValue == null)
- ? new InvalidVariableDeclaration(
- _rules, node.identifier, parameterType)
- : new StaticTypeError(_rules, defaultValue, parameterType);
- _recordMessage(staticInfo);
- }
node.visitChildren(this);
});
}
« 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