Skip to content

Cannot get methodsOf for some generic types, esp. in Scala 3 #3433

@OndrejSpanel

Description

@OndrejSpanel

Using following source file all tests fail in Scala 3, and test with ScriptingContext[_] fails even with Scala 2:

  type EvalFunction1[T] = scala.Function1[T, Any]

  class ScriptingContext[X] {
    def func(): Int = ???
    def `then`(f: EvalFunction1[X]): ScriptingContext[Any] = ???
  }

  class SC extends ScriptingContext[Int]

  test("Support generic classes") {
    Surface.of[ScriptingContext[Int]]
    val methods = Surface.methodsOf[ScriptingContext[Int]]
    val methodNames = methods.map(_.name)
    methodNames shouldContain "func"
    methodNames shouldContain "then"
  }

  test("Support generic classes 2") {
    Surface.of[SC]
    val methods = Surface.methodsOf[SC]
    val methodNames = methods.map(_.name)
    methodNames shouldContain "func"
    methodNames shouldContain "then"
  }

  test("Support generic classes 3") {
    Surface.of[ScriptingContext[_]]
    val methods = Surface.methodsOf[ScriptingContext[_]]
    val methodNames = methods.map(_.name)
    methodNames shouldContain "func"
    methodNames shouldContain "then"
  }

Scala 3 compile error are:

Found: wvlet.airframe.surface.i3418.EvalFunction1[X]
Required: wvlet.airframe.surface.i3418.EvalFunction1[Int]

And:

Found: wvlet.airframe.surface.i3418.EvalFunction1[X]
Required: wvlet.airframe.surface.i3418.EvalFunction1[
wvlet.airframe.surface.i3418.ScriptingContext[?]#X]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions