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

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

Open
OndrejSpanel opened this issue Mar 1, 2024 · 1 comment
Open

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

OndrejSpanel opened this issue Mar 1, 2024 · 1 comment

Comments

@OndrejSpanel
Copy link
Contributor

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]

@OndrejSpanel
Copy link
Contributor Author

OndrejSpanel commented Mar 2, 2024

This is in principle a lot similar to #3411, maybe also to #3418

I start wondering: where exactly is the type mismatch happening? It would not be that bad if inaccurate method parameter type was returned, but the problem is it is a compilation error, failing the project build completely as soon as any such method exists in the inspected class, even if the user is not interested in that particular method.

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

No branches or pull requests

1 participant