Browse Source

[nullsafety] not all optional args are nullable (fixes #7925)

Aleksandr Kuzmenko 6 years ago
parent
commit
caced379f6
2 changed files with 7 additions and 1 deletions
  1. 1 1
      src/typing/nullSafety.ml
  2. 6 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 1 - 1
src/typing/nullSafety.ml

@@ -1284,7 +1284,7 @@ class expr_checker mode immediate_execution report =
 		method private check_args ?(arg_num=0) callee args types =
 			match (args, types) with
 				| (arg :: args, (arg_name, optional, t) :: types) ->
-					if not optional && not (self#can_pass_expr arg t arg.epos) then begin
+					if not (self#can_pass_expr arg t arg.epos) then begin
 						let fn_str = match symbol_name callee with "" -> "" | name -> " of function \"" ^ name ^ "\""
 						and arg_str = if arg_name = "" then "" else " \"" ^ arg_name ^ "\"" in
 						self#error ("Cannot pass nullable value to not-nullable argument" ^ arg_str ^ fn_str ^ ".") [arg.epos; callee.epos]

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

@@ -206,6 +206,12 @@ class TestStrict {
 		fn(v);
 	}
 
+	static function call_nullableValueToOptionalNonNullableArgument_shouldFail() {
+		var fn = function(s:String = "") {}
+		var v:Null<String> = null;
+		shouldFail(fn(v));
+	}
+
 	static public function new_nullableValueToNotNullableArgument_shouldFail(?v:String) {
 		shouldFail(new TestStrict(v));
 	}