scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

StackOverflowError in scalac (reg. NoArgsTypeRef.typeParams) #12741

Open noresttherein opened 1 year ago

noresttherein commented 1 year ago

Reproduction steps

Scala version: 2.13.10

    trait Base[L, R] {
        type U
        val swap :Base[R, L] { type U = Base.this.U }
    }
    trait Sub[L, R] extends Base[L, R] {
        type U
        override val swap :Sub[R, L] { type U = Sub.this. U }
    }

Problem

    at scala.reflect.internal.Types$NoArgsTypeRef.typeParams(Types.scala:2160)
    at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1809)
    at scala.reflect.internal.Types$NoArgsTypeRef.typeParams(Types.scala:2160)
    at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1809)
    at scala.reflect.internal.Types$NoArgsTypeRef.typeParams(Types.scala:2160)
    at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1809)
        ...
SethTisue commented 1 year ago

more minimal:

trait Base {
  type U
  def swap: Base
}
trait Sub extends Base {
  override val swap: Sub { type U = Sub.this.U }
}

note that the override must be a val, though

som-snytt commented 1 year ago

@noresttherein never rests. Nor does @SethTisue when minimizing.

I observe that no one begins by saying, "I don't wish to appear to be minimizing your problem, but..."

noresttherein commented 1 year ago

Sorry for not minimizing it. I mean, the type on the stack trace is an unapplied higher type, and I was so surprised by it being already so simple, because I was so sure I did it already countless times, and I kind of assumed it's already minimized.

noresttherein commented 1 year ago

Also, in case someone stumbles upon it, this works:

    trait Base {
        type U
        type BaseSwap = Base { type U = Base.this.U }
        val swap :BaseSwap
    }
    trait Sub extends Base {
        type SubSwap = Sub { type U = Sub.this.U }
        val swap :SubSwap
    }

Which is probably the reason for my astonishment - I must have always been doing the above.

joroKr21 commented 1 year ago

The most confusing part is that in the minimal version there are no typeParams involved 🤔