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

Compiler crash when secondary constructor has 3 or more implicit parameters #20483

Closed
kavedaa opened this issue May 27, 2024 · 1 comment · Fixed by #20488
Closed

Compiler crash when secondary constructor has 3 or more implicit parameters #20483

kavedaa opened this issue May 27, 2024 · 1 comment · Fixed by #20488

Comments

@kavedaa
Copy link

kavedaa commented May 27, 2024

Compiler version

3.4.1 and others

Minimized code

//> using scala 3.4.1

class Foo
  (x: Option[String])
  (using Boolean)
  (using Int)
  (using Double):

  def this
    (x: String)
    (using Boolean)
    (using Int)
    (using Double) =
    this(Some(x))

Output (click arrow to expand)

Error compiling project (Scala 3.4.1, JVM (8))
Error: Unexpected error when compiling secondary-constructor-implicit_a13f841420-2a4dfdb310: java.lang.AssertionError: assertion failed: missing implicit parameter of type Double after typer at phase parser
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1075)
        at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:851)
        at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:120)
        at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:917)
        at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:851)
        at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:120)
        at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3815)
        at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3851)
        at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3930)
        at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4130)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4379)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3677)
@kavedaa kavedaa added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 27, 2024
odersky added a commit to dotty-staging/dotty that referenced this issue May 28, 2024
AddImplicitArgs can recursively add several implicit parameter lists.
We need to make sure we don't perform a thisCallContext search in another
thisCall context in this case.

Fixes scala#20483

The original code would back out further and further in the context chain for every
implicit parameter section on the secondary constructor. Eventually (in this case
after 3 times) bad things happen.
@odersky
Copy link
Contributor

odersky commented May 28, 2024

Interesting puzzler!

@Gedochao Gedochao added area:typer area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 3, 2024
odersky added a commit that referenced this issue Jun 10, 2024
AddImplicitArgs can recursively add several implicit parameter lists. We
need to make sure we don't perform a thisCallContext search in another
thisCall context in this case.

Fixes #20483

The original code would back out further and further in the context
chain for every implicit parameter section on the secondary constructor.
Eventually (in this case after 2 times) bad things happen.
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue Jun 19, 2024
AddImplicitArgs can recursively add several implicit parameter lists.
We need to make sure we don't perform a thisCallContext search in another
thisCall context in this case.

Fixes scala#20483

The original code would back out further and further in the context chain for every
implicit parameter section on the secondary constructor. Eventually (in this case
after 3 times) bad things happen.
WojciechMazur pushed a commit that referenced this issue Jun 20, 2024
AddImplicitArgs can recursively add several implicit parameter lists.
We need to make sure we don't perform a thisCallContext search in another
thisCall context in this case.

Fixes #20483

The original code would back out further and further in the context chain for every
implicit parameter section on the secondary constructor. Eventually (in this case
after 3 times) bad things happen.
WojciechMazur added a commit that referenced this issue Jul 8, 2024
AddImplicitArgs can recursively add several implicit parameter lists.
We need to make sure we don't perform a thisCallContext search in another
thisCall context in this case.

Fixes #20483

The original code would back out further and further in the context chain for every
implicit parameter section on the secondary constructor. Eventually (in this case
after 3 times) bad things happen.

[Cherry-picked 2e4a070][modified]
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.

3 participants