[英]Scala SBT compile hangs (SBT 1.5.0, Scala 2.13.5, Java 11.0.10)
在我的項目中,Scala/SBT 構建在compile
步驟中無限掛起。 重現:
git clone https://github.com/gdiet/backup.git
cd backup
# fist the good case - compiles in less than 30s (when dependencies are fetched etc. etc.)
git checkout e8bdc8a1e878bd15129f08b20df51d54ebd86e4a
sbt compile
# now the problem - compile hangs infinitely
git checkout b273a531c19ad68600026429643e13c6d2761c16
sbt compile
(抱歉,我無法創建一個最小的演示示例。)“干凈”沒有幫助。 我可以使用 SBT、IntelliJ IDEA 和 Docker 在我的 Linux 系統上重現該問題。 對於 Docker,運行
# reproduce the problem in Docker - compile hangs infinitely
git checkout b273a531c19ad68600026429643e13c6d2761c16
./build-app.sh
問題:
我怎樣才能...? 我只需要將問題減少到最小的 scope。 這就是我到達那里的方式:
sbt compile
掛起或scalac
是否也掛起(確實如此)。 在后一種情況下, scalac
是罪魁禍首。Vector
類型系統應該需要一個LazyList
。 將其更改為LazyList
,一切都按預期工作。 (請參見下面的最小示例。)我現在導致 scalac (scala 2.13.5) 掛起的最小示例是:
object CompileHangs {
def read1(): LazyList[Either[(Int, Int), String]] = ???
def read2(): Option[LazyList[Either[(Int, Int), String]]] = ???
def read(): LazyList[Either[(Int, Int), String]] =
read1().flatMap {
case Right(_) => LazyList()
case Left(value) =>
read2().getOrElse(
// LazyList instead of Vector would be the correct thing here.
// Use it and everything works as expected.
Vector(Left(value))
)
}
}
有趣的方面觀察:如果我將Either[(Int, Int), String]
切換到Either[Int, String]
,即使使用Vector
,編譯也可以正常工作,盡管我預計會出現類型檢查錯誤。
我現在將為scalac
創建一個錯誤報告。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.