Revert "fix #28233, add hint for missing returns to function expressions"
This reverts commit 058510eeabb3204679f096da5668f9911e0e5217.
This causes a lot of missing_return failures internally and requires time to fix.
Change-Id: I2c7a79c6e838bbd9f101f53919b1db2c0d4a2594
Reviewed-on: https://dart-review.googlesource.com/70024
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 6016cae..893fea7 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -417,14 +417,6 @@
}
@override
- Object visitFunctionExpression(FunctionExpression node) {
- if (node.parent is! FunctionDeclaration) {
- _checkForMissingReturn(null, node.body, node.declaredElement, node);
- }
- return super.visitFunctionExpression(node);
- }
-
- @override
Object visitImportDirective(ImportDirective node) {
_checkForDeprecatedMemberUse(node.uriElement, node);
ImportElement importElement = node.element;
@@ -1124,28 +1116,7 @@
? returnType.flattenFutures(_typeSystem)
: returnType;
- // Function expressions without a return will have their return type set
- // to `Null` regardless of their context type. So we need to figure out
- // if a return type was expected from the original downwards context.
- //
- // This helps detect hint cases like `int Function() f = () {}`.
- // See https://github.com/dart-lang/sdk/issues/28233 for context.
- if (flattenedType.isDartCoreNull &&
- functionNode is FunctionExpression) {
- var contextType = InferenceContext.getContext(functionNode);
- if (contextType is FunctionType) {
- returnType = contextType.returnType;
- flattenedType = body.isAsynchronous
- ? returnType.flattenFutures(_typeSystem)
- : returnType;
- }
- }
-
- // dynamic, Null, void, and FutureOr<T> where T is (dynamic, Null, void)
- // are allowed to omit a return.
- if (flattenedType.isDartAsyncFutureOr) {
- flattenedType = (flattenedType as InterfaceType).typeArguments[0];
- }
+ // dynamic/Null/void are allowed to omit a return.
if (flattenedType.isDynamic ||
flattenedType.isDartCoreNull ||
flattenedType.isVoid) {
diff --git a/pkg/analyzer/test/generated/hint_code_kernel_test.dart b/pkg/analyzer/test/generated/hint_code_kernel_test.dart
index 4103dd6..3e9f85c 100644
--- a/pkg/analyzer/test/generated/hint_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_kernel_test.dart
@@ -133,24 +133,6 @@
@failingTest
@override
- test_missingReturn_functionExpression_futureOrInt() async {
- return super.test_missingReturn_functionExpression_futureOrInt();
- }
-
- @failingTest
- @override
- test_missingReturn_functionExpression_inferred() async {
- return super.test_missingReturn_functionExpression_inferred();
- }
-
- @failingTest
- @override
- test_missingReturn_functionExpressionAsync_inferred() async {
- return super.test_missingReturn_functionExpressionAsync_inferred();
- }
-
- @failingTest
- @override
test_mustCallSuper() async {
return super.test_mustCallSuper();
}
diff --git a/pkg/analyzer/test/generated/hint_code_test.dart b/pkg/analyzer/test/generated/hint_code_test.dart
index 71d82e9..7235f38 100644
--- a/pkg/analyzer/test/generated/hint_code_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_test.dart
@@ -2589,96 +2589,6 @@
verify([source]);
}
- test_missingReturn_functionExpression_declared() async {
- Source source = addSource(r'''
-main() {
- f() {} // no hint
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_missingReturn_functionExpression_expression() async {
- Source source = addSource(r'''
-main() {
- int Function() f = () => null; // no hint
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- }
-
- test_missingReturn_functionExpression_futureOrDynamic() async {
- Source source = addSource(r'''
-import 'dart:async';
-main() {
- FutureOr<dynamic> Function() f = () { print(42); };
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_missingReturn_functionExpression_futureOrInt() async {
- Source source = addSource(r'''
-import 'dart:async';
-main() {
- FutureOr<int> Function() f = () { print(42); };
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.MISSING_RETURN]);
- verify([source]);
- }
-
- test_missingReturn_functionExpression_inferred() async {
- Source source = addSource(r'''
-main() {
- int Function() f = () { print(42); };
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.MISSING_RETURN]);
- verify([source]);
- }
-
- test_missingReturn_functionExpression_inferred_dynamic() async {
- Source source = addSource(r'''
-main() {
- Function() f = () { print(42); }; // no hint
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_missingReturn_functionExpressionAsync_inferred() async {
- Source source = addSource(r'''
-import 'dart:async';
-main() {
- Future<int> Function() f = () async { print(42); };
-}
-''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.MISSING_RETURN]);
- verify([source]);
- }
-
- test_missingReturn_functionExpressionAsync_inferred_dynamic() async {
- Source source = addSource(r'''
-import 'dart:async';
-main() {
- Future Function() f = () async { print(42); }; // no hint
-}
-''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
test_missingReturn_method() async {
Source source = addSource(r'''
class A {
@@ -2689,28 +2599,6 @@
verify([source]);
}
- test_missingReturn_method_futureOrDynamic() async {
- Source source = addSource(r'''
-import 'dart:async';
-class A {
- FutureOr<dynamic> m() {}
-}''');
- await computeAnalysisResult(source);
- assertNoErrors(source);
- verify([source]);
- }
-
- test_missingReturn_method_futureOrInt() async {
- Source source = addSource(r'''
-import 'dart:async';
-class A {
- FutureOr<int> m() {}
-}''');
- await computeAnalysisResult(source);
- assertErrors(source, [HintCode.MISSING_RETURN]);
- verify([source]);
- }
-
test_missingReturn_method_inferred() async {
Source source = addSource(r'''
abstract class A {
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index cfde643..b31697c 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -1379,9 +1379,8 @@
if (clause is js.Case) {
return new js.Case(
clause.expression, translateToBlock(clause.body));
- } else {
- return new js.Default(
- translateToBlock((clause as js.Default).body));
+ } else if (clause is js.Default) {
+ return new js.Default(translateToBlock(clause.body));
}
}).toList();
addStatement(new js.Switch(key, cases));
diff --git a/pkg/compiler/lib/src/js_backend/interceptor_data.dart b/pkg/compiler/lib/src/js_backend/interceptor_data.dart
index 69f45a6f..f621411 100644
--- a/pkg/compiler/lib/src/js_backend/interceptor_data.dart
+++ b/pkg/compiler/lib/src/js_backend/interceptor_data.dart
@@ -188,7 +188,6 @@
if (result == null) result = new Set<ClassEntity>();
result.add(subclass);
}
- return null;
});
}
return result;
diff --git a/pkg/compiler/lib/src/js_backend/runtime_types.dart b/pkg/compiler/lib/src/js_backend/runtime_types.dart
index 83c783a..95682d0 100644
--- a/pkg/compiler/lib/src/js_backend/runtime_types.dart
+++ b/pkg/compiler/lib/src/js_backend/runtime_types.dart
@@ -1473,7 +1473,6 @@
closedWorld.classHierarchy.forEachStrictSubtypeOf(cls,
(ClassEntity sub) {
potentiallyNeedTypeArguments(sub);
- return null;
});
} else if (entity is FunctionEntity) {
methodsNeedingTypeArguments.add(entity);
diff --git a/pkg/compiler/lib/src/js_model/js_strategy.dart b/pkg/compiler/lib/src/js_model/js_strategy.dart
index 2f434b5..a4b4472 100644
--- a/pkg/compiler/lib/src/js_model/js_strategy.dart
+++ b/pkg/compiler/lib/src/js_model/js_strategy.dart
@@ -295,7 +295,6 @@
.getClassHierarchyNode(closedWorld.commonElements.objectClass)
.forEachSubclass((ClassEntity cls) {
convertClassSet(closedWorld.classHierarchy.getClassSet(cls));
- return null;
}, ClassHierarchyNode.ALL);
Set<MemberEntity> liveInstanceMembers =
diff --git a/pkg/compiler/lib/src/old_to_new_api.dart b/pkg/compiler/lib/src/old_to_new_api.dart
index a12355f..0363419 100644
--- a/pkg/compiler/lib/src/old_to_new_api.dart
+++ b/pkg/compiler/lib/src/old_to_new_api.dart
@@ -23,8 +23,6 @@
@override
Future<Input> readFromUri(Uri uri, {InputKind inputKind: InputKind.UTF8}) {
- // The switch handles all enum values, but not null.
- // ignore: missing_return
return _inputProvider(uri).then((/*String|List<int>*/ data) {
switch (inputKind) {
case InputKind.UTF8:
diff --git a/tests/compiler/dart2js/model/class_set_test.dart b/tests/compiler/dart2js/model/class_set_test.dart
index 95f5ed5..da0633f 100644
--- a/tests/compiler/dart2js/model/class_set_test.dart
+++ b/tests/compiler/dart2js/model/class_set_test.dart
@@ -404,7 +404,6 @@
List<ClassEntity> visited = <ClassEntity>[];
classSet.forEachSubclass((cls) {
visited.add(cls);
- return null;
}, ClassHierarchyNode.ALL);
Expect.listEquals(
@@ -442,7 +441,6 @@
List<ClassEntity> visited = <ClassEntity>[];
classSet.forEachSubtype((cls) {
visited.add(cls);
- return null;
}, ClassHierarchyNode.ALL);
Expect.listEquals(
diff --git a/tests/compiler/dart2js/model/world_test.dart b/tests/compiler/dart2js/model/world_test.dart
index 14da865..a4b49ce 100644
--- a/tests/compiler/dart2js/model/world_test.dart
+++ b/tests/compiler/dart2js/model/world_test.dart
@@ -99,7 +99,6 @@
List<ClassEntity> visited = <ClassEntity>[];
forEach(cls, (ClassEntity c) {
visited.add(c);
- return null;
});
checkClasses('forEach($property)', cls, visited, expectedClasses,
exact: exact);
@@ -425,7 +424,6 @@
if (allClasses.contains(other)) {
strictSubclasses.add(other);
}
- return null;
});
Expect.setEquals(subclasses, strictSubclasses,
"Unexpected strict subclasses of $cls: ${strictSubclasses}.");
@@ -435,7 +433,6 @@
if (allClasses.contains(other)) {
strictSubtypes.add(other);
}
- return null;
});
Expect.setEquals(subtypes, strictSubtypes,
"Unexpected strict subtypes of $cls: $strictSubtypes.");
diff --git a/tests/compiler/dart2js/receiver_type_test.dart b/tests/compiler/dart2js/receiver_type_test.dart
index 26bacc4..d8ad1ac 100644
--- a/tests/compiler/dart2js/receiver_type_test.dart
+++ b/tests/compiler/dart2js/receiver_type_test.dart
@@ -49,7 +49,7 @@
Selector callSelector = new Selector.callClosure(0);
closedWorld.classHierarchy.forEachStrictSubclassOf(
closedWorld.commonElements.objectClass, (ClassEntity cls) {
- if (cls.library.canonicalUri.scheme != 'memory') return null;
+ if (cls.library.canonicalUri.scheme != 'memory') return;
TypeMask mask = new TypeMask.nonNullSubclass(cls, closedWorld);
TypeMask receiverType = closedWorld.computeReceiverType(callSelector, mask);
@@ -65,7 +65,6 @@
Expect.equals(expected, '$receiverType',
"Unexpected receiver type for $callSelector on $mask");
}
- return null;
});
Expect.equals(2, closureCount);
diff --git a/tests/compiler/dart2js/sourcemaps/helpers/sourcemap_helper.dart b/tests/compiler/dart2js/sourcemaps/helpers/sourcemap_helper.dart
index 3e52e3a..270e686 100644
--- a/tests/compiler/dart2js/sourcemaps/helpers/sourcemap_helper.dart
+++ b/tests/compiler/dart2js/sourcemaps/helpers/sourcemap_helper.dart
@@ -254,7 +254,6 @@
}
return null;
}
- return null;
});
}
}