@@ -414,10 +414,17 @@ class ResolverVisitor extends ScopedVisitor {
414414 }
415415
416416 if (typeSystem.isPotentiallyNonNullable (returnType)) {
417- errorReporter.reportErrorForNode (
418- CompileTimeErrorCode .BODY_MIGHT_COMPLETE_NORMALLY ,
419- errorNode,
420- );
417+ if (errorNode is ConstructorDeclaration ) {
418+ errorReporter.reportErrorForName (
419+ CompileTimeErrorCode .BODY_MIGHT_COMPLETE_NORMALLY ,
420+ errorNode,
421+ );
422+ } else {
423+ errorReporter.reportErrorForNode (
424+ CompileTimeErrorCode .BODY_MIGHT_COMPLETE_NORMALLY ,
425+ errorNode,
426+ );
427+ }
421428 }
422429 }
423430 }
@@ -807,24 +814,41 @@ class ResolverVisitor extends ScopedVisitor {
807814 @override
808815 void visitConstructorDeclaration (ConstructorDeclaration node) {
809816 ExecutableElement outerFunction = _enclosingFunction;
810- try {
811- _flowAnalysis? .topLevelDeclaration_enter (
812- node, node.parameters, node.body);
813- _flowAnalysis? .executableDeclaration_enter (node, node.parameters, false );
817+ _enclosingFunction = node.declaredElement;
818+
819+ if (_flowAnalysis != null ) {
820+ _flowAnalysis.topLevelDeclaration_enter (node, node.parameters, node.body);
821+ _flowAnalysis.executableDeclaration_enter (node, node.parameters, false );
822+ } else {
814823 _promoteManager.enterFunctionBody (node.body);
815- _enclosingFunction = node.declaredElement;
816- FunctionType type = _enclosingFunction.type;
817- InferenceContext .setType (node.body, type.returnType);
818- super .visitConstructorDeclaration (node);
819- } finally {
820- _flowAnalysis? .executableDeclaration_exit (node.body, false );
821- _flowAnalysis? .topLevelDeclaration_exit ();
824+ }
825+
826+ var returnType = _enclosingFunction.type.returnType;
827+ InferenceContext .setType (node.body, returnType);
828+
829+ super .visitConstructorDeclaration (node);
830+
831+ if (_flowAnalysis != null ) {
832+ var bodyContext = BodyInferenceContext .of (node.body);
833+ if (node.factoryKeyword != null ) {
834+ checkForBodyMayCompleteNormally (
835+ returnType: bodyContext? .contextType,
836+ body: node.body,
837+ errorNode: node,
838+ );
839+ }
840+ _flowAnalysis.executableDeclaration_exit (node.body, false );
841+ _flowAnalysis.topLevelDeclaration_exit ();
842+ nullSafetyDeadCodeVerifier? .flowEnd (node);
843+ } else {
822844 _promoteManager.exitFunctionBody ();
823- _enclosingFunction = outerFunction;
824845 }
846+
825847 ConstructorElementImpl constructor = node.declaredElement;
826848 constructor.constantInitializers =
827849 _createCloner ().cloneNodeList (node.initializers);
850+
851+ _enclosingFunction = outerFunction;
828852 }
829853
830854 @override
0 commit comments