2

I have a Symbol and want to check if it's visible at the point of macro expansion or shadowed (e.g. by a local variable), so that splicing the symbol's name in the quasiquote doesn't refer to something else.

Looking at http://docs.scala-lang.org/overviews/reflection/annotations-names-scopes.html, one idea would be to look at the enclosing lexical scopes and check if they contain a symbol with the same name; the problem is that I can't find a way to obtain the directly enclosing scope for the macro.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

0

Solution based on som-snytt's reply on scala-user:

symbol.pos == c.typecheck(q"${symbol.name.toTermName}").symbol.pos

(I had to compare positions, because in one of my tests the symbols weren't equal despite having the same name, owner and position.)

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487