Skip to content

Macros don't warn against visibility issues #6003

Closed
@scabug

Description

@scabug

I was playing with this macro and this example, and wondered about the wildcard import. That makes the macro definition itself visible, which might not be desirable. At that point, I wondered what would happen if that definition was made private. The results I got were:

  1. There was no complain at trace that traceImpl was private, or vice versa.

  2. When I tried to use trace, I got this:

scala> trace(2 + x)
<console>:12: error: exception during macro expansion: 
java.lang.IllegalAccessException: Class scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroRuntime$2 can not access a member of class Macros$ with modifiers "private"

Now, I don't see any situation where a private macro definition might make sense. If I understand it correctly, it will always be the compiler calling them, which makes it important not only that they are static, as is already complained about, but that they are public.

In which case, an error message is in order.

As a side note, the fact that I can't envision any situation where a different visibility makes sense is making me unease. I sense that there's some design issue there I can't quite put a finger on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions