Skip to content

Commit

Permalink
[macro] fix abstract unop naming
Browse files Browse the repository at this point in the history
closes #10641
  • Loading branch information
Simn committed Mar 26, 2022
1 parent efaeae7 commit ffb8d24
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/macro/macroApi.ml
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions 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());
}
}

0 comments on commit ffb8d24

Please sign in to comment.