Browse Source

[macro] fix abstract unop naming

closes #10641
Simon Krajewski 3 năm trước cách đây
mục cha
commit
ffb8d24e99
2 tập tin đã thay đổi với 41 bổ sung1 xóa
  1. 1 1
      src/macro/macroApi.ml
  2. 40 0
      tests/unit/src/unit/issues/Issue10641.hx

+ 1 - 1
src/macro/macroApi.ml

@@ -921,7 +921,7 @@ and encode_tabstract a =
 		"type", encode_type a.a_this;
 		"impl", (match a.a_impl with None -> vnull | Some c -> encode_clref c);
 		"binops", encode_array (List.map (fun (op,cf) -> encode_obj [ "op",encode_binop op; "field",encode_cfield cf]) a.a_ops);
-		"unops", encode_array (List.map (fun (op,postfix,cf) -> encode_obj [ "op",encode_unop op; "isPostfix",vbool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
+		"unops", encode_array (List.map (fun (op,postfix,cf) -> encode_obj [ "op",encode_unop op; "postFix",vbool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
 		"from", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_from) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_from_field));
 		"to", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_to) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_to_field));
 		"array", encode_array (List.map encode_cfield a.a_array);

+ 40 - 0
tests/unit/src/unit/issues/Issue10641.hx

@@ -0,0 +1,40 @@
+package unit.issues;
+
+private abstract A(Int) from Int {
+	@:op(A++)
+	function preInc():Void;
+
+	@:op(++A)
+	function postInc():Void;
+}
+
+macro function check() {
+	#if macro
+	final type = haxe.macro.ComplexTypeTools.toType(TPath({
+		pack: ["unit", "issues"],
+		name: "Issue10641",
+		sub: "A"
+	}));
+	var acc = [];
+	function add(s:String) {
+		acc.push(s);
+	}
+	switch type {
+		case TAbstract(_.get() => t, params):
+			final unop = t.unops[0];
+			for (unop in t.unops) {
+				add("" + unop.op);
+				add("" + unop.postFix);
+				add(unop.field.name);
+			}
+		case _:
+	}
+	return macro $v{acc.join(" ")};
+	#end
+}
+
+class Issue10641 extends unit.Test {
+	public function test() {
+		eq("OpIncrement true preInc OpIncrement false postInc", check());
+	}
+}