Skip to content

Stack overflow or compiler hangs on opaque types with cyclic references #6226

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
panacekcz opened this issue Apr 4, 2019 · 0 comments · Fixed by #9557
Closed

Stack overflow or compiler hangs on opaque types with cyclic references #6226

panacekcz opened this issue Apr 4, 2019 · 0 comments · Fixed by #9557
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement prio:low

Comments

@panacekcz
Copy link
Contributor

Test code 1:

object O1 {
  opaque type X = Array[X]
}

Output:

java.lang.StackOverflowError while compiling opaque-cycle-1.scala
Exception in thread "main" java.lang.StackOverflowError
        at dotty.tools.dotc.core.Types$Type.dealias1(Types.scala:1073)
        at dotty.tools.dotc.core.Types$Type.dealias(Types.scala:1091)
        at dotty.tools.dotc.core.Definitions$ArrayOf$.unapply(Definitions.scala:926)
        at dotty.tools.dotc.core.TypeErasure.eraseArray(TypeErasure.scala:480)
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:422)
        at dotty.tools.dotc.core.TypeErasure.eraseArray(TypeErasure.scala:483)
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:422)
        at dotty.tools.dotc.core.TypeErasure.eraseArray(TypeErasure.scala:483)
        (repeats)

Test code 2:

object O2 {
  opaque type X = X
}

Compiler hangs.

Test code 3:

object O3 {
  opaque type R[X] = T[X]
  opaque type T[X] = R[X]
}

Output:

java.lang.StackOverflowError while compiling opaque-cycle-3.scala
Exception in thread "main" java.lang.StackOverflowError
        at dotty.tools.dotc.core.Substituters.substParams(Substituters.scala:154)
        at dotty.tools.dotc.core.Substituters.substParams$(Substituters.scala:149)
        at dotty.tools.dotc.core.Contexts$Context.substParams(Contexts.scala:71)
        at dotty.tools.dotc.core.Substituters$SubstParamsMap.apply(Substituters.scala:196)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:4408)
        at dotty.tools.dotc.core.Substituters.substParams(Substituters.scala:160)
        at dotty.tools.dotc.core.Substituters.substParams$(Substituters.scala:149)
        at dotty.tools.dotc.core.Contexts$Context.substParams(Contexts.scala:71)
        at dotty.tools.dotc.core.Types$Type.substParams(Types.scala:1443)
        at dotty.tools.dotc.core.Types$LambdaType.instantiate(Types.scala:2909)
        at dotty.tools.dotc.core.Types$LambdaType.instantiate$(Types.scala:2908)
        at dotty.tools.dotc.core.Types$HKLambda.instantiate(Types.scala:2938)
        at dotty.tools.dotc.core.TypeApplications$.tryReduce$1(TypeApplications.scala:375)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$appliedTo$extension0$1(TypeApplications.scala:392)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
        at dotty.tools.dotc.core.TypeApplications$.appliedTo$extension0(TypeApplications.scala:354)
        at dotty.tools.dotc.core.Types$AppliedType.derivedAppliedType(Types.scala:3497)
        at dotty.tools.dotc.core.Types$TypeMap.derivedAppliedType(Types.scala:4350)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:4408)
        at dotty.tools.dotc.core.Substituters.substParams(Substituters.scala:160)
        at dotty.tools.dotc.core.Substituters.substParams$(Substituters.scala:149)
        at dotty.tools.dotc.core.Contexts$Context.substParams(Contexts.scala:71)
        at dotty.tools.dotc.core.Types$Type.substParams(Types.scala:1443)
        at dotty.tools.dotc.core.Types$LambdaType.instantiate(Types.scala:2909)
        at dotty.tools.dotc.core.Types$LambdaType.instantiate$(Types.scala:2908)
        at dotty.tools.dotc.core.Types$HKLambda.instantiate(Types.scala:2938)
        at dotty.tools.dotc.core.TypeApplications$.tryReduce$1(TypeApplications.scala:375)
        at dotty.tools.dotc.core.TypeApplications$.$anonfun$appliedTo$extension0$1(TypeApplications.scala:392)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:37)
        at dotty.tools.dotc.core.TypeApplications$.appliedTo$extension0(TypeApplications.scala:354)
        at dotty.tools.dotc.core.Types$AppliedType.derivedAppliedType(Types.scala:3497)
        at dotty.tools.dotc.core.Types$TypeMap.derivedAppliedType(Types.scala:4350)
        (repeats)
@OlivierBlanvillain OlivierBlanvillain added area:reporting Error reporting including formatting, implicit suggestions, etc prio:low itype:enhancement labels May 7, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 13, 2020
@nicolasstucki nicolasstucki linked a pull request Aug 13, 2020 that will close this issue
anatoliykmetyuk added a commit that referenced this issue Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement prio:low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants