Skip to content

spurious ambiguous overload with Tasty, GADTs and cake pattern #9074

Closed
@odersky

Description

@odersky

Minimized code

The following is a minimization of the cps-async project which starts failing after #9063.

import scala.quoted._

trait App[F[_],CT]:
  this: Base[F,CT] =>

  import qctx.tasty._

  trait AA

  def f(cpsCtx: FC[F]): AA =
    g(cpsCtx)

  def g(cpsCtx: FC[F]): AA =
    val paramSym: Symbol = ???
    println(paramSym.tree)   // println necessary for failure
    val t: Term = ???
    t match {                // match necessary for failure
      case Typed(_, _) => ???  // both cases necessary for failure
      case Lambda(_, _) => ???
    }
    f(cpsCtx)                 // necessary for failure
    val cpsBody = runRoot()   // necessary for failure
    g(cpsCtx)                 // failure
      // 26 |    g(cpsCtx)
      //    |    ^
      //    |Ambiguous overload. The overloaded alternatives of method g in trait App with types
      //    | (cpsCtx: FC[F]): Base.this.AA
      //    | (cpsCtx: FC[F]): App.this.AA
      //    |both match arguments ((cpsCtx : FC[F]))
      //    |
      //    |Note: this happens because two or more alternatives have the same erasure,
      //    |      so they cannot be distinguished by overloading resolution


class FC[F[_]]()

trait Base[F[_]:Type,CT:Type]  // Both :Type context bounds are necessary for failure
extends Cps with Root[F, CT] with App[F, CT]:
  implicit val qctx: QuoteContext

trait Root[F[_], CT]:
  this: Base[F, CT] =>
  def runRoot(): CpsTree = ???

trait Cps:
  sealed abstract class CpsTree

Somewhat depressingly, I could not make it smaller than that. There are lots of elements that need to appear in exactly the order given, or the error will go away.

Output

-- [E051] Reference Error: cps-async-failure.scala:24:4 ------------------------
24 |    g(cpsCtx)                 // failure
   |    ^
   |Ambiguous overload. The overloaded alternatives of method g in trait App with types
   | (cpsCtx: FC[F]): Base.this.AA
   | (cpsCtx: FC[F]): App.this.AA
   |both match arguments ((cpsCtx : FC[F]))
   |
   |Note: this happens because two or more alternatives have the same erasure,
   |      so they cannot be distinguished by overloading resolution

Expectation

Should compile. There is only one method g.

Previously, the error was hidden by the somewhat arbitrary disambiguation in mergeDenots. But it was always there, and manifested itself in the project with a wrong exhaustivity warning.

It might be a cache invalidation problem. But probably not one of the caches under control from Config. I tried to turn these caches off, but the error still persisted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions