-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Consistent compiler crash, assertion failed while typechecking #19317
Comments
We should try to define the spire implicits and types in the example file to avoid the dependency. |
@jgogstad could you compile it with the latest nightly build? That version should show more information on the assertion failure. |
sure, code: https://github.com/jgogstad/spire-scalac-crash/tree/nightly output
|
At least the crash is fixed. It is hard to know if this is an expected error from this snipped of code alone. We will need a minimization. We should also check if the crash fix will be in 3.3.2. If not, we should backport it. |
Similar issue got reported in Chimney, but without a working reproduction. I also assumed it is a compiler bug, since I feel it's unlikely that 2 libraries have the same bug at the same time. |
I'm experiencing the same issue |
I just got the same error in a project using FS2 and cats-effect. |
I just tried with Scala 3.6.2: //> using dep org.typelevel::spire:0.18.0
//> using scala 3.6.2
package issue19317
import spire.math.{Integral, IntegralOps}
import spire.implicits.integralOps
def coerce[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]]
Is that a faithful reproduction? If yes, then what is the expectation here; would you like an instance |
sorry, I've (unfortunately) moved off Scala since I filed this issue, I no longer remember the details here |
Thanks for answering nevertheless @jgogstad! :) For the others, my current conclusion is that the original compiler bug reported here has been fixed. The current "implicit not found error" seems expected to me: Minimized: // issue19317_min.scala
//> using scala 3.6.2
package issue19317_min
import scala.language.implicitConversions
class Integral[A]
class IntegralOps[A](lhs: A)(implicit ev: Integral[A]):
def coerce(a: A): Long = 0L
implicit def integralOps[A](a: A)(using Integral[A]): IntegralOps[A] = new IntegralOps(a)
def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a) // fails
def coerceCorrect[A](a: A)(using Integral[A]): Unit = a.coerce(a) // works
@main def main = () With the dependency: // issue19317.scala
//> using dep org.typelevel::spire:0.18.0
//> using scala 3.6.2
package issue19317
import spire.math.{Integral, IntegralOps}
import spire.implicits.integralOps
def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a) // fails
def coerceCorrect[A](a: A)(using Integral[A]): Unit = a.coerce(a) // works
@main def main = ()
|
I also confirm that the crash initially reported has been fixed between 3.3.1 and 3.3.2: //> using dep org.typelevel::spire:0.18.0
package issue19317_bug
import spire.math.{Bounded, Integral, IntegralOps}
import spire.implicits.*
extension [A: Integral] (a: A) {
def coerce: Long = implicitly[IntegralOps[A]].coerce(a)
}
@main def main = ()
|
with a huge disclaimer that I left Scala more than two years ago, I do think the behavior looks a bit strange. Please feel free to ignore this comment if it's extremely obvious: this code def coerceCorrect[A](a: A)(using Integral[A]): Unit = a.coerce(a) // works only works if the compiler can summon an def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a) // fails said differently, an instance of am I missing something obvious here? |
|
@jgogstad maybe you missed the Without this parameter, what you want would work. However with this parameter, //> using scala 3.6.2
package issue19317_conversion
import scala.language.implicitConversions
class Integral[A]
class IntegralOps[A](lhs: A)(implicit ev: Integral[A]):
def coerce(a: A): Long = 0L
implicit def integralOpsConversion[A](a: A)(using Integral[A]): IntegralOps[A] = new IntegralOps(a)
implicit def integralOpsImplicit[A](using Integral[A]): IntegralOps[A] = new IntegralOps(???)
def coerceConversion[A](a: A)(using ev: Integral[A]): Unit =
a.coerce(a) // works
// integralOpsConversion[A](a)(ev).coerce(a)
def coerceImplicit[A](a: A)(using ev: Integral[A]): Unit =
implicitly[IntegralOps[A]].coerce(a)
// implicitly[IntegralOps[A]](integralOpsImplicit[A](ev)).coerce(a)
@main def main = () |
thank you for taking the time to explain! I'll leave issue resolution to you |
So, to conclude:
I think we can therefore safely close this issue. |
Compiler version
3.3.1
Minimized code
Small project for reproducing: https://github.com/jgogstad/spire-scalac-crash,
There is a chance that Spire is a culprit here, however, there are no traces of Spire in the compiler stacktraces, hence filing the issue here. See repo linked above for contained test case.
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: