Skip to content

Packaged macro that accesses protected definitions emits access errors #12948

Closed
@soronpo

Description

@soronpo

Access modifiers are treated transparently through a packaged macro inlining, so a a protected method that is not protected for the macro itself is still considered protected when inlined and we get illegal access error.

Compiler version

v3.0.1-RC2 (also tested on nightly)

Minimized code

See minimized project at: https://github.com/soronpo/dottybug/tree/inline_illegal_access

mylib/Main.scala

package mylib
import scala.quoted.*

object Main:
  protected def foo: Unit = {}
  inline def fooCaller: Unit = foo
  inline def fooCallerM: Unit = ${ fooMacro }
  def fooMacro(using Quotes): Expr[Unit] =
    '{ foo }

Test.scala

import mylib.Main

object Test:
  Main.fooCaller //works
  Main.fooCallerM //error

Output

[error] -- Error: C:\IdeaProjects\dottybug\src\main\scala\Test.scala:5:7 ------------------------------------------------------------
[error] 5 |  Main.fooCallerM
[error]   |  ^^^^^^^^^^^^^^^
[error]   |  illegal access to protected method foo in object Main from object Test
[error]   | This location contains code that was inlined from Main.scala:9
[error]   | This location contains code that was inlined from Main.scala:9
[error] one error found

Expectation

No error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions