浏览代码

[nullsafety] respect @:nullSafety(Off) in closures in constructors
closes #9643

Aleksandr Kuzmenko 5 年之前
父节点
当前提交
f21fbca233
共有 3 个文件被更改,包括 15 次插入1 次删除
  1. 1 0
      extra/CHANGES.txt
  2. 1 1
      src/typing/nullSafety.ml
  3. 13 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	flash : fixed var shadowing issue for variables captured in a closure inside of a loop (#9624)
+	nullsafety: fixed `@:nullSafety(Off)` in closures inside of constructors (#9643)
 	nullsafety: fixed "Type not found NullSafetyMode_Impl_" (#9483)
 
 2020-06-19 4.1.2

+ 1 - 1
src/typing/nullSafety.ml

@@ -1608,7 +1608,7 @@ class class_checker cls immediate_execution report =
 							List.iter (check_unsafe_usage init_list safety_enabled) args
 						| TConst TThis when safety_enabled ->
 							checker#error "Cannot use \"this\" until all instance fields are initialized." [e.epos]
-						| TLocal v when Hashtbl.mem this_vars v.v_id ->
+						| TLocal v when safety_enabled && Hashtbl.mem this_vars v.v_id ->
 							checker#error "Cannot use \"this\" until all instance fields are initialized." [e.epos]
 						| TMeta ((Meta.NullSafety, [(EConst (Ident "Off"), _)], _), e) ->
 							iter (check_unsafe_usage init_list false) e

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

@@ -78,6 +78,19 @@ private class TestWithoutConstructor {
 	@:shouldFail var notInitializedField:String;
 }
 
+class Issue9643 {
+	static var tmp:Null<()->Void>;
+
+	final field: String;
+
+	public function new() {
+		tmp = () -> @:nullSafety(Off) method();
+		field = 'hello';
+	}
+
+	function method() {}
+}
+
 class AllVarsInitializedInConstructor_weHaveClosure_thisShouldBeUsable {
 	var v:Int;