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

Subtype information getting lost #11972

Closed
ultrasecreth opened this issue May 3, 2020 · 2 comments
Closed

Subtype information getting lost #11972

ultrasecreth opened this issue May 3, 2020 · 2 comments

Comments

@ultrasecreth
Copy link

Hi there, I recenctly got this bug mockito/mockito-scala/issues/229 reported and after some digging it seems to be caused by what I think it may be a bug in the compiler.

reproduction steps

In the following scenario, the inheritance information is not present on the compiled Class (Tested in both 2.12.11 and 2.13.2)

abstract class Abstract
trait TraitExtendsAbstract extends Abstract

println(classOf[TraitExtendsAbstract].getSuperclass)
println(classOf[Abstract].isAssignableFrom(classOf[TraitExtendsAbstract]))

problem

Running that code will print

null
false

expectation

It should print

class Abstract
true

extra details

If I run the following code it would actually print the expected result

val anInstance: TraitExtendsAbstract = new TraitExtendsAbstract {}

println(anInstance.getClass.getSuperclass)
println(classOf[Abstract].isAssignableFrom(anInstance.getClass.getSuperclass))
@sjrd
Copy link
Member

sjrd commented May 3, 2020

That is unfortunately unavoidable. On the JVM, an interface cannot extend any class but Object. So if you look at Java reflection, which only uses the JVM type system, and not the Scala type system, you have no way of telling that the trait initially extended a class.

@ultrasecreth
Copy link
Author

ultrasecreth commented May 4, 2020

@sjrd Fair enough, many thanks for your answer!

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

3 participants