Ver código fonte

[macro] type-hint MacroStringTools.formatString (fixes #9928)

Aleksandr Kuzmenko 4 anos atrás
pai
commit
c0ef0ae1a6

+ 1 - 0
extra/CHANGES.txt

@@ -5,6 +5,7 @@
 	jvm : fixed equality checks for `Null<Float>` and `Null<Int>` (#9897)
 	hl : fixed crash if a thread finishes without invoking `sendMessage`/`readMessage` (#9920)
 	php : fixed local vars with certain names (_SERVER, _GET etc) overriding super global values (#9924)
+	macro : added return type hint to haxe.macro.MacroStringTools.formatString (#9928)
 
 2020-09-11 4.1.4:
 

+ 1 - 1
std/haxe/macro/MacroStringTools.hx

@@ -39,7 +39,7 @@ class MacroStringTools {
 		The returned expression is a concatenation of string parts and escaped
 		elements.
 	**/
-	static public function formatString(s:String, pos:Position) {
+	static public function formatString(s:String, pos:Position):Expr {
 		#if (neko || eval)
 		return Context.load("format_string", 2)(s, pos);
 		#end

+ 19 - 0
tests/unit/src/unit/issues/Issue9928.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+#if !macro
+class Issue9928 extends unit.Test {
+	function test() {
+		var w = Std.random(10);
+		eq('hello $w', format('hello $w'));
+	}
+
+	macro static function format(s:String):haxe.macro.Expr;
+}
+#else
+class Issue9928 extends unit.Test {
+	macro static function format(s:String):haxe.macro.Expr {
+		var p = haxe.macro.Context.currentPos();
+		var ed:{expr:haxe.macro.Expr.ExprDef} = haxe.macro.MacroStringTools.formatString(s, p);
+		return haxe.macro.MacroStringTools.formatString(s, p);
+	}
+}
+#end