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 error in wild mix of pattern matching and existentials #1048

Closed
scabug opened this issue Jun 16, 2008 · 4 comments
Closed

Assertion error in wild mix of pattern matching and existentials #1048

scabug opened this issue Jun 16, 2008 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jun 16, 2008

Compiling the following code,

trait T[U] {
  def x: T[V] forSome { type V <: U }
}
  
object T {
  def unapply[U](t: T[U]): Option[T[V] forSome { type V <: U }] = Some(t.x)
}
  
def f[W](t: T[W]) = t match {
  case T(T(_)) => ()
}

has the compiler crash with the following stack trace.

Exception in thread "main" java.lang.AssertionError: assertion failed: T(_) ==> Test.this.T.unapply[Nothing](<unapply-selector>) <unapply> (_), pt = Test.T[?] forSome { type V <: W }
	at scala.Predef$$.assert(Predef.scala:92)
	at scala.tools.nsc.typechecker.Typers$$Typer.doTypedApply(Typers.scala:1837)
	at scala.tools.nsc.typechecker.Typers$$Typer.doTypedApply(Typers.scala:1756)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedApply$$1(Typers.scala:2553)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3140)
	at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3243)
	at scala.tools.nsc.typechecker.Typers$$Typer.typedArg(Typers.scala:1591)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedArgs$$2.apply(Typers.scala:1607)
	at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$typedArgs$$2.apply(Typers.scala:1607)
	...

The crash is not reproducible when case classes are used.

I have no idea as to whether this program should be rejected, or if a sensible type can be given to it.

@scabug
Copy link
Author

scabug commented Jun 16, 2008

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

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug
Copy link
Author

scabug commented Mar 15, 2011

Mikhail Vorozhtsov (mikhail.vorozhtsov) said:
I have a simpler (certainly not "wild") example which produces the same stack trace as the original snippet on 2.8.1 and 2.9.0.r24458-b20110315020117:

final case class W[A](v: A)

object E {
  def unapply(w: W[Any]): Option[Any] = None
}

object Bug {
  def bug[A](e: Either[W[_], A]) = e match {
    case Left(E(x)) =>
    case _ =>
  }
}

@scabug
Copy link
Author

scabug commented Jul 13, 2011

Commit Message Bot (anonymous) said:
(extempore in r25277) Bounded wildcard types arising during pattern type inference can
cause unnecessary crashes. Closes #1048, review by odersky.

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