Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

cast class exception using algebra with algebird #179

Open
johnynek opened this issue Nov 7, 2016 · 1 comment
Open

cast class exception using algebra with algebird #179

johnynek opened this issue Nov 7, 2016 · 1 comment

Comments

@johnynek
Copy link
Contributor

johnynek commented Nov 7, 2016

[info]   java.lang.ClassCastException: com.twitter.algebird.IntRing$ cannot be cast to cats.kernel.CommutativeGroup
[info]   at com.twitter.algebird.IntRing$.additive(Ring.scala:66)
[info]   at com.twitter.algebird.AdjoinedUnitRing.<init>(AdjoinedUnitRing.scala:40)
[info]   at com.twitter.algebird.AdjoinedUnit$.ring(AdjoinedUnitRing.scala:32)
[info]   at com.twitter.algebird.AdjoinedRingSpecification.<init>(AdJoinedUnitRing.scala:40)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info]   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info]   at java.lang.Class.newInstance(Class.java:442)
[info]   at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:435)

The code compiled, but at runtime it failed. This resulted from treating a Ring[T] as a Rng[T]. I'll try to repro here.

@johnynek
Copy link
Contributor Author

johnynek commented Nov 7, 2016

I fixed it by making algebra Ring extend CommutativeGroup. Note, the code compiled, but I got a class cast exception at runtime.

https://github.com/twitter/algebird/pull/523/files#diff-7347f7f93e4781e9ba09b718ce5d981cR47

Seems like some kind of issue with the inheritance we have set up, and somehow scala thinks things are fine at runtime, but makes some unsafe casts.

It's a little concerning.

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

No branches or pull requests

1 participant