scala / bug

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

crash with higher kinded types in patterns, depends on order of scalac args #4070

Closed scabug closed 12 years ago

scabug commented 13 years ago

What steps will reproduce the problem (please be specific and use wikiformatting)?

scalac ACompileFirst.scala BCompileSecond.scala

There is no error if the order of the arguments is reversed!

File ACompileFirst.scala:

trait FooBar {
  val IR: FooOpsExp
  import IR._

  def foobar(rhs: Def[_]) : Unit = rhs match {
      case m: DeliteOpMap[_,_,creatingThisTypeVarFails] =>
  }
}

File BCompileSecond.scala:

trait FooOpsExp {

  abstract class Def[B]

  abstract class DeliteCollection[A]

  abstract case class DeliteOpMap[A,B,C[X] <: DeliteCollection[X]]() extends Def[C[B]]
}

What is the expected behavior? Compiling without error.

What do you see instead?

When constructing a TypeVar for creatingThisTypeVarFails, typeArgs is List(?_) but params is empty. Assertivity ensues:

Exception in thread "main" java.lang.AssertionError: assertion failed
    at scala.Predef$$.assert(Predef.scala:100)
    at scala.tools.nsc.symtab.Types$$TypeVar.<init>(Types.scala:2281)
    at scala.tools.nsc.symtab.Types$$TypeVar$$.apply(Types.scala:2266)
    at scala.tools.nsc.symtab.Types$$TypeVar.applyArgs(Types.scala:2299)
    at scala.tools.nsc.symtab.Types$$class.appliedType(Types.scala:2743)
    at scala.tools.nsc.symtab.SymbolTable.appliedType(SymbolTable.scala:13)
    at scala.tools.nsc.symtab.Types$$SubstMap.apply(Types.scala:3449)
    at scala.tools.nsc.symtab.Types$$SubstMap.apply(Types.scala:3399)
    at scala.tools.nsc.symtab.Types$$TypeMap$$$$anonfun$$mapOverArgs$$1.apply(Types.scala:3104)
    at scala.tools.nsc.symtab.Types$$TypeMap$$$$anonfun$$mapOverArgs$$1.apply(Types.scala:3100)
    at scala.tools.nsc.symtab.Types$$class.map2Conserve(Types.scala:4833)
    at scala.tools.nsc.symtab.SymbolTable.map2Conserve(SymbolTable.scala:13)
    at scala.tools.nsc.symtab.Types$$TypeMap.mapOverArgs(Types.scala:3100)
    at scala.tools.nsc.symtab.Types$$TypeMap.mapOver(Types.scala:3010)
    at scala.tools.nsc.symtab.Types$$SubstMap.apply(Types.scala:3434)
    at scala.tools.nsc.symtab.Types$$Type.subst(Types.scala:590)
    at scala.tools.nsc.symtab.Types$$Type.instantiateTypeParams(Types.scala:431)
    at scala.tools.nsc.symtab.Types$$TypeRef.instantiateTypeParams(Types.scala:1792)
    at scala.tools.nsc.symtab.Types$$TypeRef.transform(Types.scala:1700)
    at scala.tools.nsc.symtab.Types$$TypeRef.baseType(Types.scala:1862)
    at scala.tools.nsc.symtab.Types$$class.firstTry$$1(Types.scala:4520)
    at scala.tools.nsc.symtab.Types$$class.scala$$tools$$nsc$$symtab$$Types$$$$isSubType2(Types.scala:4679)
    at scala.tools.nsc.symtab.Types$$$$anonfun$$isSubType$$1.apply$$mcZ$$sp(Types.scala:4388)
    at scala.tools.nsc.symtab.Types$$undoLog$$.undoUnless(Types.scala:136)
    at scala.tools.nsc.symtab.Types$$class.isSubType(Types.scala:4375)
    at scala.tools.nsc.symtab.SymbolTable.isSubType(SymbolTable.scala:13)
    at scala.tools.nsc.symtab.Types$$Type.$$less$$colon$$less(Types.scala:645)
    at scala.tools.nsc.typechecker.Infer$$Inferencer.inferTypedPattern(Infer.scala:1395)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4218)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedBind$$1(Typers.scala:3089)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4122)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedPattern(Typers.scala:4507)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedCase(Typers.scala:1975)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1996)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1995)
    at scala.collection.immutable.List.loop$$1(List.scala:119)
    at scala.collection.immutable.List.mapConserve(List.scala:135)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedCases(Typers.scala:1995)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4162)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.transformedOrTyped(Typers.scala:4563)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedDefDef(Typers.scala:1788)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4078)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2120)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2203)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2203)
    at scala.collection.immutable.List.loop$$1(List.scala:119)
    at scala.collection.immutable.List.mapConserve(List.scala:135)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2203)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedTemplate(Typers.scala:1550)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedClassDef(Typers.scala:1311)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4069)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:2120)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2203)
    at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$24.apply(Typers.scala:2203)
    at scala.collection.immutable.List.loop$$1(List.scala:119)
    at scala.collection.immutable.List.mapConserve(List.scala:135)
    at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:2203)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:4065)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4418)
    at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:4467)
    at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3.apply(Analyzer.scala:87)
    at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply$$mcV$$sp(Global.scala:330)
    at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:330)
    at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:330)
    at scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:48)
    at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:330)
    at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3$$$$anonfun$$run$$1.apply(Analyzer.scala:82)
    at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3$$$$anonfun$$run$$1.apply(Analyzer.scala:82)
    at scala.collection.Iterator$$class.foreach(Iterator.scala:633)
    at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:311)
    at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$3.run(Analyzer.scala:82)
    at scala.tools.nsc.Global$$Run.compileSources(Global.scala:863)
    at scala.tools.nsc.Global$$Run.compile(Global.scala:943)
    at scala.tools.nsc.Main$$.process(Main.scala:106)
    at scala.tools.nsc.Main$$.main(Main.scala:122)
    at scala.tools.nsc.Main.main(Main.scala)

What versions of the following are you using? Scala:r23727 Java:1.6.0_20 Operating system: Mac 10.6

scabug commented 13 years ago

Imported From: https://issues.scala-lang.org/browse/SI-4070?orig=1 Reporter: @TiarkRompf

scabug commented 13 years ago

@adriaanm said: I have a fix for the immediate cause (see https://github.com/adriaanm/scala/tree/ticket/4070), but that revealed that a full fix will require higher-kinded existentials, which are a pending enhancement.

I haven't investigating yet why compilation order matters, but I suspect the bug is rather that the other way around somehow masks the problem that you see in the order that reveals the crash.

scabug commented 13 years ago

@adriaanm said: of course i should have investigated why compilation order matters first -- pursuing a fix for that, hoping it doesn't cause any spurious cyclic errors

scabug commented 13 years ago

@TiarkRompf said: There seems to be another related error:

 // file DeliteOps.scala
  trait DeliteOpMap[A,B,C[X] <: DeliteCollection[X]] extends DeliteOp[C[B]] with DeliteOpMapLikeWhileLoopVariant {
    val in: Exp[C[A]]
    val v: Sym[A]
    val func: Exp[B]
    val alloc: Exp[C[B]]
    ...
  }

  // file DeliteGenTaskGraph.scala

   case map: DeliteOpMap[_,_,_] => ...  gen.remap(map.alloc.Type) ...

Depending on compilation order, this throws an exception "head of empty list at Infer.scala 1029". This kind of error is rather unfortunate because it makes using IDEs very brittle (workaround: comment, make, uncomment, make, sigh).

scabug commented 12 years ago

@paulp said: Here it is minimized a ways, and with only one source file. It's still order-dependent: if you move the class definitions before the method definition, it no longer crashes. Which is more than a little scary all by itself.

trait Foo {
  def crash(x: Dingus[_]) = x match { case m: Bippy[tv] => }

  class Dingus[T]
  class Bippy[CC[X] <: Seq[X]]() extends Dingus[CC[Int]]
}

It's easy enough to make this stop crashing, but not so easy to fix it without existential type constructors. I had a vision that adriaan will fix it.

scabug commented 12 years ago

@adriaanm said: for the record, suggested workaround: replace _ by Any

scabug commented 12 years ago

@paulp said: I can't crash it this way anymore as of f39537a369 , tiark please let me know if it's still an issue.