Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertion failure in typer with nested match and existentials #1357

Closed
scabug opened this issue Sep 20, 2008 · 6 comments
Closed

assertion failure in typer with nested match and existentials #1357

scabug opened this issue Sep 20, 2008 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 20, 2008

This occurred against 2.7.2 RC2 (and RC1). See attached file for code.

java.lang.AssertionError: assertion failed: NonEmptyCons((head @ *), (tail @ *)) ==> NonEmptyCons.unapplyNothing, Nothing ((head @ *), (tail @ *)), pt = ?
at scala.Predef$$.assert(Predef.scala:92)
at scala.tools.nsc.typechecker.Typers$$Typer.doTypedApply(Typers.scala:1892)
at scala.tools.nsc.typechecker.Typers$$Typer.doTypedApply(Typers.scala:1811)
at scala.tools.nsc.typechecker.Typers$$Typer.typedApply$$1(Typers.scala:2619)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3219)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typedPattern(Typers.scala:3390)
at scala.tools.nsc.typechecker.Typers$$Typer.typedCase(Typers.scala:1419)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1442)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1440)
at scala.List$$.loop$$1(List.scala:293)
at scala.List$$.mapConserve(List.scala:310)
at scala.tools.nsc.typechecker.Typers$$Typer.typedCases(Typers.scala:1440)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3135)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typedBlock(Typers.scala:1405)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3083)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3371)
at scala.tools.nsc.typechecker.Typers$$Typer.typedCase(Typers.scala:1422)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1442)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedCases$$1.apply(Typers.scala:1440)
at scala.List$$.loop$$1(List.scala:293)
at scala.List$$.mapConserve(List.scala:310)
at scala.tools.nsc.typechecker.Typers$$Typer.typedCases(Typers.scala:1440)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3135)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3371)
at scala.tools.nsc.typechecker.Typers$$Typer.transformedOrTyped(Typers.scala:3429)
at scala.tools.nsc.typechecker.Typers$$Typer.typedDefDef(Typers.scala:1342)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3059)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3360)
at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:1570)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1615)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1615)
at scala.List$$.loop$$1(List.scala:293)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:1615)
at scala.tools.nsc.typechecker.Typers$$Typer.typedTemplate(Typers.scala:1193)
at scala.tools.nsc.typechecker.Typers$$Typer.typedModuleDef(Typers.scala:1086)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3053)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3360)
at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:1570)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1615)
at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1615)
at scala.List$$.loop$$1(List.scala:293)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.List$$.loop$$1(List.scala:297)
at scala.List$$.mapConserve(List.scala:310)
at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:1615)
at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3046)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3323)
at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3360)
at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$2.apply(Analyzer.scala:40)
at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:268)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:247)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:247)
at scala.Iterator$$class.foreach(Iterator.scala:410)
at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:266)
at scala.tools.nsc.Global$$GlobalPhase.run(Global.scala:247)
at scala.tools.nsc.Global$$Run.compileSources(Global.scala:579)
at scala.tools.nsc.Global$$Run.compile(Global.scala:663)
at scala.tools.ant.Scalac.execute(Scalac.scala:574)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:394)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:273)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:486)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)

@scabug
Copy link
Author

scabug commented Sep 20, 2008

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

@scabug
Copy link
Author

scabug commented Sep 20, 2008

@eengbrec said:
// I can't seem to find the "Attach file" button, so here's the code

package constreecompilercrash

object ConsCell {
// Here I'm trying to fake out the compiler into letting me define
// what would more logically be a recursive type. It could be that this
// should be illegal and that's why it is crashing the typer later on.
type BT[+H, +T <: ConsCell[ConsCell[H, T], ConsCell[H, T]]] = ConsCell[H, T]
type BinaryTree[+E] = BT[E, T forSome {type T <: ConsCell[BT[E, T], BT[E, T]]}]

def apply[H, T](h: H, t: T): ConsCell[H, T] = BasicConsCell(h, t)

private case class BasicConsCell[+H, +T](val head: H, val tail: T) extends ConsCell[H, T]
}

sealed trait ConsCell[+H, +T] {
def ::[A](obj: A): ConsCell[A, ConsCell[H, T]] = ConsCell(obj, this)
}

object NonEmptyCons {
def unapply[H, T](c: ConsCell[H, T]): Option[(H, T)] = c match {
case Nil => None
case c: NonEmptyCons[H, T] => Some(c.head, c.tail)
}
}

trait NonEmptyCons[+H, +T] extends ConsCell[H, T] {
def head: H
def tail: T
}

object Nil extends ConsCell[Nothing, Nothing]

object Main {

import ConsCell._

def main(args: Array[String]) {
val t1 = 1 :: Nil // looks like a list, doesn't it?
val t2 = 1 :: ConsCell((2 :: Nil), (3 :: Nil))
walkTree(t1, println)
walkTree(t2, println)
}

def walkTree[E](tree: BinaryTree[E], op: E => Unit): Unit = tree match {
case Nil => ()
case NonEmptyCons(head, tail) => {
op(head)
tail match {
case Nil => ()
case NonEmptyCons(head, tail) => {
walkTree(tail.head, op)
walkTree(tail.tail, op)
}
}
}
}
}

@scabug
Copy link
Author

scabug commented Sep 28, 2008

@TiarkRompf said:
Here's a reduced version that also fails. Removing the inner match makes it pass the typer. Replacing the extractors with tuple patterns makes it pass the typer but will cause a crash in ParallelMatching during explicit outer.

object NonEmptyCons {
  def unapply[H, T](c: (H, T)): Option[(H, T)] = Some(c)
}


object Main {

  type BT[+H, +T <: Tuple2[Tuple2[H, T], Tuple2[H, T]]] = Tuple2[H, T]
  
  type BinaryTree[+E] = BT[E, T forSome {type T <: Tuple2[BT[E, T], BT[E, T]]}]

  def foo[E](tree: BinaryTree[E]): Unit = tree match {
    case NonEmptyCons(_, tail) => {
      tail match {
        case NonEmptyCons(_, _) => {
        }
      }
    }
  }
}

@scabug
Copy link
Author

scabug commented Oct 6, 2009

@paulp said:
Once again I can't pin which commit fixed a ticket, but the test case is in r18937.

@scabug
Copy link
Author

scabug commented Nov 22, 2009

@odersky said:
This re-surfaced with the fix to #2635. The problem seems to be deep in the constraint variable solver which can produce solutions that then do not conform to bounds. A simpler test case is here (in pending/pos/depexists.scala):

 val c: Cell[(a, b)] forSome { type a <: Number; type b <: (a, a) } = null
 val d = c

I defer until we redo the whole approach to constraint solving (which we should do, soon).

@scabug
Copy link
Author

scabug commented Jan 20, 2011

@paulp said:
That test has been in files/pos for a year now so I think it's time to close this ticket; I'm sure we'll have no trouble finding issues of more recent vintage.

@scabug scabug closed this as completed May 18, 2011
@scabug scabug added the crash label Apr 6, 2017
@scabug scabug added this to the 2.8.0 milestone Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants