Skip to content

Compiler crash with Dotty 0.22.0-RC1 #8464

Closed
@rachitnigam

Description

@rachitnigam

reproduction steps

Running the following program crashes the compiler with java.lang.OutOfMemoryError.

  enum Kind {
    case Type
  }

  enum Term[T <: Term[T, K], K] {
    case Wrap(t: T)
    case Fun(id: Id, tag: K, ret: Term[T, K])
  }

  enum Type {
    case Var(id: Id)
  }

  val tExp: Term[Type, Kind] =
    Term.Fun("x", Kind.Type, Term.Wrap(Type.Var("x")))

  def main(args: Array[String]): Unit = { }

problem

I was trying to implement an parametric AST where the Term enum can be parameterized with a type T used to recursively build well-typed terms (so a Term[Type] can only contain other Term[Type]) and a "Tag" K.

On changing the program to not have K (note the mistake where the Fun node still has an unbound type variable K), I get a different error:

  enum Term[T <: Term[T]] {
    case Wrap(t: T)
    case Fun(id: Id, tag: K, ret: Term[T])
  }

  enum Type {
    case Var(id: Id)
  }

  val tExp: Term[Type, Kind] =
    Term.Fun("x", Term.Wrap(Type.Var("x")))
[error] -- [E007] Type Mismatch Error:
[error] 41 |    Term.Fun("x", Term.Wrap(Type.Var("x")))
[error]    |                            ^^^^^^^^^^^^^
[error]    |Found:    Main.Type
[error]    |Required: Main.Term[
[error]    |  LazyRef(
[error]    |    Main.Term[
[error]    |      LazyRef(
[error]    |        Main.Term[
[error]    |          LazyRef(
[error]    |            Main.Term[
[error]    |              LazyRef(
[error]    |                Main.Term[
[error]    |                  LazyRef( ... // repeats for a while    

expectation

In the program above, I expected the compiler to infer the type for tExp to be Term[Type, Kind]. Instead, it infinite loops. If this is expected behavior, can someone explain what's happening?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions