فهرست منبع

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

Aleksandr Kuzmenko 5 سال پیش
والد
کامیت
555c915334
2فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 1 1
      src/typing/nullSafety.ml
  2. 12 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 1 - 1
src/typing/nullSafety.ml

@@ -1317,9 +1317,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 nullable values to not-nullable arguments
 		*)

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

@@ -898,6 +898,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();