Browse Source

[nullsafety] respect @:nullSafety(false) meta on getters/setters

Alexander Kuzmenko 6 years ago
parent
commit
31ab7ebbe7
2 changed files with 12 additions and 4 deletions
  1. 8 4
      src/typing/nullSafety.ml
  2. 4 0
      tests/nullsafety/src/cases/Test.hx

+ 8 - 4
src/typing/nullSafety.ml

@@ -1244,10 +1244,14 @@ class class_checker cls immediate_execution report  =
 							with Not_found -> None
 							with Not_found -> None
 						in
 						in
 						match accessor with
 						match accessor with
-							| Some { cf_expr = Some ({ eexpr = TFunction fn } as accessor_expr) } ->
-								let fn = { fn with tf_type = field.cf_type } in
-								checker#check_root_expr { accessor_expr with eexpr = TFunction fn }
-							| _ -> ()
+							| None -> ()
+							| Some accessor ->
+								if self#is_in_safety accessor then
+									match accessor.cf_expr with
+										| Some ({ eexpr = TFunction fn } as accessor_expr) ->
+											let fn = { fn with tf_type = field.cf_type } in
+											checker#check_root_expr { accessor_expr with eexpr = TFunction fn }
+										| _ -> ()
 					in
 					in
 					if read_access = AccCall then check_accessor "get_";
 					if read_access = AccCall then check_accessor "get_";
 					if write_access = AccCall then check_accessor "set_"
 					if write_access = AccCall then check_accessor "set_"

+ 4 - 0
tests/nullsafety/src/cases/Test.hx

@@ -45,6 +45,10 @@ class UnsafeFields {
 		var s:String;
 		var s:String;
 		@:nullSafety(false) cast(null, String);
 		@:nullSafety(false) cast(null, String);
 	}
 	}
+
+	var str(get,set):String;
+	@:nullSafety(false) function get_str() return (null:Null<String>);
+	@:nullSafety(false) function set_str(v) return (v:Null<String>);
 }
 }
 
 
 /** Test `@:nullSafety(false)` is respected on a class */
 /** Test `@:nullSafety(false)` is respected on a class */