Scala Programming Language
  1. Scala Programming Language
  2. SI-1048

Assertion error in wild mix of pattern matching and existentials

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Martin Odersky added a comment -

        Milestone postponed deleted

        Show
        Martin Odersky added a comment - Milestone postponed deleted
        Hide
        Mikhail Vorozhtsov added a comment -

        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 _ =>
          }
        }
        
        Show
        Mikhail Vorozhtsov added a comment - 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 _ => } }
        Hide
        Commit Message Bot added a comment -

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

        Show
        Commit Message Bot added a comment - (extempore in r25277 ) Bounded wildcard types arising during pattern type inference can cause unnecessary crashes. Closes #1048, review by odersky.

          People

          • Assignee:
            Martin Odersky
            Reporter:
            Gilles Dubochet
            TracCC:
            Mikhail Vorozhtsov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development