Parcourir la source

rename @:safety to @:nullSafety

Alexander Kuzmenko il y a 6 ans
Parent
commit
83d9c11a2b

+ 2 - 2
src/core/meta.ml

@@ -142,7 +142,7 @@ type strict_meta =
 	| Rtti
 	| Runtime
 	| RuntimeValue
-	| Safety
+	| NullSafety
 	| Scalar
 	| SelfCall
 	| Semantics
@@ -345,7 +345,7 @@ let get_info = function
 	| Rtti -> ":rtti",("Adds runtime type information",[UsedOn TClass])
 	| Runtime -> ":runtime",("?",[])
 	| RuntimeValue -> ":runtimeValue",("Marks an abstract as being a runtime value",[UsedOn TAbstract])
-	| Safety -> ":safety",("Enables null safety for classes or disables null safety for classes or fields if provided with `false` as an argument (e.g. `@:safety(false)`)",[UsedOnEither [TClass;TClassField]])
+	| NullSafety -> ":nullSafety",("Enables null safety for classes or disables null safety for classes or fields if provided with `false` as an argument (e.g. `@:nullSafety(false)`)",[UsedOnEither [TClass;TClassField]])
 	| Scalar -> ":scalar",("Used by hxcpp to mark a custom coreType abstract",[UsedOn TAbstract; Platform Cpp])
 	| SelfCall -> ":selfCall",("Translates method calls into calling object directly",[UsedOn TClassField; Platforms [Js;Lua]])
 	| Semantics -> ":semantics",("The native semantics of the type",[UsedOnEither [TClass;TTypedef;TAbstract];HasParam "value | reference | variable"])

+ 5 - 5
src/typing/nullSafety.ml

@@ -326,22 +326,22 @@ let process_condition condition (is_nullable_expr:texpr->bool) callback =
 	(!nulls, !not_nulls)
 
 (**
-	Check if metadata contains @:safety(false) meta
+	Check if metadata contains @:nullSafety(false) meta
 **)
 let rec contains_unsafe_meta metadata =
 	match metadata with
 		| [] -> false
-		| (Meta.Safety, [(EConst (Ident "false"), _)], _) :: _  -> true
+		| (Meta.NullSafety, [(EConst (Ident "false"), _)], _) :: _  -> true
 		| _ :: rest -> contains_unsafe_meta rest
 
 (**
-	Check if metadata contains @:safety or @:safety(true) meta
+	Check if metadata contains @:nullSafety or @:nullSafety(true) meta
 **)
 let rec contains_safe_meta metadata =
 	match metadata with
 		| [] -> false
-		| (Meta.Safety, [], _) :: _
-		| (Meta.Safety, [(EConst (Ident "true"), _)], _) :: _  -> true
+		| (Meta.NullSafety, [], _) :: _
+		| (Meta.NullSafety, [(EConst (Ident "true"), _)], _) :: _  -> true
 		| _ :: rest -> contains_safe_meta rest
 
 (**

+ 8 - 8
tests/nullsafety/src/cases/Test.hx

@@ -31,12 +31,12 @@ typedef AnonAsStruct = {
 	?optional:String
 }
 
-/** Test `@:safety(false)` is respected on fields */
+/** Test `@:nullSafety(false)` is respected on fields */
 class UnsafeFields {
-	@:safety(false) var unsafeVar:String = null;
-	@:safety(false) var notInitializedField:String;
+	@:nullSafety(false) var unsafeVar:String = null;
+	@:nullSafety(false) var notInitializedField:String;
 
-	@:safety(false)
+	@:nullSafety(false)
 	static function unsafeMethod() {
 		var s:String = null;
 	}
@@ -47,8 +47,8 @@ class UnsafeFields {
 	}
 }
 
-/** Test `@:safety(false)` is respected on a class */
-@:safety(false)
+/** Test `@:nullSafety(false)` is respected on a class */
+@:nullSafety(false)
 class UnsafeClass {
 	var uninitializedVar:String;
 
@@ -59,12 +59,12 @@ class UnsafeClass {
 	function doStuff(t:UnsafeClass) {}
 }
 
-/** Test `@:safety(false)` on a constructor. And that it does not disable safety checks for instance vars */
+/** Test `@:nullSafety(false)` on a constructor. And that it does not disable safety checks for instance vars */
 @:build(Validator.checkFields())
 class UnsafeConstructor {
 	@:shouldFail var uninitializedVar:String;
 
-	@:safety(false)
+	@:nullSafety(false)
 	public function new() {
 		var s:String = null;
 	}

+ 1 - 1
tests/nullsafety/test.hxml

@@ -2,5 +2,5 @@
 -main cases.Test
 -D analyzer-optimize
 
---macro addGlobalMetadata('cases', '@:safety')
+--macro addGlobalMetadata('cases', '@:nullSafety')
 --macro Validator.register()