Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definition of haxe.macro.Type.AbstractType.unops is wrong #10641

Closed
saharan opened this issue Mar 24, 2022 · 0 comments
Closed

Type definition of haxe.macro.Type.AbstractType.unops is wrong #10641

saharan opened this issue Mar 24, 2022 · 0 comments

Comments

@saharan
Copy link
Contributor

saharan commented Mar 24, 2022

The standard library says its type is Array<{op:Expr.Unop, postFix:Bool, field:ClassField}>, but actually is not.
The type definition should be Array<{op:Expr.Unop, isPostfix:Bool, field:ClassField}>, or the corresponding part of macroApi.ml should be corrected accordingly.

"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);

Test code:

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: [],
		name: "Test",
		sub: "A"
	}));
	switch type {
		case TAbstract(_.get() => t, params):
			final unop = t.unops[0];
			for (unop in t.unops) {
				trace("--");
				trace(unop.op);
				trace(unop.postFix);
				trace(untyped unop.isPostfix);
				trace(unop.field.name);
			}
		case _:
	}
	return macro {};
	#end
}

class Test {
	static function main() {
		check();
	}
}

Compiler output:

Test.hx:20: --
Test.hx:21: OpIncrement
Test.hx:22: null
Test.hx:23: true
Test.hx:24: preInc
Test.hx:20: --
Test.hx:21: OpIncrement
Test.hx:22: null
Test.hx:23: false
Test.hx:24: postInc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant