Skip to content

Compilation hangs when trying to resolve a context function with multiple implicit parameters #10605

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
neko-kai opened this issue Dec 2, 2020 · 1 comment · Fixed by #10916
Assignees
Labels
Milestone

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Dec 2, 2020

Minimized code

object x { 
  def xa[a, b, c, X, Y](
    f: X => ((a, b, c) ?=> Y),
    x: Any, 
    y: Any
  ) = { 
    println(f(y.asInstanceOf)(using x.asInstanceOf, x.asInstanceOf, x.asInstanceOf))
    (x: X) => (a: a, b: b, c: c) => f(x)(using a, b, c)
  }
}

def superxa(using String, Int, Option[Boolean]): Nothing = {
  implicitly[String] + implicitly[Int] + implicitly[Option[Boolean]] 
  ???
}

@main def main = 
  x.xa(Function.const(superxa)(_: Int), Nil, 5) // this line causes hang

https://scastie.scala-lang.org/G4oNvGFESFa3yyXkn5ICgg

Output

scalac superxa.scala
> // never returns

/

timed out after 30 seconds when running code

Expectation

Expected to work

@b-studios
Copy link
Contributor

I could confirm the issue and minimize the example a bit further to

def xa[A, B, X, Y](f: X => ((A, B) ?=> Y)) = 
  (z: X) => (a: A, b: B) => f(z)(using a, b)

// will hang
def superxa(using String, Int): Nothing = ???

// will raise an error
// [error] 14 |  xa(Function.const(superxa)(_: Int)) // this line causes hang
// [error]    |                           ^
// [error]    |ambiguous implicit arguments: both value evidence$2 and value evidence$1 match type String of parameter x$1 of method superxa in
def superxa(using String, Int): Unit = ???

def main = 
  xa(Function.const(superxa)(_: Int)) // this line causes hang

Note that the variant with Nothing as return type diverges, whereas Unit reports the above error.

@b-studios b-studios added area:implicits related to implicits area:typer labels Dec 3, 2020
@odersky odersky assigned odersky and unassigned smarter Dec 7, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 26, 2020
odersky added a commit that referenced this issue Jan 6, 2021
Fix #10605: Avoid mismatched constraints when prototypes are context …
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants