scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

scala.MatchError: LazyRef(...) (of class dotty.tools.dotc.core.Types$LazyRef) #12327

Closed xuwei-k closed 3 years ago

xuwei-k commented 3 years ago

Compiler version

Minimized code

build.sbt

scalaVersion := "3.0.0-RC3"

project/build.properties

sbt.version=1.5.1

Foo.scala

package example

trait Foo[A]

object Foo {
  implicit def javaEnumInstance[A <: java.lang.Enum[A]]: Foo[A] =
    ???
}

Output

run sbt doc

[warn] -- Warning: Foo.scala:6:15 -----------------------------------------------------
[warn] 6 |  implicit def javaEnumInstance[A <: java.lang.Enum[A]]: Foo[A] =
[warn]   |  ^
[warn]   |scala.MatchError: LazyRef(...) (of class dotty.tools.dotc.core.Types$LazyRef)
[warn]   |  at dotty.tools.scaladoc.tasty.TypesSupport.dotty$tools$scaladoc$tasty$TypesSupport$$inner(TypesSupport.scala:262)
[warn]   |  at dotty.tools.scaladoc.tasty.TypesSupport.inner$$anonfun$5(TypesSupport.scala:190)
[warn]   |  at scala.collection.immutable.List.map(List.scala:246)
[warn]   |  at dotty.tools.scaladoc.tasty.TypesSupport.dotty$tools$scaladoc$tasty$TypesSupport$$inner(TypesSupport.scala:190)
[warn] 7 |    ???
[warn] two warnings found
[info] Main Scala API documentation successful.

Expectation

smarter commented 3 years ago

https://github.com/lampepfl/dotty/blob/d81b0e502dd29e24d8594d48da3f405d4ea75c51/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala#L84 attempts to exhaustively match on all possibly types, but there's no extractor for LazyRef in tasty-reflect. @romanowski What is this code used for? @nicolasstucki is there a good way to handle all types? In the compiler a common pattern is to match on TypeProxy and recurse on .underlying but I don't see a TypeProxy in tasty-reflect.

odersky commented 3 years ago

Maybe the type extractors could skip a LazyRef? But then we would have no natural recursion brake anymore.

pikinier20 commented 3 years ago

https://github.com/lampepfl/dotty/blob/d81b0e502dd29e24d8594d48da3f405d4ea75c51/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala#L84

attempts to exhaustively match on all possibly types, but there's no extractor for LazyRef in tasty-reflect. @romanowski What is this code used for? @nicolasstucki is there a good way to handle all types? In the compiler a common pattern is to match on TypeProxy and recurse on .underlying but I don't see a TypeProxy in tasty-reflect.

The code you attached is meant to construct showable representation of type (strings and links). LazyRefs probably need to be handled there to avoid MatchErrors.