Skip to content

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

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
odersky opened this issue May 29, 2020 · 7 comments
Closed

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

odersky opened this issue May 29, 2020 · 7 comments

Comments

@odersky
Copy link
Contributor

odersky commented May 29, 2020

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.

@nicolasstucki
Copy link
Contributor

I tried the minimization with dotc -Ycheck:all on #9063 and it compiled. How should I run this to get the failure?

@nicolasstucki
Copy link
Contributor

Might have been fixed by the last commit f47f51b

@odersky
Copy link
Contributor Author

odersky commented May 29, 2020

No it was a commit before that: Something about black magic to make it compile. I have now pushed a version without the black magic that exhibits the error. The test itself is in

tests/pending/pos/cps-async-failure.scala

@odersky
Copy link
Contributor Author

odersky commented May 29, 2020

The black magic just picked one of two conflicting denotations. It was wrong half of the time, but happened to be right for this particular problem in cps-async. But then there were other problems, so I had to disable cps-async in the end.

@odersky
Copy link
Contributor Author

odersky commented May 29, 2020

I have pushed a new #9063 that exhibits the failure.

@odersky
Copy link
Contributor Author

odersky commented May 29, 2020

The test case is in tests/pending/pos/cps-async-failure.scala

rssh added a commit to dotty-cps-async/dotty-cps-async that referenced this issue Jun 7, 2020
@odersky
Copy link
Contributor Author

odersky commented Jan 3, 2021

I can't make it compile anymore with latest Tasty, so let's close.

@odersky odersky closed this as completed Jan 3, 2021
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

2 participants