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

Surface.methodsOf - assertion failed: Tree had an unexpected owner for method #3367

Open
OndrejSpanel opened this issue Feb 5, 2024 · 1 comment
Labels

Comments

@OndrejSpanel
Copy link
Contributor

OndrejSpanel commented Feb 5, 2024

When building project from https://github.com/OndrejSpanel/Scala3KeyNotFound with -Xcheck-macros, an assertion is shown:

java.lang.AssertionError: assertion failed: Tree had an unexpected owner for method $anonfun
Expected: val __s001 (InjectScript$.ScriptX.$$__s001)
|But was: val macro (InjectScript$.ScriptX._$macro)

The project is:

import wvlet.airframe.surface.*

class InjectScript(x: Seq[MethodSurface])

class XParams[+T](params: Map[String, T])

object InjectScript {
  trait Params {
    def getParams: XParams[Unit]
  }

  class ScriptX extends InjectScript(Surface.methodsOf[Params])
}

When building without the option, Scala 3 compiler crashes (reported as scala/scala3#19575)

@xerial xerial added the bug label Feb 6, 2024
@xerial
Copy link
Member

xerial commented Feb 25, 2024

It seems a workaround is calling Surface.methodsOf[X] outside the constructor scope. For example:

  class InjectScript(x: Seq[MethodSurface])

  class XParams[+T](params: Map[String, T])

  trait Params {
    def getParams: XParams[Unit]
  }
  private def methods = Surface.methodsOf[Params]
  class ScriptX extends InjectScript(methods)

Surface.methodsOf[X] needs to generate several code blocks for building Surface classes, so calling it outside the constructor argument is recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants