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

Warnings for macro-in-macro. #7348

Closed
back2dos opened this issue Aug 13, 2018 · 12 comments
Closed

Warnings for macro-in-macro. #7348

back2dos opened this issue Aug 13, 2018 · 12 comments
Assignees

Comments

@back2dos
Copy link
Member

Until macro-in-macro is properly supported, we should warn when it's used (personally I wouldn't mind an error). It would go a long way to make things easier for newcomers. I've lost count of how many times I saw some variant of this problem: https://community.haxe.org/t/injecting-a-local-variable-with-macro/953

@jdonaldson
Copy link
Member

Are all of the problems here due to macros containing macros in the same file? I'm wondering if we could just detect that somehow and give a more specific error for that.

@Simn Simn self-assigned this Aug 14, 2018
@Simn
Copy link
Member

Simn commented Aug 14, 2018

We have an option to show macro-in-macro by using -D macro-debug. Of course that doesn't actually help you unless you know that macro-in-macro is your problem in the first place.

@Simn
Copy link
Member

Simn commented Sep 6, 2018

If we add a warning for this we also need a way to avoid the warning in case you genuinely want to have a macro-in-macro call.

@back2dos
Copy link
Member Author

back2dos commented Sep 6, 2018

Ok, more drastic then: How about forbidding it to see if anybody complains? Since macro-in-macro busts the cache, I doubt anybody would "genuinely want to have a macro-in-macro call" other than for some funky experiments. It creates way more problems than it solves.

@Simn
Copy link
Member

Simn commented Sep 28, 2018

I'm experimenting with this, but our mutual friend haxelib gets in the way because of this:

class Main {
	static var VERSION:SemVer = SemVer.ofString(getHaxelibVersion());
	static var VERSION_LONG:String = getHaxelibVersionLong();

	macro static function getHaxelibVersion() {
		var haxelibJson:Infos = Json.parse(File.getContent("haxelib.json"));
		return macro $v{haxelibJson.version};
	}

	macro static function getHaxelibVersionLong() {
		var version:String = VERSION;

@back2dos
Copy link
Member Author

How about #if-fencing it in haxelib then?

@Simn
Copy link
Member

Simn commented Sep 28, 2018

That won't be enough because there's some legit macro-in-macro handling going because macro getHaxelibVersionLong works with VERSION which is initialized using a macro call.

@back2dos
Copy link
Member Author

Without further ado I present to you: #if !macro macro #end

@Simn
Copy link
Member

Simn commented Sep 28, 2018

That still won't do because.... you know what, how about you just fix it? :P

@back2dos
Copy link
Member Author

I'll do my best, but I have no way of knowing if it's fixed, do I? :P

@Simn
Copy link
Member

Simn commented Sep 28, 2018

-D check-macro should not give warnings.

Although the way it's implemented right now is not ideal. It warns when typing a macro-in-macro, which is not necessary. We only care about it if we actually call such a macro.

@Simn
Copy link
Member

Simn commented Sep 28, 2018

I meant -D macro-debug

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

3 participants