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

'@sp' causing stack overflow on implicitly[Numeric[Int/Long/Double/Float]].toRational() #624

Closed
erikerlandson opened this issue Jan 29, 2017 · 3 comments
Labels

Comments

@erikerlandson
Copy link
Contributor

Happens for all the native typesInt, Long, Double, Float. Doesn't seem to happen for non-native types like BigInt.

[eje@localhost spire]$ xsbt coreJVM/console
Welcome to Scala 2.12.0 (OpenJDK 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> import spire.implicits._; import spire.math._
import spire.implicits._
import spire.math._

scala> implicitly[Numeric[Int]].toRational(1)
java.lang.StackOverflowError
  at spire.std.IntIsReal.toBigInt(int.scala:68)
  at spire.std.IntIsReal.toBigInt$(int.scala:68)
  at spire.math.IntIsNumeric.toBigInt$mcI$sp(Numeric.scala:97)
  at spire.std.IntIsReal.toBigInt(int.scala:68)
  at spire.std.IntIsReal.toBigInt$(int.scala:68)
  at spire.math.IntIsNumeric.toBigInt$mcI$sp(Numeric.scala:97) ....
@erikerlandson
Copy link
Contributor Author

Looks like it it is some kind of interaction with @sp specializations, which would explain why it's happening with Int/Long/Float/Double.

@erikerlandson
Copy link
Contributor Author

Wondering how important @sp really is in this hierarchy. Isn't specialization already being achieved with the type-specific implicits, like IntIsNumeric, DoubleIsNumeric, etc?

@erikerlandson
Copy link
Contributor Author

Confirmed that if I remove @sp from Numeric[A] and some related traits, it fixes the problem.

@erikerlandson erikerlandson changed the title stack overflow (infinite recursion) on: implicitly[Numeric[Int]].toRational(1) '@sp' causing stack overflow on implicitly[Numeric[Int/Long/Double/Float]].toRational() Jan 31, 2017
erikerlandson added a commit to erikerlandson/spire that referenced this issue Feb 1, 2017
@denisrosset denisrosset added the bug label Mar 4, 2017
JoeWrightss pushed a commit to JoeWrightss/spire that referenced this issue Apr 13, 2019
…ite-fix

Fix to `spire-agent api fetch -write` command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants