Sfoglia il codice sorgente

[nullsafety] Some inline api fixes (#12210)

RblSb 4 mesi fa
parent
commit
b4b99d6004

+ 1 - 1
src/optimization/inline.ml

@@ -268,7 +268,7 @@ let inline_config cls_opt cf call_args return_type =
 let inline_metadata e meta =
 	let inline_meta e meta = match meta with
 		| Meta.Pure,[EConst(Ident "inferredPure"),_],_ -> e
-		| (Meta.Deprecated | Meta.Pure),_,_ -> mk (TMeta(meta,e)) e.etype e.epos
+		| (Meta.Deprecated | Meta.Pure | Meta.NullSafety),_,_ -> mk (TMeta(meta,e)) e.etype e.epos
 		| _ -> e
 	in
 	List.fold_left inline_meta e meta

+ 1 - 0
std/haxe/iterators/DynamicAccessIterator.hx

@@ -46,6 +46,7 @@ class DynamicAccessIterator<T> {
 	/**
 		See `Iterator.next`
 	**/
+	@:nullSafety(Off)
 	public inline function next():T {
 		return access[keys[index++]];
 	}

+ 1 - 0
std/haxe/iterators/DynamicAccessKeyValueIterator.hx

@@ -46,6 +46,7 @@ class DynamicAccessKeyValueIterator<T> {
 	/**
 		See `Iterator.next`
 	**/
+	@:nullSafety(Off)
 	public inline function next():{key:String, value:T} {
 		var key = keys[index++];
 		return {value: (access[key] : T), key: key};

+ 1 - 0
std/python/_std/EReg.hx

@@ -51,6 +51,7 @@ class EReg {
 	}
 
 	public inline function match(s:String):Bool {
+		@:nullSafety(Off)
 		matchObj = Re.search(pattern, s);
 		return matchObj != null;
 	}

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

@@ -45,6 +45,12 @@ class UnsafeFields {
 		var s:String = null;
 	}
 
+	@:nullSafety(Off)
+	public static inline function unsafeCall():Int {
+		var n:Int = null;
+		return n;
+	}
+
 	static function unsafeExpr() {
 		var s:String;
 		@:nullSafety(Off) cast(null, String);
@@ -1052,6 +1058,23 @@ class TestStrict {
 	static function issue10272_nullableConcatString_shouldPass(msg:Null<Dynamic>) {
 		trace("Message: " + msg);
 	}
+
+	static function inlineUnsafeCall_shouldPass(msg:Null<Dynamic>) {
+		final v = UnsafeFields.unsafeCall();
+		final obj = new haxe.DynamicAccess<String>();
+		for (v in obj) obj["foo"] = v;
+		for (i => v in obj) obj["foo"] = v;
+	}
+
+	public static function overloadNullableArgs_shouldPass(cmd:String, ?args:Array<String>):Int {
+		if (args == null)
+			return spawnSome(cmd, {shell: true, stdio: "inherit"}).status;
+		else
+			return spawnSome(cmd, args, {stdio: "inherit"}).status;
+	}
+
+	@:overload(function(command:String, args:Array<String>, ?options:{}):{status:Int} {})
+	static function spawnSome(command:String, ?options:{}):{status:Int} return {status: 0};
 }
 
 private class AnonFields {