Skip to content

stack overflow compiling single-arg implicit constructor with empty auxiliary ctor #1639

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
ljdelight opened this issue Oct 29, 2016 · 3 comments · Fixed by #1658
Closed

Comments

@ljdelight
Copy link
Contributor

ljdelight commented Oct 29, 2016

Dotty encounters a stack overflow when compiling this invalid code:
class Foo(implicit val bar: String) { def this() = this("baz") }

Here's the full trace, and a snippet below from using dotc.

Exception in thread "main" java.lang.StackOverflowError
    at dotty.tools.dotc.core.OrderingConstraint$ConstraintLens.update(OrderingConstraint.scala:51)
    at dotty.tools.dotc.core.OrderingConstraint$ConstraintLens.update(OrderingConstraint.scala:72)
    at dotty.tools.dotc.core.OrderingConstraint.updateEntry(OrderingConstraint.scala:337)
    at dotty.tools.dotc.core.OrderingConstraint.init(OrderingConstraint.scala:305)
    at dotty.tools.dotc.core.OrderingConstraint.add(OrderingConstraint.scala:289)
    at dotty.tools.dotc.core.OrderingConstraint.add(OrderingConstraint.scala:128)
    at dotty.tools.dotc.core.ConstraintHandling$class.addToConstraint(ConstraintHandling.scala:297)
    at dotty.tools.dotc.core.TypeComparer.addToConstraint(TypeComparer.scala:18)
    at dotty.tools.dotc.typer.ProtoTypes$.constrained(ProtoTypes.scala:369)
    at dotty.tools.dotc.typer.ProtoTypes$.constrained(ProtoTypes.scala:374)
    at dotty.tools.dotc.typer.ProtoTypes$$anonfun$normalize$1.apply(ProtoTypes.scala:393)
    at dotty.tools.dotc.typer.ProtoTypes$$anonfun$normalize$1.apply(ProtoTypes.scala:392)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.ProtoTypes$.normalize(ProtoTypes.scala:391)
    at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.dotty$tools$dotc$typer$Implicits$ImplicitRefs$$anonfun$$refMatches$1(Implicits.scala:95)
    at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1$$anonfun$apply$1.apply(Implicits.scala:100)
    at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1$$anonfun$apply$1.apply(Implicits.scala:100)
    at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:259)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:258)
    at scala.collection.TraversableLike$class.filter(TraversableLike.scala:270)
    at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
    at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.apply(Implicits.scala:100)
    at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.apply(Implicits.scala:48)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
...

And compiling with scalac:

./tests/neg/mytest.scala:3: error: overloaded method constructor Foo with alternatives:
  ()Foo <and>
  ()(implicit bar: String)Foo
 cannot be applied to (String)
class Foo(implicit val bar: String) { def this() = this("baz") }
                                                   ^
one error found
@liufengyun
Copy link
Contributor

Thanks a lot @ljdelight , report confirmed!

odersky added a commit to dotty-staging/dotty that referenced this issue Nov 5, 2016
This can lead to stackoverflow, as i1639.scala shows.

Fixes scala#1639.
@odersky odersky self-assigned this Nov 5, 2016
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 24, 2016
This can lead to stackoverflow, as i1639.scala shows.

Fixes scala#1639.
odersky added a commit that referenced this issue Dec 3, 2016
Fix #1639: Changes around implicits and apply methods
@odersky
Copy link
Contributor

odersky commented Dec 3, 2016

In fact this is not fixed yet. The commit message of #1658 said "while trying to fix" #1639. Sorry for the confusion.

@odersky odersky reopened this Dec 3, 2016
@odersky
Copy link
Contributor

odersky commented Dec 3, 2016

I was on the wrong branch when testing. The issue is indeed fixed by #1658.

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.

4 participants