From ea162bc467bafb936d13cd4772b3433c504d9813 Mon Sep 17 00:00:00 2001 From: RblSb Date: Tue, 11 Apr 2023 09:58:24 +0300 Subject: [PATCH] Dont check `return expr` in assignments (#11114) --- src/typing/nullSafety.ml | 2 +- tests/nullsafety/src/cases/TestLoose.hx | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/typing/nullSafety.ml b/src/typing/nullSafety.ml index be3da1f5913..f67b0a69c18 100644 --- a/src/typing/nullSafety.ml +++ b/src/typing/nullSafety.ml @@ -1040,7 +1040,7 @@ class expr_checker mode immediate_execution report = | TMeta (m, _) when contains_unsafe_meta [m] -> false | TMeta (_, e) -> self#is_nullable_expr e | TThrow _ -> false - | TReturn (Some e) -> self#is_nullable_expr e + | TReturn _ -> false | TBinop ((OpAssign | OpAssignOp _), _, right) -> self#is_nullable_expr right | TBlock exprs -> local_safety#block_declared; diff --git a/tests/nullsafety/src/cases/TestLoose.hx b/tests/nullsafety/src/cases/TestLoose.hx index 2be8f7cbaa3..233f9c778d7 100644 --- a/tests/nullsafety/src/cases/TestLoose.hx +++ b/tests/nullsafety/src/cases/TestLoose.hx @@ -99,4 +99,18 @@ class TestLoose { } } } -} \ No newline at end of file + + static function nullCoal_returnNull_shouldPass(token:{children:Array}):Null { + final children = token.children ?? return null; + var i = children.length; + return null; + } + + static function localFunc_returnNullCoal_shouldFail():Void { + function foo() { + final x = (null : Null) ?? return null; + return x; + } + shouldFail(if (foo()) {}); + } +}