@@ -414,10 +414,17 @@ class ResolverVisitor extends ScopedVisitor {
414
414
}
415
415
416
416
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
+ }
421
428
}
422
429
}
423
430
}
@@ -807,24 +814,41 @@ class ResolverVisitor extends ScopedVisitor {
807
814
@override
808
815
void visitConstructorDeclaration (ConstructorDeclaration node) {
809
816
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 {
814
823
_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 {
822
844
_promoteManager.exitFunctionBody ();
823
- _enclosingFunction = outerFunction;
824
845
}
846
+
825
847
ConstructorElementImpl constructor = node.declaredElement;
826
848
constructor.constantInitializers =
827
849
_createCloner ().cloneNodeList (node.initializers);
850
+
851
+ _enclosingFunction = outerFunction;
828
852
}
829
853
830
854
@override
0 commit comments