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 stack overflow when converting an unapplied method with implicit to a function value #10156

Closed
scabug opened this issue Jan 20, 2017 · 2 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jan 20, 2017

Having defined a simple method with an implicit argument, e.g.

trait A

def x(implicit a: A) = a

we can easily make the compiler to fail with stack overflow using (possibly errornous, but nevertheless) converting of an unapplied function to a function value:

val z = x _

Stack trace is

java.lang.StackOverflowError
        at scala.reflect.internal.Types$Type.isError(Types.scala:298)
        at scala.reflect.internal.Types$SimpleTypeProxy.isError(Types.scala:141)
        at scala.reflect.internal.Types$SimpleTypeProxy.isError$(Types.scala:141)
        at scala.reflect.internal.Types$SingletonType.isError(Types.scala:1088)
        at scala.reflect.internal.tpe.TypeMaps$ErroneousCollector$.traverse(TypeMaps.scala:1093)
        at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:300)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
        at scala.reflect.internal.tpe.TypeMaps$ErroneousCollector$.traverse(TypeMaps.scala:1094)
        at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:300)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
        at scala.reflect.internal.tpe.TypeMaps$ErroneousCollector$.traverse(TypeMaps.scala:1094)
        at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:300)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:110)
        at scala.reflect.internal.tpe.TypeMaps$ErroneousCollector$.traverse(TypeMaps.scala:1094)
        at scala.reflect.internal.tpe.TypeMaps$TypeCollector.collect(TypeMaps.scala:312)
        at scala.reflect.internal.Types$Type.isErroneous(Types.scala:301)
        at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$applyImplicitArgs$2(Typers.scala:172)
        at scala.collection.immutable.List.foreach(List.scala:378)
        at scala.tools.nsc.typechecker.Typers$Typer.applyImplicitArgs(Typers.scala:166)
        at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$adapt$2(Typers.scala:850)
        at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:703)
        at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$adapt$1(Typers.scala:849)
        at scala.tools.nsc.typechecker.Typers$Typer.withCondConstrTyper(Typers.scala:482)
        at scala.tools.nsc.typechecker.Typers$Typer.adaptToImplicitMethod$1(Typers.scala:847)
        at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1197)
        at scala.tools.nsc.typechecker.Typers$Typer.typedEta$1(Typers.scala:4523)
        at scala.tools.nsc.typechecker.Typers$Typer.typedTyped$1(Typers.scala:5224)
        at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5469)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5483)
        at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5519)
        at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5549)
        at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5493)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5497)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5594)
        at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$adapt$3(Typers.scala:867)
        at scala.tools.nsc.typechecker.Typers$SilentResult.orElse(Typers.scala:77)
        at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$adapt$1(Typers.scala:854)
        at scala.tools.nsc.typechecker.Typers$Typer.withCondConstrTyper(Typers.scala:482)

etc...

@scabug
Copy link
Author

scabug commented Jan 20, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10156?orig=1
Reporter: Denis Buzdalov (buzden)
Affected Versions: 2.12.1

@diesalbla
Copy link

I have checked out the version 2.12.4, and tested the following code, added to a neg test file.

object t10156 {
  trait A
  def x(implicit a: A) = a
  val z = x _
}

Running this with partest test/files/pos/t10156.scala no longer gives a StackOverflow, but with a compiler error. It would seem that this bug has been solved since at least version 2.12.4.

@adriaanm adriaanm added this to the 2.12.4 milestone Sep 21, 2018
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

4 participants