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

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

Issue 2092873002: fix #25794, infer parameter type from default value (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge remote-tracking branch 'origin/master' into 25794_param_infer Created 4 years, 6 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 | pkg/analyzer/lib/src/summary/summarize_elements.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 474642ae4338266461ab1140774d7ff043a4056b..854661a8291d74307f60ce28bf115225d624a06f 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -4835,7 +4835,7 @@ class InferenceContext {
* Place an info node into the error stream indicating that a
* [type] has been inferred as the type of [node].
*/
- void recordInference(Expression node, DartType type) {
+ void recordInference(AstNode node, DartType type) {
if (!_inferenceHints) {
return;
}
@@ -5631,6 +5631,11 @@ class ResolverVisitor extends ScopedVisitor {
bool resolveOnlyCommentInFunctionBody = false;
/**
+ * True if we're analyzing in strong mode.
+ */
+ bool _strongMode;
+
+ /**
* Body of the function currently being analyzed, if any.
*/
FunctionBody _currentFunctionBody;
@@ -5661,6 +5666,7 @@ class ResolverVisitor extends ScopedVisitor {
this.typeSystem = definingLibrary.context.typeSystem;
bool strongModeHints = false;
AnalysisOptions options = definingLibrary.context.analysisOptions;
+ _strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
strongModeHints = options.strongModeHints;
}
@@ -6351,13 +6357,24 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitDefaultFormalParameter(DefaultFormalParameter node) {
- InferenceContext.setType(node.defaultValue, node.parameter.element?.type);
- super.visitDefaultFormalParameter(node);
ParameterElement element = node.element;
+ InferenceContext.setType(node.defaultValue, element.type);
+ super.visitDefaultFormalParameter(node);
if (element.initializer != null && node.defaultValue != null) {
(element.initializer as FunctionElementImpl).returnType =
node.defaultValue.staticType;
}
+ if (_strongMode &&
+ node.defaultValue != null &&
+ element.hasImplicitType &&
+ element is! FieldFormalParameterElement) {
+
+ DartType type = node.defaultValue.staticType;
+ if (!type.isBottom && !type.isDynamic) {
+ (element as ParameterElementImpl).type = type;
+ inferenceContext.recordInference(node, type);
+ }
+ }
// Clone the ASTs for default formal parameters, so that we can use them
// during constant evaluation.
if (!LibraryElementImpl.hasResolutionCapability(
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698