Skip to content

Commit

Permalink
Dont check return expr in assignments (#11114)
Browse files Browse the repository at this point in the history
  • Loading branch information
RblSb authored Apr 11, 2023
1 parent b55358d commit ea162bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/typing/nullSafety.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion tests/nullsafety/src/cases/TestLoose.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ class TestLoose {
}
}
}
}

static function nullCoal_returnNull_shouldPass(token:{children:Array<Int>}):Null<Bool> {
final children = token.children ?? return null;
var i = children.length;
return null;
}

static function localFunc_returnNullCoal_shouldFail():Void {
function foo() {
final x = (null : Null<Bool>) ?? return null;
return x;
}
shouldFail(if (foo()) {});
}
}

0 comments on commit ea162bc

Please sign in to comment.