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

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

Issue 1531313002: fix #25280, treat setters as returning void in strong mode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 7c3433d5d18ec5f3c2bfe55be18287c8310b3a6e..3ae42e474a965824460dc9d6ed74d540a8555bd1 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -11674,6 +11674,11 @@ class TypeResolverVisitor extends ScopedVisitor {
bool _hasReferenceToSuper = false;
/**
+ * True if we're analyzing in strong mode.
+ */
+ bool _strongMode;
+
+ /**
* Initialize a newly created visitor to resolve the nodes in an AST node.
*
* [definingLibrary] is the element for the library containing the node being
@@ -11695,6 +11700,7 @@ class TypeResolverVisitor extends ScopedVisitor {
nameScope: nameScope) {
_dynamicType = typeProvider.dynamicType;
_undefinedType = typeProvider.undefinedType;
+ _strongMode = definingLibrary.context.analysisOptions.strongMode;
}
@override
@@ -11935,6 +11941,7 @@ class TypeResolverVisitor extends ScopedVisitor {
}
element.returnType = _computeReturnType(node.returnType);
element.type = new FunctionTypeImpl(element);
+ _inferSetterReturnType(element);
return null;
}
@@ -11983,6 +11990,7 @@ class TypeResolverVisitor extends ScopedVisitor {
}
element.returnType = _computeReturnType(node.returnType);
element.type = new FunctionTypeImpl(element);
+ _inferSetterReturnType(element);
if (element is PropertyAccessorElement) {
PropertyAccessorElement accessor = element as PropertyAccessorElement;
PropertyInducingElementImpl variable =
@@ -12511,6 +12519,20 @@ class TypeResolverVisitor extends ScopedVisitor {
return type;
}
+ /**
+ * In strong mode we infer "void" as the setter return type (as void is the
+ * only legal return type for a setter). This allows us to give better
+ * errors later if an invalid type is returned.
+ */
+ void _inferSetterReturnType(ExecutableElementImpl element) {
+ if (_strongMode &&
+ element is PropertyAccessorElementImpl &&
+ element.isSetter &&
+ element.returnType.isDynamic) {
Brian Wilkerson 2015/12/17 17:57:59 We should check that the type 'dynamic' was not ex
Jennifer Messerly 2016/01/05 00:42:44 Good catch! I thought it was okay because it's inv
+ element.returnType = VoidTypeImpl.instance;
+ }
+ }
+
DartType _instantiateType(DartType type, List<DartType> typeArguments) {
if (type is InterfaceTypeImpl) {
return type.substitute4(typeArguments);

Powered by Google App Engine
This is Rietveld 408576698