Browse Source

[nullsafety] ignore autogenerated `_this = null` (closes #8443)

Aleksandr Kuzmenko 6 years ago
parent
commit
e79e708689
2 changed files with 10 additions and 0 deletions
  1. 2 0
      src/typing/nullSafety.ml
  2. 8 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 2 - 0
src/typing/nullSafety.ml

@@ -1259,6 +1259,8 @@ class expr_checker mode immediate_execution report =
 				| None -> ()
 				| None -> ()
 				(* Local named functions like `function fn() {}`, which are generated as `var fn = null; fn = function(){}` *)
 				(* 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 -> ()
 				| 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 e ->
 				| Some e ->
 					let local = { eexpr = TLocal v; epos = v.v_pos; etype = v.v_type } in
 					let local = { eexpr = TLocal v; epos = v.v_pos; etype = v.v_type } in
 					self#check_binop OpAssign local e p
 					self#check_binop OpAssign local e p

+ 8 - 0
tests/nullsafety/src/cases/TestStrict.hx

@@ -881,6 +881,14 @@ class TestStrict {
 		var y:Float = x.val();
 		var y:Float = x.val();
 		x += x;
 		x += x;
 	}
 	}
+
+	static function issue8443_nullPassedToInline_shouldPass() {
+		inline function method(?map: (Int)->Int) {
+			return map != null ? map(0) : -1;
+		}
+
+		var x:Int = method();
+	}
 }
 }
 
 
 private class FinalNullableFields {
 private class FinalNullableFields {