Nested macros and constant parameter bug?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested macros and constant parameter bug?

sledorze
  @:macro public static function nested(nameToExpressions_ : String, exp : Expr) : Expr {
    return exp;
  }

  @:macro public static function test(x : Expr) : Expr {
    var toto = "toto";    
    return nested(toto, x);   // <----
  }


calling test macro generates the error below at the arrow line on the toto keyword.
src/com/mindrocks/macros/SubstMacro.hx:152: characters 18-22 : haxe.macro.Expr should be String

This is a nested call, doing it on a non nested code works.
Bug/Normal? Any idea?

Thanks,
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: Nested macros and constant parameter bug?

Juraj Kirchheim
I'm not sure why this would work with non-nested macros.

To my understanding a macro parameter set to a type other than
Expr/ExprRequire actually demands a constant.

On Tue, Nov 1, 2011 at 10:19 PM, sledorze <[hidden email]> wrote:

>  @:macro public static function nested(nameToExpressions_ : String, exp :
> Expr) : Expr {
>    return exp;
>  }
>
>  @:macro public static function test(x : Expr) : Expr {
>    var toto = "toto";
>    return nested(toto, x);   // <----
>  }
>
>
> calling test macro generates the error below at the arrow line on the toto
> keyword.
> src/com/mindrocks/macros/SubstMacro.hx:152: characters 18-22 :
> haxe.macro.Expr should be String
>
> This is a nested call, doing it on a non nested code works.
> Bug/Normal? Any idea?
>
> Thanks,
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Nested-macros-and-constant-parameter-bug-tp6953298p6953298.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Nested macros and constant parameter bug?

sledorze
Perhaps this is due to constant propagation..
Reply | Threaded
Open this post in threaded view
|

Re: Nested macros and constant parameter bug?

Juraj Kirchheim
Yes, but my point was, it shouldn't work ;)

On Tue, Nov 1, 2011 at 10:46 PM, sledorze <[hidden email]> wrote:

> Perhaps this is due to constant propagation..
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Nested-macros-and-constant-parameter-bug-tp6953298p6953374.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Nested macros and constant parameter bug?

sledorze
Yes indeed! got to make a bug report? (ahahha :) )
Reply | Threaded
Open this post in threaded view
|

Re: Nested macros and constant parameter bug?

Nicolas Cannasse
In reply to this post by sledorze
Le 01/11/2011 22:19, sledorze a écrit :

>    @:macro public static function nested(nameToExpressions_ : String, exp :
> Expr) : Expr {
>      return exp;
>    }
>
>    @:macro public static function test(x : Expr) : Expr {
>      var toto = "toto";
>      return nested(toto, x);   //<----
>    }
>
>
> calling test macro generates the error below at the arrow line on the toto
> keyword.
> src/com/mindrocks/macros/SubstMacro.hx:152: characters 18-22 :
> haxe.macro.Expr should be String

This is perfectly normal : when you ask for a typed a macro parameter a
compile-time constant is required, because we could not pass it the
value "toto" without actually executing your test() function.
(which is not yet done since we are currently _typing_ this method)

If you want to restrict the type of expressions that you can pass to the
macros (so you don't have to do type checks again inside your nested
macro) you can use ExprRequire<String> instead. But that will still be
an Expr that you're receiving as parameter in your macro.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org