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

Consistent compiler crash, assertion failed while typechecking #19317

Closed
jgogstad opened this issue Dec 20, 2023 · 16 comments
Closed

Consistent compiler crash, assertion failed while typechecking #19317

jgogstad opened this issue Dec 20, 2023 · 16 comments
Assignees

Comments

@jgogstad
Copy link

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.

import spire.math.{Bounded, IntegralOps}
import spire.implicits.*

extension [A: spire.math.Integral] (a: A) {
  def coerce: Long = implicitly[IntegralOps[A]].coerce(a)
}

// this code isn't actually correct as far as calculating sizes goes as it doesn't account for closed and open bounds
extension [A: spire.math.Integral] (n: Bounded[A]) {
  def size: Long = spire.math.Integral[A].minus(n.upperBound.a, n.lowerBound.a).coerce
}

Output (click arrow to expand)

❯ sbt compile

[info] welcome to sbt 1.9.7 (Azul Systems, Inc. Java 11.0.10)
[info] loading project definition from /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/project
[info] loading settings for project spire-scalac-crash from build.sbt ...
[info] set current project to hello-world (in build file:/Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 2 Scala sources to /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/target/scala-3.3.1/classes ...
java.lang.AssertionError: assertion failed while typechecking /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/src/main/scala/SpireExtensions.scala
[info] exception occurred while typechecking /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/src/main/scala/SpireExtensions.scala
[info] 
[info]   exception occurred while compiling List(/Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/src/main/scala/Main.scala, /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/src/main/scala/SpireExtensions.scala)
[info] 
[info]   An unhandled exception was thrown in the compiler.
[info]   Please file a crash report here:
[info]   https://github.com/lampepfl/dotty/issues/new/choose
[info] 
[info]      while compiling: <no file>
[info]         during phase: <no phase>
[info]                 mode: Mode(ImplicitsEnabled)
[info]      library version: version 2.13.10
[info]     compiler version: version 3.3.1
[info]             settings: -bootclasspath /Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar -classpath /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/target/scala-3.3.1/classes:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire_3/0.18.0/spire_3-0.18.0.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-macros_3/0.18.0/spire-macros_3-0.18.0.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-platform_3/0.18.0/spire-platform_3-0.18.0.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-util_3/0.18.0/spire-util_3-0.18.0.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/algebra_3/2.8.0/algebra_3-2.8.0.jar:/Users/josteingogstad/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_3/2.8.0/cats-kernel_3-2.8.0.jar -d /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/target/scala-3.3.1/classes
[info] 
[info]                 tree: EmptyTree
[info]        tree position: :<unknown>
[info]            tree type: <notype>
[info]               symbol: val <none>
[info]            call site: package <root> in module class <root>
[info] 
[info]   == Source file context for tree position ==
[info] 
[error] ## Exception when compiling 2 sources to /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/target/scala-3.3.1/classes
[error] java.lang.AssertionError: assertion failed
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error] dotty.tools.dotc.ast.tpd$.TypeApply(tpd.scala:60)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.appliedToTypeTrees$extension(tpd.scala:985)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4255)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
[error] dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
[error] dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
[error] dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
[error] dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
[error] dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
[error] dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:116)
[error] dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
[error] dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3324)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3048)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1136)
[error] dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1167)
[error] dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:818)
[error] dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:116)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1242)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1341)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1511)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1539)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1572)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1060)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:818)
[error] dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:116)
[error] dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:856)
[error] dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:818)
[error] dotty.tools.dotc.typer.Typer.inferView(Typer.scala:116)
[error] dotty.tools.dotc.typer.Implicits.viewExists(Implicits.scala:831)
[error] dotty.tools.dotc.typer.Implicits.viewExists$(Implicits.scala:818)
[error] dotty.tools.dotc.typer.Typer.viewExists(Typer.scala:116)
[error] dotty.tools.dotc.typer.Implicits.ignoredConvertibleImplicits$1$$anonfun$3(Implicits.scala:960)
[error] scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] scala.collection.Iterator.isEmpty(Iterator.scala:466)
[error] scala.collection.Iterator.isEmpty$(Iterator.scala:466)
[error] scala.collection.AbstractIterator.isEmpty(Iterator.scala:1300)
[error] scala.collection.View$Filter.isEmpty(View.scala:146)
[error] scala.collection.IterableOnceOps.nonEmpty(IterableOnce.scala:833)
[error] scala.collection.IterableOnceOps.nonEmpty$(IterableOnce.scala:833)
[error] scala.collection.AbstractIterable.nonEmpty(Iterable.scala:933)
[error] dotty.tools.dotc.reporting.MissingImplicitArgument.noChainConversionsNote$1(messages.scala:2838)
[error] dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript$$anonfun$4(messages.scala:2846)
[error] scala.Option.orElse(Option.scala:477)
[error] dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript(messages.scala:2846)
[error] dotty.tools.dotc.reporting.Message.message$$anonfun$1(Message.scala:345)
[error] dotty.tools.dotc.reporting.Message.inMessageContext(Message.scala:341)
[error] dotty.tools.dotc.reporting.Message.message(Message.scala:345)
[error] dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:322)
[error] dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16)
[error] dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10)
[error] dotty.tools.dotc.reporting.AbstractReporter.isHidden(AbstractReporter.scala:8)
[error] dotty.tools.dotc.reporting.Reporter.issueUnconfigured(Reporter.scala:156)
[error] dotty.tools.dotc.reporting.Reporter.go$1(Reporter.scala:181)
[error] dotty.tools.dotc.reporting.Reporter.issueIfNotSuppressed(Reporter.scala:200)
[error] dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:203)
[error] dotty.tools.dotc.report$.error(report.scala:68)
[error] dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1(Typer.scala:3808)
[error] scala.runtime.function.JProcedure3.apply(JProcedure3.java:15)
[error] scala.runtime.function.JProcedure3.apply(JProcedure3.java:10)
[error] scala.collection.LazyZip3.foreach(LazyZipOps.scala:248)
[error] dotty.tools.dotc.typer.Typer.issueErrors$1(Typer.scala:3810)
[error] dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3832)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3849)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4038)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4268)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:752)
[error] dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:790)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3017)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:941)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3048)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] dotty.tools.dotc.typer.Typer.$anonfun$57(Typer.scala:2486)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2486)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3024)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
[error] scala.Function0.apply$mcV$sp(Function0.scala:42)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
[error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:279)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:194)
[error] dotty.tools.dotc.Run.compile(Run.scala:179)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[error] sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] sbt.Execute.work(Execute.scala:292)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] java.base/java.lang.Thread.run(Thread.java:834)
[error]            
[error] java.lang.AssertionError: assertion failed
[error] 	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error] 	at dotty.tools.dotc.ast.tpd$.TypeApply(tpd.scala:60)
[error] 	at dotty.tools.dotc.ast.tpd$TreeOps$.appliedToTypeTrees$extension(tpd.scala:985)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4255)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] 	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] 	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
[error] 	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
[error] 	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
[error] 	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
[error] 	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
[error] 	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3324)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] 	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3048)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1136)
[error] 	at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1167)
[error] 	at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1242)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1341)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1511)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1539)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1572)
[error] 	at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1060)
[error] 	at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:856)
[error] 	at dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.viewExists(Implicits.scala:831)
[error] 	at dotty.tools.dotc.typer.Implicits.viewExists$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.viewExists(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.ignoredConvertibleImplicits$1$$anonfun$3(Implicits.scala:960)
[error] 	at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] 	at scala.collection.Iterator.isEmpty(Iterator.scala:466)
[error] 	at scala.collection.Iterator.isEmpty$(Iterator.scala:466)
[error] 	at scala.collection.AbstractIterator.isEmpty(Iterator.scala:1300)
[error] 	at scala.collection.View$Filter.isEmpty(View.scala:146)
[error] 	at scala.collection.IterableOnceOps.nonEmpty(IterableOnce.scala:833)
[error] 	at scala.collection.IterableOnceOps.nonEmpty$(IterableOnce.scala:833)
[error] 	at scala.collection.AbstractIterable.nonEmpty(Iterable.scala:933)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.noChainConversionsNote$1(messages.scala:2838)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript$$anonfun$4(messages.scala:2846)
[error] 	at scala.Option.orElse(Option.scala:477)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript(messages.scala:2846)
[error] 	at dotty.tools.dotc.reporting.Message.message$$anonfun$1(Message.scala:345)
[error] 	at dotty.tools.dotc.reporting.Message.inMessageContext(Message.scala:341)
[error] 	at dotty.tools.dotc.reporting.Message.message(Message.scala:345)
[error] 	at dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:322)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10)
[error] 	at dotty.tools.dotc.reporting.AbstractReporter.isHidden(AbstractReporter.scala:8)
[error] 	at dotty.tools.dotc.reporting.Reporter.issueUnconfigured(Reporter.scala:156)
[error] 	at dotty.tools.dotc.reporting.Reporter.go$1(Reporter.scala:181)
[error] 	at dotty.tools.dotc.reporting.Reporter.issueIfNotSuppressed(Reporter.scala:200)
[error] 	at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:203)
[error] 	at dotty.tools.dotc.report$.error(report.scala:68)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1(Typer.scala:3808)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:15)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:10)
[error] 	at scala.collection.LazyZip3.foreach(LazyZipOps.scala:248)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$1(Typer.scala:3810)
[error] 	at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3832)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3849)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4038)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4268)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:752)
[error] 	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:790)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3017)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:941)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] 	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3048)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.Typer.$anonfun$57(Typer.scala:2486)
[error] 	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
[error] 	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2486)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3024)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
[error] 	at scala.Function0.apply$mcV$sp(Function0.scala:42)
[error] 	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.immutable.List.foreach(List.scala:333)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
[error] 	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error] 	at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
[error] 	at dotty.tools.dotc.Run.compileSources(Run.scala:194)
[error] 	at dotty.tools.dotc.Run.compile(Run.scala:179)
[error] 	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] 	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] 	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] 	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] 	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] 	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] 	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] 	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] 	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] 	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
[error] 	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] 	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] 	at sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] 	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] 	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] 	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] 	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] 	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] 	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] 	at sbt.Execute.work(Execute.scala:292)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] 	at java.base/java.lang.Thread.run(Thread.java:834)
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed
[error] Total time: 2 s, completed Dec 20, 2023, 8:23:32 PM
@jgogstad jgogstad added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 20, 2023
@nicolasstucki nicolasstucki added stat:needs minimization Needs a self contained minimization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 21, 2023
@nicolasstucki
Copy link
Contributor

We should try to define the spire implicits and types in the example file to avoid the dependency.

@nicolasstucki
Copy link
Contributor

@jgogstad could you compile it with the latest nightly build? That version should show more information on the assertion failure.

https://github.com/lampepfl/dotty/blob/d3fafd6ab11ce7385f31675a2ce7a305e3faf2a8/compiler/src/dotty/tools/dotc/ast/tpd.scala#L59

@jgogstad
Copy link
Author

sure, code: https://github.com/jgogstad/spire-scalac-crash/tree/nightly

output

❯ sbt compile
[info] welcome to sbt 1.9.7 (Azul Systems, Inc. Java 11.0.10)
[info] loading project definition from /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/project
[info] loading settings for project spire-scalac-crash from build.sbt ...
[info] set current project to hello-world (in build file:/Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 2 Scala sources to /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/target/scala-3.4.0-RC1-bin-20231219-eae8831-NIGHTLY/classes ...
[error] -- [E172] Type Error: /Users/josteingogstad/source-code/github.com/jgogstad/spire-scalac-crash/src/main/scala/SpireExtensions.scala:5:47 
[error] 5 |  def coerce: Long = implicitly[IntegralOps[A]].coerce(a)
[error]   |                                               ^
[error]   |No given instance of type spire.math.IntegralOps[A] was found for parameter e of method implicitly in object Predef
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 8 s, completed Dec 21, 2023, 12:30:51 PM

@nicolasstucki
Copy link
Contributor

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.

@MateuszKubuszok
Copy link

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.

@nicolasstucki nicolasstucki added the area:implicits related to implicits label Dec 21, 2023
@ldeluigi
Copy link

ldeluigi commented Feb 6, 2024

I'm experiencing the same issue

@cptwunderlich
Copy link

I just got the same error in a project using FS2 and cats-effect.

@mbovel
Copy link
Member

mbovel commented Jan 8, 2025

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]]
➜  ~/scala-snippets-6 scala issue19317.scala
Compiling project (Scala 3.6.2, JVM (21))
[error] ./issue19317.scala:9:74
[error] No given instance of type spire.math.IntegralOps[A] was found for parameter e of method implicitly in object Predef
[error] def coerce[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]]
[error]                                                                          ^
Error compiling project (Scala 3.6.2, JVM (21))
Compilation failed

Is that a faithful reproduction? If yes, then what is the expectation here; would you like an instance IntegralOps[A] to be found via integralOps?

@jgogstad
Copy link
Author

jgogstad commented Jan 8, 2025

sorry, I've (unfortunately) moved off Scala since I filed this issue, I no longer remember the details here

@mbovel
Copy link
Member

mbovel commented Jan 8, 2025

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: implicitly cannot trigger the implicit conversion. But calling coerce directly on a works.

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 = ()

coerceIncorrect doesn't type-check in both cases, coerceCorrect does:

➜  ~/scala-snippets-6 scala issue19317.scala
Compiling project (Scala 3.6.2, JVM (21))
[error] ./issue19317.scala:9:83
[error] No given instance of type spire.math.IntegralOps[A] was found for parameter e of method implicitly in object Predef
[error] def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a)
[error]                                                                                   ^
Error compiling project (Scala 3.6.2, JVM (21))
Compilation failed
➜  ~/scala-snippets-6 scala issue19317_min.scala
Compiling project (Scala 3.6.2, JVM (21))
[error] ./issue19317_min.scala:13:83
[error] No given instance of type issue19317_min.IntegralOps[A] was found for parameter e of method implicitly in object Predef
[error] def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a)
[error]                                                                                   ^
Error compiling project (Scala 3.6.2, JVM (21))
Compilation failed

@mbovel
Copy link
Member

mbovel commented Jan 8, 2025

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 = ()
➜  ~/scala-snippets-6 scala -S 3.3.1 issue19317_bug.scala
Compiling project (Scala 3.3.1, JVM (21))
exception occurred while typechecking /Users/mbovel/scala-snippets-6/issue19317_bug.scala
...
Error compiling project (Scala 3.3.1, JVM (21))
Error: Unexpected error when compiling scala-snippets-6_fb9235b12f-9a197343bd: java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.ast.tpd$.TypeApply(tpd.scala:60)
        at dotty.tools.dotc.ast.tpd$TreeOps$.appliedToTypeTrees$extension(tpd.scala:985)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4255)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
        at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
        at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
        at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:116)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
        at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3324)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)

Compilation failed
➜  ~/scala-snippets-6 scala -S 3.3.2 issue19317_bug.scala
Compiling project (Scala 3.3.2, JVM (21))
[error] ./issue19317_bug.scala:9:48
[error] No given instance of type spire.math.IntegralOps[A] was found for parameter e of method implicitly in object Predef
[error]   def coerce: Long = implicitly[IntegralOps[A]].coerce(a)
[error]                                                ^
Error compiling project (Scala 3.3.2, JVM (21))
Compilation failed

@mbovel mbovel removed the stat:needs minimization Needs a self contained minimization label Jan 8, 2025
@jgogstad
Copy link
Author

jgogstad commented Jan 9, 2025

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 IntegralOps[A]. Given this fact, and if this compiles, one would expect that summoning that instance explicitly also should work, i.e.

def coerceIncorrect[A](a: A)(using Integral[A]): Unit = implicitly[IntegralOps[A]].coerce(a) // fails

said differently, an instance of Integral[A] in the implicit scope defined in your example always implies the existence of ImplicitOps[A], therefore it should be possible to summon it explicitly.

am I missing something obvious here?

@joroKr21
Copy link
Member

joroKr21 commented Jan 9, 2025

am I missing something obvious here?

IntegralOps is an implicit conversion: https://docs.scala-lang.org/tour/implicit-conversions.html

@mbovel
Copy link
Member

mbovel commented Jan 9, 2025

@jgogstad maybe you missed the a parameter of integralOps?

Without this parameter, what you want would work. However with this parameter, integralOps defines an implicit conversion, and an instance of A to convert from is therefore needed.

//> 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 = ()

@jgogstad
Copy link
Author

thank you for taking the time to explain! I'll leave issue resolution to you

@mbovel
Copy link
Member

mbovel commented Jan 10, 2025

So, to conclude:

  1. The original compiler crash reported here has been fixed.
  2. The error currently reported is expected and not a bug.

I think we can therefore safely close this issue.

@mbovel mbovel closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants