Skip to content

Macro expansion fails if names of variables defined by macro end in $ #8533

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

Closed
scabug opened this issue Apr 24, 2014 · 7 comments
Closed

Macro expansion fails if names of variables defined by macro end in $ #8533

scabug opened this issue Apr 24, 2014 · 7 comments
Labels

Comments

@scabug
Copy link

scabug commented Apr 24, 2014

Such macro will compile, but fails to expand.

def aggregate[T: c.WeakTypeTag, S: c.WeakTypeTag](c: Context)(z: c.Expr[S])(combop: c.Expr[(S, S) => S])(seqop: c.Expr[(S, T) => S]): c.Expr[S] = {

      import c.universe._
      val t = q"""$
      var zero$$ = $z
      val seqop$$ = $seqop
      val comboop$$ = $combop
      for(el <- 1 to 10) zero$$ = seqop$$(zero$$, el)
      zero$$
      """
      c.Expr[S](c.untypecheck(t))
      }

Compiler stack trace https://gist.github.com/DarkDimius/cd3e49d4740ce52a7db8

Adding '0' suffix to names of variables is a workaround.

@scabug
Copy link
Author

scabug commented Apr 24, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8533?orig=1
Reporter: @DarkDimius
Affected Versions: 2.11.0
See #8425

@scabug
Copy link
Author

scabug commented Apr 24, 2014

@retronym said:
Sounds like a second helping of #8425.

@scabug
Copy link
Author

scabug commented Apr 24, 2014

@retronym said:
Using consecutive '$' in an identifier is pretty much suicide.

@scabug
Copy link
Author

scabug commented Apr 24, 2014

@DarkDimius said (edited on Apr 24, 2014 11:37:44 AM UTC):
AFAIK those wont end as consecutive '$$' as it's just a way to escape '$' inside string interpolators.

@scabug
Copy link
Author

scabug commented Apr 24, 2014

@retronym said:
Okay, it must be added elsewhere.

@scabug
Copy link
Author

scabug commented Apr 24, 2014

@retronym said:
PS: Because it is my hobby to point out fun issues with hygiene and quasiquotes, putting 1 to 10 in a quasiquote is unsafe as you can't be sure that the extension method to will always be the same one, it depends on the context of the call site. new *root*.....Range(1, 10) would be safer.

@SethTisue
Copy link
Member

closing all quasiquotes tickets; see #10755

(comment and/or reopen if I'm casting my net too wide here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants