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

Possible to use @:await inside expression macros? #13

Open
kevinresol opened this issue Aug 24, 2016 · 3 comments
Open

Possible to use @:await inside expression macros? #13

kevinresol opened this issue Aug 24, 2016 · 3 comments

Comments

@kevinresol
Copy link
Member

kevinresol commented Aug 24, 2016

// Main.hx
@:await
class Main {
    @:await static function main() {
      var s:String = Macro.expr();
    }

    @:async static function string() return 'hi';
}

// Macro.hx
class Macro {
    public static macro function expr() {
        return macro @:await string();
    }
}

The above code won't work because the await macro runs first. After that the typer kicks in and transform the macro call to actual expression. As a result, the generated expression (@:await string()) won't get handled by the await macro.

So, are there any workarounds for that?

@kevinresol
Copy link
Member Author

kevinresol commented Aug 24, 2016

Is it possible to have a "expression-level" version of tink_await. That I can apply the transformation with a macro call? like so:

var surprise = Await.manuallyTransform({
  // my block of code:
  @:await string();
});

public macro static function manuallyTransform(expr:Expr) {...}

@kevinresol
Copy link
Member Author

kevinresol commented Aug 24, 2016

The above example won't work because even so the outer macro will run first (if I supply a macro call as its parameter)

However, if somehow we can manually execute an expression macro, it may work. HaxeFoundation/haxe#5534

@benmerckx
Copy link
Member

Well, I had a look at that when #10 popped up. Seems like expression macros run when you use Context.typeExpr on an expression. But it only worked when applied to every expression, not the full body. It also failed multiple times with errors I couldn't catch. Anyway, that's when I gave up :) So we'll have to wait until haxe gives us a proper way to run all expression macros during type building.

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

2 participants