Do not report BODY_MIGHT_COMPLETE_NORMALLY for setters

Fixes https://github.com/dart-lang/sdk/issues/42303
Change-Id: I4b0f6ac1f446c22eec278b3421a41e4176864e13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212720
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2021-09-08 16:07:13 +00:00 committed by commit-bot@chromium.org
parent 450dc37e6b
commit c0b5d99d82
3 changed files with 31 additions and 18 deletions

View file

@ -1423,15 +1423,17 @@ class ResolverVisitor extends ResolverBase with ErrorDetectionHelpers {
_enclosingFunction = outerFunction;
}
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(
node.functionExpression.body,
);
checkForBodyMayCompleteNormally(
returnType: bodyContext?.contextType,
body: node.functionExpression.body,
errorNode: node.name,
);
if (!node.isSetter) {
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(
node.functionExpression.body,
);
checkForBodyMayCompleteNormally(
returnType: bodyContext?.contextType,
body: node.functionExpression.body,
errorNode: node.name,
);
}
flowAnalysis.executableDeclaration_exit(
node.functionExpression.body,
isLocal,
@ -1650,13 +1652,15 @@ class ResolverVisitor extends ResolverBase with ErrorDetectionHelpers {
_thisType = null;
}
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(node.body);
checkForBodyMayCompleteNormally(
returnType: bodyContext?.contextType,
body: node.body,
errorNode: node.name,
);
if (!node.isSetter) {
// TODO(scheglov) encapsulate
var bodyContext = BodyInferenceContext.of(node.body);
checkForBodyMayCompleteNormally(
returnType: bodyContext?.contextType,
body: node.body,
errorNode: node.name,
);
}
flowAnalysis.executableDeclaration_exit(node.body, false);
flowAnalysis.topLevelDeclaration_exit();
nullSafetyDeadCodeVerifier.flowEnd(node);

View file

@ -367,4 +367,15 @@ class A {
}
''');
}
test_setter() async {
// Even though this code has an illegal return type for a setter, do not
// use the invalid return type to report BODY_MIGHT_COMPLETE_NORMALLY for
// setters.
await assertErrorsInCode(r'''
bool set s(int value) {}
''', [
error(CompileTimeErrorCode.NON_VOID_RETURN_FOR_SETTER, 0, 4),
]);
}
}

View file

@ -17,8 +17,6 @@ class A {
//^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_VOID_RETURN_FOR_SETTER
// [cfe] The return type of the setter must be 'void' or absent.
// ^^^
// [analyzer] COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY
}
main() {