mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:35:01 +00:00
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:
parent
450dc37e6b
commit
c0b5d99d82
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue