scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Type argument of class scala.Int is resolved to java.lang.Object when discovering type arguments using Java reflection #4948

Closed scabug closed 13 years ago

scabug commented 13 years ago

We're using a legacy infrastructure for data conversion based on the Dozer project, for which we wrote some scala-specific adapters. Everything works properly except for fields that are generic on scala.Int, such as Option[Int] or List[Int]. After some research it appears that the Java reflection system fails to discover the type argument for Option[Int], whereas it succeeds in doing so for Option[String].

Please see the attached file which reproduces the issue.

scabug commented 13 years ago

Imported From: https://issues.scala-lang.org/browse/SI-4948?orig=1 Reporter: Shai Yallin (electricmonk) Affected Versions: 2.9.0-1 Attachments:

scabug commented 13 years ago

@paulp said: Duplicate of several other tickets.

scabug commented 13 years ago

Shai Yallin (electricmonk) said: Can you please link this issue to any of the duplicates so that I can add a watch on it?

scabug commented 13 years ago

@paulp said: First, can you enumerate the searches you issued before opening this ticket, the results of which must have omitted the existing ones. I need this information to improve the search facility, because I lose far too much time to duplicate, not-a-bug, and documented-wontfix tickets.

scabug commented 13 years ago

@SethTisue said: I searched for "object type parameter primitive" and the #1 hit was #4403 which is linked to #4214 which iirc is the main relevant ticket here.

scabug commented 13 years ago

Shai Yallin (electricmonk) said (edited on Aug 30, 2011 5:40:30 AM UTC): I see the relation to #4403, although the comment by @paulp seems to indicate that there's no intention to fix this issue, which is a problem, as I see it, since the compiler generates invalid bytecode.

4214 seems to have been resolved if you look at the comment from the original reporter, but nowhere do I see a reference to a solution that resolves the primitive generic type issue.

I've linked this issue to the "metabug" #4912, I hope to see a fix soon, and I would love to hear from @paulp why there's not much that can be done about it.

scabug commented 13 years ago

@retronym said: Hi Shai,

It's best to consult the mailing list before raising a ticket unless you're sure that it it's a bug, and not a duplicate.

There is a conflict between the Java generics, which can only accept AnyRef type parameters, and the Scala type system, which can include AnyVals. For this reason, some information must be erased.

Here are a few threads that highlight the difficulty of the problem.

http://www.scala-lang.org/node/8888 https://groups.google.com/forum/#!topic/scala-internals/734iM8b3kGc

You're really after a Scala specific reflection API. The good news is that this is coming in Scala 2.10. In the meantime, take a look at Salat, which uses the Scala Decompiler (scalap) to extract the same information.