scala / scala3

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

Following code causes compiler to crash with: `NoSuchElementException: head of empty list @ core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)` #13238

Closed GavinRay97 closed 2 years ago

GavinRay97 commented 3 years ago

Compiler version

3.0.0

Minimized code

https://scastie.scala-lang.org/L6jYE1KFSYqlUA5S8UPfwg

// libraryDependencies += "com.github.pathikrit" % "better-files_2.13" % "3.9.1"
case class FilenameWithPath(filename: String, path: java.nio.file.Path)
def extractFile(it: FilenameWithPath): java.io.File =
  val file: better.files.File = better.files.File(it.path).renameTo(it.filename)
  file.unzipTo(file.parent / file.nameWithoutExtension)

It's the file.unzipTo line -- that code is here if it matters:

Output (click arrow to expand)

```scala java.util.NoSuchElementException: head of empty list at scala.collection.immutable.Nil$.head(List.scala:662) at scala.collection.immutable.Nil$.head(List.scala:661) at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312) at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312) at dotty.tools.dotc.core.SymDenotations$SymDenotation.paramSymss(SymDenotations.scala:329) at dotty.tools.dotc.typer.Typer.paramSymWithMethodTree$3(Typer.scala:3342) at dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1$$anonfun$1(Typer.scala:3354) at dotty.tools.dotc.reporting.NoExplanation.msg(Message.scala:133) at dotty.tools.dotc.reporting.Message.message(Message.scala:88) at dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:100) at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16) at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10) at dotty.tools.dotc.reporting.AbstractReporter.isHidden(AbstractReporter.scala:8) at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:148) at dotty.tools.dotc.report$.error(report.scala:71) at dotty.tools.dotc.typer.Typer.issueErrors$2$$anonfun$2(Typer.scala:3356) at scala.runtime.function.JProcedure3.apply(JProcedure3.java:15) at scala.runtime.function.JProcedure3.apply(JProcedure3.java:10) at scala.collection.LazyZip3.foreach(LazyZipOps.scala:248) at dotty.tools.dotc.typer.Typer.issueErrors$3(Typer.scala:3358) at dotty.tools.dotc.typer.Typer.addImplicitArgs$2$$anonfun$2(Typer.scala:3382) at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2954) at dotty.tools.dotc.typer.Typer.addImplicitArgs$3(Typer.scala:3383) at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$2(Typer.scala:3401) at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3598) at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3811) at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3163) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943) at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1029) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2703) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943) at dotty.tools.dotc.typer.Typer.$anonfun$34(Typer.scala:2168) at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225) at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2168) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2672) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899) at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2354) at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2683) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2687) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899) at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2477) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2728) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943) at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79) at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84) at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43) at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85) at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:333) at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120) at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) at dotty.tools.dotc.Run.runPhases$5(Run.scala:216) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:224) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67) at dotty.tools.dotc.Run.compileUnits(Run.scala:231) at dotty.tools.dotc.Run.compileSources(Run.scala:166) at dotty.tools.dotc.Run.compile(Run.scala:150) at dotty.tools.dotc.Driver.doCompile(Driver.scala:39) at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88) at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528) at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:175) at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:173) at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459) at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414) at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501) at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401) at sbt.internal.inc.Incremental$.apply(Incremental.scala:167) at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482) at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420) at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2357) at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2314) at sbt.internal.io.Retry$.apply(Retry.scala:46) at sbt.internal.io.Retry$.apply(Retry.scala:28) at sbt.internal.io.Retry$.apply(Retry.scala:23) at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31) at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2310) at scala.Function1.$anonfun$compose$1(Function1.scala:49) at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) at sbt.std.Transform$$anon$4.work(Transform.scala:68) at sbt.Execute.$anonfun$submit$2(Execute.scala:282) at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) at sbt.Execute.work(Execute.scala:291) at sbt.Execute.$anonfun$submit$1(Execute.scala:282) at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) at sbt.CompletionService$$anon$2.call(CompletionService.scala:64) ```
griggt commented 3 years ago

Minimized to:

foo.scala

// Compile with Scala 2.13
trait Bar
class Foo {
  def foo(out: Foo)(implicit bar: Bar): out.type = out
}

boom.scala

// no implicit of type Bar in scope
def boom(foo: Foo) = foo.foo(foo)
$ scalac -version && dotc -version
Scala compiler version 2.13.6 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.
Scala compiler version 3.0.3-RC1-bin-SNAPSHOT-git-814fca6 -- Copyright 2002-2021, LAMP/EPFL

$ scalac foo.scala 
$ dotc boom.scala
exception occurred while typechecking boom.scala
exception occurred while compiling boom.scala
java.util.NoSuchElementException: head of empty list while compiling boom.scala
Exception in thread "main" java.util.NoSuchElementException: head of empty list
    at scala.collection.immutable.Nil$.head(List.scala:662)
    at scala.collection.immutable.Nil$.head(List.scala:661)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.paramSymss(SymDenotations.scala:329)
    at dotty.tools.dotc.typer.Typer.paramSymWithMethodTree$3(Typer.scala:3344)
    at dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1$$anonfun$1(Typer.scala:3356)
    at dotty.tools.dotc.reporting.NoExplanation.msg(Message.scala:132)
    at dotty.tools.dotc.reporting.Message.message(Message.scala:87)
    at dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:99)
    at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16)
    at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10)
    at dotty.tools.dotc.reporting.AbstractReporter.isHidden(AbstractReporter.scala:8)
    at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:148)
    at dotty.tools.dotc.report$.error(report.scala:71)
    at dotty.tools.dotc.typer.Typer.issueErrors$2$$anonfun$2(Typer.scala:3358)
    at scala.runtime.function.JProcedure3.apply(JProcedure3.java:15)
    at scala.runtime.function.JProcedure3.apply(JProcedure3.java:10)
    at scala.collection.LazyZip3.foreach(LazyZipOps.scala:248)
    at dotty.tools.dotc.typer.Typer.issueErrors$3(Typer.scala:3360)
    at dotty.tools.dotc.typer.Typer.addImplicitArgs$3(Typer.scala:3386)
    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$2(Typer.scala:3403)
    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3600)
    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3813)
    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3165)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2824)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2828)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2944)
    at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1424)
    at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1414)
    at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1424)
    at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1676)
    at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
    at dotty.tools.dotc.typer.Namer.typedAheadRhs$2(Namer.scala:1676)
    at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1684)
    at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1711)
    at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1712)
    at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1723)
    at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1463)
    at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1470)
    at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1554)
    at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:755)
    at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:887)
    at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:779)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
    at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
    at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
    at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2638)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2663)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2824)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2828)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2850)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2900)
    at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2355)
    at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2684)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2688)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2824)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2828)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2850)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2900)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2478)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2729)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2759)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2824)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2828)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2944)
    at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
    at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
    at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:333)
    at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120)
    at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
    at dotty.tools.dotc.Run.runPhases$5(Run.scala:216)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:224)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:231)
    at dotty.tools.dotc.Run.compileSources(Run.scala:166)
    at dotty.tools.dotc.Run.compile(Run.scala:150)
    at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
    at dotty.tools.dotc.Driver.process(Driver.scala:199)
    at dotty.tools.dotc.Driver.process(Driver.scala:167)
    at dotty.tools.dotc.Driver.process(Driver.scala:179)
    at dotty.tools.dotc.Driver.main(Driver.scala:209)
    at dotty.tools.dotc.Main.main(Main.scala)