Sfoglia il codice sorgente

[nullSafety] only process fields that do not have CfPostProcessed flag (#11185)

* [nullSafety] only process fields that do not have CfPostProcessed flag

* [tests] add test for 11179
Rudy Ges 2 anni fa
parent
commit
43844ae8be

+ 2 - 2
src/typing/nullSafety.ml

@@ -1498,7 +1498,7 @@ class class_checker cls immediate_execution report =
 			validate_safety_meta report cls_meta;
 			if is_safe_class && (not (has_class_flag cls CExtern)) && (not (has_class_flag cls CInterface)) then
 				self#check_var_fields;
-			let check_field is_static f =
+			let check_field is_static f = if not (has_class_field_flag f CfPostProcessed) then begin
 				validate_safety_meta report f.cf_meta;
 				match (safety_mode (cls_meta @ f.cf_meta)) with
 					| SMOff -> ()
@@ -1509,7 +1509,7 @@ class class_checker cls immediate_execution report =
 								(self#get_checker mode)#check_root_expr expr
 						);
 						self#check_accessors is_static f
-			in
+			end in
 			if is_safe_class then
 				Option.may ((self#get_checker (safety_mode cls_meta))#check_root_expr) cls.cl_init;
 			Option.may (check_field false) cls.cl_constructor;

+ 7 - 0
tests/server/src/cases/ServerTests.hx

@@ -243,7 +243,14 @@ class ServerTests extends TestCase {
 		vfs.touchFile("haxe/ds/Vector.hx");
 		runHaxe(args);
 		assertSuccess();
+	}
 
+	function test11179() {
+		vfs.putContent("Main.hx", getTemplate("issues/Issue11179/Main.hx"));
+		var args = ["-main", "Main", "--macro", 'nullSafety("Main", Strict)', "--interp"];
+		runHaxe(args);
+		runHaxe(args);
+		assertSuccess();
 	}
 
 	// See https://github.com/HaxeFoundation/haxe/issues/8368#issuecomment-525379060

+ 22 - 0
tests/server/test/templates/issues/Issue11179/Main.hx

@@ -0,0 +1,22 @@
+class Main {
+	final prev:Null<A> = null;
+	var nextChar = TriState.UNKNOWN;
+
+	function new() {
+		final prevChar = @:nullSafety(Off) prev.get();
+		try {} catch (ex:String) nextChar = FALSE;
+	}
+
+	static function main() {}
+}
+
+abstract A(Bool) {
+	inline public function get():Int return _get();
+	function _get():Int return 1;
+}
+
+enum abstract TriState(Null<Bool>) from Null<Bool> to Null<Bool> {
+	final TRUE = true;
+	final FALSE = false;
+	final UNKNOWN = null;
+}