瀏覽代碼

Fix null arg check (#11076)

RblSb 8 月之前
父節點
當前提交
d54034a62c
共有 2 個文件被更改,包括 15 次插入2 次删除
  1. 1 1
      src/typing/nullSafety.ml
  2. 14 1
      tests/nullsafety/src/cases/TestStrict.hx

+ 1 - 1
src/typing/nullSafety.ml

@@ -1368,7 +1368,7 @@ class expr_checker mode immediate_execution report =
 				(* Local named functions like `function fn() {}`, which are generated as `var fn = null; fn = function(){}` *)
 				| Some { eexpr = TConst TNull } when v.v_kind = VUser TVOLocalFunction -> ()
 				(* `_this = null` is generated for local `inline function` *)
-				| Some { eexpr = TConst TNull } when v.v_kind = VGenerated -> ()
+				(* | Some { eexpr = TConst TNull } when v.v_kind = VGenerated -> () *)
 				| Some e ->
 					let local = { eexpr = TLocal v; epos = v.v_pos; etype = v.v_type } in
 					self#check_binop OpAssign local e p

+ 14 - 1
tests/nullsafety/src/cases/TestStrict.hx

@@ -289,6 +289,13 @@ class TestStrict {
 		shouldFail((true ? 'hello' : v).length);
 	}
 
+	static function inlineCallWithNullArg_shouldFail() {
+		inline function check(value: Int): Int {
+			return value;
+		}
+		shouldFail(check((null : Null<Int>)));
+	}
+
 	static function ternary_returnedFromInlinedFunction_shouldPass() {
 		var str:String = inlinedNullableSafeString([null]);
 	}
@@ -779,6 +786,12 @@ class TestStrict {
 				cb();
 			}
 		}
+		inline function cb2() {
+			if(foo != null) {
+				trace(foo);
+			}
+		}
+		cb2();
 	}
 
 	static public function closure_immediatelyExecuted_shouldInheritSafety(?s:String) {
@@ -1068,4 +1081,4 @@ abstract NullFloat(Null<Float>) from Null<Float> to Null<Float> {
 	@:op(A + B) static inline function addOp1(lhs: NullFloat, rhs: Float): Float {
 		return lhs != null ? lhs.val() + rhs : rhs;
 	}
-}
+}