Răsfoiți Sursa

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

Aleksandr Kuzmenko 4 ani în urmă
părinte
comite
6208c8733d

+ 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