Przeglądaj źródła

[nullsafety] fixed field access on a block with nullable var declared inside

Aleksandr Kuzmenko 5 lat temu
rodzic
commit
d14884ac65

+ 1 - 1
extra/CHANGES.txt

@@ -17,7 +17,7 @@
 	std : fixed an exception from `haxe.zip.Huffman` on reading a zip (#8875)
 	windows : workaround windows installer being detected as a malware by some anti-virus software (#8951)
 	windows : fix PATH env var modification when running windows installer without admin privileges (#8870)
-
+	all : fixed null-safety checker for field access on a call to inlined function
 
 2019-11-11: 4.0.2
 

+ 1 - 1
src/typing/nullSafety.ml

@@ -1281,9 +1281,9 @@ class expr_checker mode immediate_execution report =
 			Make sure nobody tries to access a field on a nullable value
 		*)
 		method private check_field target access p =
+			self#check_expr target;
 			if self#is_nullable_expr target then
 				self#error ("Cannot access \"" ^ accessed_field_name access ^ "\" of a nullable value.") [p; target.epos];
-			self#check_expr target
 		(**
 			Check constructor invocation: don't pass nulable values to not-nullable arguments
 		*)

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

@@ -876,6 +876,18 @@ class TestStrict {
 		}
 	}
 
+	static function fieldAccess_onBlockWithSafeVarDeclaredInside_shouldPass(?a:String) {
+		var fn = function() {
+			({
+				var value = a;
+				if(value == null)
+					'hello'
+				else
+					value;
+			}).length;
+		}
+	}
+
 	static function issue8122_abstractOnTopOfNullable() {
 		var x:NullFloat = null;
 		var y:Float = x.val();