Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Lose experimental scope while macro implementation has private/protected modifier #16091

Closed
jilen opened this issue Sep 23, 2022 · 2 comments · Fixed by #16099
Closed

Lose experimental scope while macro implementation has private/protected modifier #16091

jilen opened this issue Sep 23, 2022 · 2 comments · Fixed by #16099

Comments

@jilen
Copy link

jilen commented Sep 23, 2022

Compiler version

3.2.0

Minimized code

import scala.quoted._
import scala.annotation.experimental

trait Foo {}

object Macro {
 @experimental
  inline def foo() = ${ fooImpl }

  @experimental
  private def fooImpl(using Quotes) = {
    import quotes.reflect._
    val name: String = "TestFoo"
    val parents = List(TypeTree.of[Object])
    val cls = Symbol.newClass(
      Symbol.spliceOwner,
      name,
      parents = parents.map(_.tpe),
      _ => Nil,
      selfType = None
    )
    '{
      new Foo {}
    }
  }
}

Output

Report error

method fooImpl is marked @experimental and therefore may only be used in an experimental scope.

Expectation

private def fooImpl(using Quotes) = ...

Without private modifier, this example compiles (even without @experimental at call site.).
Should be same with private modifier.

@jilen jilen added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 23, 2022
@jchyb
Copy link
Contributor

jchyb commented Sep 23, 2022

I managed to minimize the code further:

import scala.annotation.experimental

object Macro {
  @experimental
  inline def foo() = fooImpl

  @experimental
  private def fooImpl = ()
}

It seems that the mix of inline + private is the root of this. When reproducing on the dotty main branch it's worth to remember to enable the -Yno-experimental option, otherwise everything is in experimental scope and the error does not show (probably obvious to most, but I managed to make the mistake)

@jchyb jchyb added area:inline area:experimental and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 23, 2022
@odersky
Copy link
Contributor

odersky commented Sep 26, 2022

Nice minimization!

Inlined private methods get inline accessors. I believe that's the source of the problem.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants