Forráskód Böngészése

[nullsafety] allow checked captured locals in Loose mode (fixes #7853)

Alexander Kuzmenko 6 éve
szülő
commit
11de964d10
2 módosított fájl, 10 hozzáadás és 1 törlés
  1. 1 1
      src/typing/nullSafety.ml
  2. 9 0
      tests/nullsafety/src/cases/TestLoose.hx

+ 1 - 1
src/typing/nullSafety.ml

@@ -718,7 +718,7 @@ class local_safety (mode:safety_mode) =
 							traverse scopes
 						| _ -> false
 				in
-				not captured && self#get_current_scope#is_safe expr
+				(mode = SMLoose || not captured) && self#get_current_scope#is_safe expr
 		(**
 			This method should be called upon passing `while`.
 			It collects locals which are checked against `null` and executes callbacks for expressions with proper statuses of locals.

+ 9 - 0
tests/nullsafety/src/cases/TestLoose.hx

@@ -55,4 +55,13 @@ class TestLoose {
 			var notNullable:String = o.o2.field;
 		}
 	}
+
+	function checkedAgainstNullInLocalFunction_shouldPass(?callback:()->Void) {
+		function bar() {
+			if (callback != null) {
+				callback();
+			}
+		}
+		bar();
+	}
 }