소스 검색

[nullsafety] handle `(function() expr)()`

Aleksandr Kuzmenko 6 년 전
부모
커밋
2ff0d6b252
2개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      src/typing/nullSafety.ml
  2. 6 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 6 - 1
src/typing/nullSafety.ml

@@ -1282,7 +1282,12 @@ class expr_checker mode immediate_execution report =
 		method private check_call callee args p =
 			if self#is_nullable_expr callee then
 				self#error "Cannot call a nullable value." [callee.epos; p];
-			self#check_expr callee;
+			(match callee.eexpr with
+				| TFunction fn | TParenthesis { eexpr = TFunction fn } ->
+					self#check_function ~immediate_execution:true fn
+				| _ ->
+					self#check_expr callee
+			);
 			match follow callee.etype with
 				| TFun (types, _) ->
 					self#check_args callee args types

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

@@ -869,6 +869,12 @@ class TestStrict {
 			({a: 0, b: i} : {a:Int, b: Int});
 		}
 	}
+
+	static function immediateFunction_keepsSafety(?s:String) {
+		if (s != null) {
+			(function() s.length)();
+		}
+	}
 }
 
 private class FinalNullableFields {