Skip to content

Crash due to wildApprox failed to remove uninstantiated A` under new 3.6 implicits resolution #21215

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

Closed
WojciechMazur opened this issue Jul 17, 2024 · 4 comments · Fixed by #21252
Assignees

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure in takapi327/ldbc - build logs
The code is expected to fail compilation under 3.6 however, it should not crash. Related to #21212

Compiler version

3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY

Minimized code

trait FlatMap[F[_]]:
  def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = ???
  def ifM[B](ifTrue: => F[B], ifFalse: => F[B])(implicit F: FlatMap[F]): F[B] = ???
trait Monad[F[_]] extends FlatMap[F]
trait MonadError[F[_], E] extends Monad[F]:
  def raiseError[A](e: E): F[A]
trait Temporal[F[_]] extends MonadError[F, Throwable]

trait FlatMapOps[F[_], A]:
  def flatMap[B](f: A => F[B]): F[B] = ???
  def ifM[B](ifTrue: => F[B], ifFalse: => F[B])(implicit F: FlatMap[F]): F[B] = ???

implicit def toFlatMapOps[F[_], A](target: F[A])(implicit tc: FlatMap[F]): FlatMapOps[F, A] = ???

abstract class Ref[F[_], A]
object Ref:
  final class ApplyBuilders[F[_]]:
    def of[A](a: A): F[Ref[F, A]] = ???
  def apply[F[_]]: ApplyBuilders[F] = ???

trait DatabaseMetaData[F[_]]
class DatabaseMetaDataImpl[F[_]](
    statementClosed: Ref[F, Boolean],
    resultSetClosed: Ref[F, Boolean]
) extends DatabaseMetaData[F]

trait LdbcConnection[F[_]]:
  def getMetaData(): F[DatabaseMetaData[F]]

class ConnectionImpl[F[_]: Temporal](using ev: MonadError[F, Throwable])
    extends LdbcConnection[F]:
  def isClosed(): F[Boolean] = ???
  override def getMetaData(): F[DatabaseMetaData[F]] =
    isClosed().ifM(
      ev.raiseError(???),
      (for
        statementClosed <- Ref[F].of[Boolean](false)
        resultSetClosed <- Ref[F].of[Boolean](false)
      yield DatabaseMetaDataImpl[F](
        statementClosed,
        resultSetClosed
      ))
    )

Output (click arrow to expand)

[error] ./src/main/scala/test.scala:38:28
[error] Found:    F[Ref[F, Boolean]]
[error] Required: ?{ flatMap: ? }
[error] 
[error] where:    F is a type in class ConnectionImpl with bounds <: [_] =>> Any
[error] 
[error] Note that implicit conversions cannot be applied because they are ambiguous;
[error] both value evidence$1 in class ConnectionImpl and given instance ev in class ConnectionImpl match type FlatMap[F]
[error]         statementClosed <- Ref[F].of[Boolean](false)
[error]                            ^^^^^^^^^^^^^^^^^^^^^^^^^

  exception occurred while typechecking /Users/wmazur/projects/sandbox/src/main/scala/test.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Xno-enrich-error-messages.

     while compiling: /Users/wmazur/projects/sandbox/src/main/scala/test.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.14
    compiler version: version 3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY-git-bbb45ca
            settings: -bootclasspath /Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY/scala3-library_3-3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY.jar:/Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar -classpath /Users/wmazur/projects/sandbox/src/.scala-build/.bloop/src_aea078f50b/bloop-internal-classes/main-q0_2TGcRQVKPA6upcOSarA==:/Users/wmazur/projects/sandbox/src/.scala-build/src_aea078f50b/classes/classes-empty-src_aea078f50b -d /Users/wmazur/projects/sandbox/src/.scala-build/.bloop/src_aea078f50b/bloop-internal-classes/main-q0_2TGcRQVKPA6upcOSarA== -java-output-version 17 -sourceroot /Users/wmazur/projects/sandbox/src

Error compiling project (Scala 3.6.0-RC1-bin-20240716-bbb45ca-NIGHTLY, JVM (17))
Error: Unexpected error when compiling src_aea078f50b: java.lang.AssertionError: assertion failed: `wildApprox` failed to remove uninstantiated A
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:667)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6807)
        at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6880)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:675)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeAccumulator.op$proxy26$1(Types.scala:6790)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldArgs$3(Types.scala:6790)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6794)
        at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6880)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:675)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6872)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.fold(ProtoTypes.scala:603)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6842)
        at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6880)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:675)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.fold(ProtoTypes.scala:279)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6842)
        at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6880)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:675)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6879)
        at dotty.tools.dotc.typer.ProtoTypes$ViewProto.fold(ProtoTypes.scala:660)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6842)
        at dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6880)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:675)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.apply(Implicits.scala:681)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.computeIScope(Implicits.scala:768)
        at dotty.tools.dotc.typer.ImplicitRunInfo.$anonfun$1(Implicits.scala:844)
        at dotty.tools.dotc.util.ReadOnlyMap.getOrElse(ReadOnlyMap.scala:23)
        at dotty.tools.dotc.typer.ImplicitRunInfo.implicitScope(Implicits.scala:844)
        at dotty.tools.dotc.typer.ImplicitRunInfo.implicitScope$(Implicits.scala:619)
        at dotty.tools.dotc.Run.implicitScope(Run.scala:43)
        at dotty.tools.dotc.typer.Implicits$ImplicitSearch.implicitScope(Implicits.scala:1762)
        at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1647)
        at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit$$anonfun$3(Implicits.scala:1731)
        at dotty.tools.dotc.typer.Implicits$SearchResult.recoverWith(Implicits.scala:430)
        at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1717)
        at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1758)
        at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1104)
        at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:855)
        at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:145)
        at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1124)
        at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:855)
        at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:145)
        at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1124)
        at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:855)
        at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:145)
        at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:895)
        at dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:855)
        at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:145)
        at dotty.tools.dotc.typer.Typer.tryExtensionOrConversion(Typer.scala:3915)
        at dotty.tools.dotc.typer.Typer.tryExt$1(Typer.scala:800)
        at dotty.tools.dotc.typer.Typer.typedSelectWithAdapt(Typer.scala:887)
        at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:978)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:1016)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3410)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3519)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1045)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1236)
        at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:434)
        at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:145)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3435)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.Typer.$anonfun$65(Typer.scala:2859)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2859)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3417)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3519)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3623)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3669)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3117)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3423)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3427)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3519)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3623)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3669)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3250)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3469)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3520)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3597)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3601)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3712)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
        at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
        at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
        at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.immutable.List$.from(List.scala:685)
        at scala.collection.immutable.List$.from(List.scala:682)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
        at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:396)
        at dotty.tools.dotc.Run.compileSources(Run.scala:282)
        at dotty.tools.dotc.Run.compile(Run.scala:267)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
        at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
        at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)
        at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
        at monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)
        at monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)
        at monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Output under -source:3.5

[warn] ./src/main/scala/test.scala:41:6
[warn] Given search preference for Monad[F] between alternatives (ConnectionImpl.this.evidence$1 : Temporal[F]) and (ConnectionImpl.this.ev : MonadError[F, Throwable]) will change
[warn] Current choice           : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] 
[warn] where:    F is a type in class ConnectionImpl with bounds <: [_] =>> Any
[warn]     )
[warn]      ^
[warn] ./src/main/scala/test.scala:39:53
[warn] Given search preference for Monad[F] between alternatives (ConnectionImpl.this.evidence$1 : Temporal[F]) and (ConnectionImpl.this.ev : MonadError[F, Throwable]) will change
[warn] Current choice           : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] 
[warn] where:    F is a type in class ConnectionImpl with bounds <: [_] =>> Any
[warn]         resultSetClosed <- Ref[F].of[Boolean](false)
[warn]                                                     ^
[warn] ./src/main/scala/test.scala:38:53
[warn] Given search preference for Monad[F] between alternatives (ConnectionImpl.this.evidence$1 : Temporal[F]) and (ConnectionImpl.this.ev : MonadError[F, Throwable]) will change
[warn] Current choice           : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] 
[warn] where:    F is a type in class ConnectionImpl with bounds <: [_] =>> Any
[warn]         statementClosed <- Ref[F].of[Boolean](false)
[warn]                                                     ^
[warn] ./src/main/scala/test.scala:35:15
[warn] Given search preference for Monad[F] between alternatives (ConnectionImpl.this.evidence$1 : Temporal[F]) and (ConnectionImpl.this.ev : MonadError[F, Throwable]) will change
[warn] Current choice           : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] 
[warn] where:    F is a type in class ConnectionImpl with bounds <: [_] =>> Any
[warn]     isClosed().ifM(
@WojciechMazur
Copy link
Contributor Author

Fixed probably in #21226 . No longer crashes in 3.6.0-RC1-bin-20240719-af933c4-NIGHTLY

@EugeneFlesselle
Copy link
Contributor

@WojciechMazur was line 38 statementClosed <- Ref[F].of[Boolean](false) the only expected error ?

@EugeneFlesselle
Copy link
Contributor

EugeneFlesselle commented Jul 24, 2024

@WojciechMazur was line 38 statementClosed <- Ref[F].of[Boolean](false) the only expected error ?

My bad, line 39 resultSetClosed <- Ref[F].of[Boolean](false)

@WojciechMazur
Copy link
Contributor Author

The reproducer was missing a single line with a map method

trait FlatMapOps[F[_], A]:
  def map[B](f: A => B): F[B] = ???

With line present it would compile without errors, but would crash in in 3.5 + -source:3.6 or 3.6+

EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Jul 24, 2024
WojciechMazur pushed a commit that referenced this issue Dec 2, 2024
WojciechMazur added a commit that referenced this issue Dec 3, 2024
)

Backports #21252 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants