question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't detect binary incompatibility when trait extends abstract class

See original GitHub issue

library x v1

package com.example

trait A

library x v2

package com.example

abstract class B {
  def foo: Int = 42
}

trait A extends B

mima said library x v1 => v2 binary compatible.

another library y

  • depends on library x v1
package com.example

object C {
  val a = new com.example.A {}
}

main

  • depends on library y
  • also depends on library x v2 (override x v1 transitive dependency from y)
package com.example

object Main {
  def main(args: Array[String]): Unit = println(C.a.foo)
}

run main

[error] (run-main-0) java.lang.ClassCastException: com.example.C$$anon$1 cannot be cast to com.example.B
[error] java.lang.ClassCastException: com.example.C$$anon$1 cannot be cast to com.example.B
[error] 	at com.example.Main$.main(Main.scala:6)
[error] 	at com.example.Main.main(Main.scala)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
adriaanmcommented, Feb 7, 2019

That’s why a @PureInterface annotation would be useful: the compiler could check that your trait doesn’t have any of this baggage.

0reactions
dwijnandcommented, Feb 7, 2019

Thanks, it’s slightly different, but fundamentally the same problem.

Note to self’s brain-MiMa:

  • beware what your open traits extend (prefer extending Object)
  • beware what your open traits self subtype

In addition to the other binary compatibility hazardous problems, like super calls, fields, and etc…

Maybe I’ll just avoid traits altogether…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are traits and interfaces binary compatible? - Stack Overflow
When the Scala 2.11 compiler compiles a trait, it doesn't generate an interface with default methods, because the generated code has to work ......
Read more >
Class Abstraction - Manual - PHP
Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method must also be abstract.
Read more >
Weeks Flashcards | Chegg.com
Binary Incompatibility. Not binary comparable across major releases - must rebuild libraries. var. mutable variable. val. immutable value that cannot be ...
Read more >
Using Scala Traits Like Abstract Classes
When a class extends a trait, each abstract method must be implemented, so here's a class that extends Pet and defines comeToMaster :...
Read more >
Re: [rdf4j-dev] Source and binary compatiblity checks (was: Re ...
Essentially it's for the query optimizers where they all extend an abstract class in order to inherit a basic implementation. I can't see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found