Browse Source

Dont check `return expr` in assignments (#11114)

RblSb 2 years ago
parent
commit
ea162bc467
2 changed files with 16 additions and 2 deletions
  1. 1 1
      src/typing/nullSafety.ml
  2. 15 1
      tests/nullsafety/src/cases/TestLoose.hx

+ 1 - 1
src/typing/nullSafety.ml

@@ -1040,7 +1040,7 @@ class expr_checker mode immediate_execution report =
 				| TMeta (m, _) when contains_unsafe_meta [m] -> false
 				| TMeta (m, _) when contains_unsafe_meta [m] -> false
 				| TMeta (_, e) -> self#is_nullable_expr e
 				| TMeta (_, e) -> self#is_nullable_expr e
 				| TThrow _ -> false
 				| TThrow _ -> false
-				| TReturn (Some e) -> self#is_nullable_expr e
+				| TReturn _ -> false
 				| TBinop ((OpAssign | OpAssignOp _), _, right) -> self#is_nullable_expr right
 				| TBinop ((OpAssign | OpAssignOp _), _, right) -> self#is_nullable_expr right
 				| TBlock exprs ->
 				| TBlock exprs ->
 					local_safety#block_declared;
 					local_safety#block_declared;

+ 15 - 1
tests/nullsafety/src/cases/TestLoose.hx

@@ -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()) {});
+	}
+}