Skip to content

No generic signature emitted for local classes #6349

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

Closed
smarter opened this issue Apr 22, 2019 · 4 comments · Fixed by #10936
Closed

No generic signature emitted for local classes #6349

smarter opened this issue Apr 22, 2019 · 4 comments · Fixed by #10936

Comments

@smarter
Copy link
Member

smarter commented Apr 22, 2019

class Foo[T]
object Test {
  class Inner extends Foo[String]

  def main(args: Array[String]): Unit = {
    class Local extends Foo[String]

    // Prints "Foo<java.lang.String>" as expected
    println((new Inner).getClass.getGenericSuperclass)

    // Prints "class Foo" instead of "Foo<java.lang.String>" because the generic
    // signature for the parent is missing.
    println((new Local).getClass.getGenericSuperclass)
  }
}

In particular, this is needed to implement the "super type tokens" pattern described in http://gafter.blogspot.com/2006/12/super-type-tokens.html and used for example in http://fasterxml.github.io/jackson-core/javadoc/2.9/com/fasterxml/jackson/core/type/TypeReference.html

smarter added a commit to dotty-staging/dotty that referenced this issue Apr 22, 2019
To work properly, `TypeReference` relies on using runtime reflection to
get the generic arguments it was instantiated with, this does not work
currently with Dotty, because we're not emitting a generic
signature for the parent, see scala#6349.
anatoliykmetyuk pushed a commit to dotty-staging/dotty that referenced this issue May 2, 2019
To work properly, `TypeReference` relies on using runtime reflection to
get the generic arguments it was instantiated with, this does not work
currently with Dotty, because we're not emitting a generic
signature for the parent, see scala#6349.
@pjfanning
Copy link
Contributor

pjfanning commented Dec 23, 2020

@smarter would this be a change that could be done for Scala 3 release? Without this, I'm not sure if jackson-module-scala can be made to work for Scala3. Of course, there are lots of other ways to work with JSON in scala and it could be about time to halt work on jackson-module-scala in favour of encouraging users onto alternatives.

@smarter
Copy link
Member Author

smarter commented Dec 23, 2020

No promise it'll be done for Scala 3.0.0, but I'll give it a try if I can find the time.

@pjfanning
Copy link
Contributor

@smarter I'm no sure that this issue only affects local classes

  val typeRef = new TypeReference[Map[String, String]]{}

This fails with same issue (java.lang.IllegalArgumentException: Internal error: TypeReference constructed without actual type information being thrown by TypeReference constructor)

@smarter
Copy link
Member Author

smarter commented Dec 24, 2020

new TypeReference[Map[String, String]]{} constructs an anonymous class, the anonymous class that is generated by the compiler is a local class.

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.

3 participants