Skip to content
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

Packaged macro that accesses protected definitions emits access errors #12948

Closed
soronpo opened this issue Jun 26, 2021 · 2 comments · Fixed by #13188
Closed

Packaged macro that accesses protected definitions emits access errors #12948

soronpo opened this issue Jun 26, 2021 · 2 comments · Fixed by #13188
Assignees
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Jun 26, 2021

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.

@dwijnand
Copy link
Member

Looking at the "Semantics-Preserving Inlining for Metaprogramming" it's correct that Main.fooCaller works and I agree Main.fooCallerM should work exactly the same.

@nicolasstucki
Copy link
Contributor

Yes, it should work. We should use part of what is in PrepareInlineable to make those definitions accessible inside quoted code.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 28, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 28, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 29, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 30, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 2, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
tanishiking pushed a commit to tanishiking/scala3 that referenced this issue Aug 10, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants