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

Regression involving existential types and pattern matching #5399

Closed
scabug opened this Issue Jan 23, 2012 · 9 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Jan 23, 2012

The following code compiles without errors in 2.9.1, but fails in 2.10.0-SNAPSHOT (2.10.0.rdev-4232-2012-01-23-g9a20086). This looks related to Martin's fix on Jan. 21:
scala/scala@2e092d4

class Foo {
  trait Init[T]
  class ScopedKey[T] extends Init[T]

  trait Setting[T] {
    val key: ScopedKey[T]
  }

  case class ScopedKey1[T](val foo: Init[T]) extends ScopedKey[T]

  val scalaHome: Setting[Option[String]] = null
  val scalaVersion: Setting[String] = null

  def testPatternMatch(s: Setting[_]) {
    s.key match {
      case ScopedKey1(scalaHome.key | scalaVersion.key) => ()
    }
  }
}

Errors when compiled with trunk:

existential.scala:34: error: type mismatch;
 found   : Foo.this.ScopedKey[Option[String]]
 required: Foo.this.Init[Any]
Note: Option[String] <: Any, but trait Init is invariant in type T.
You may wish to define T as +T instead. (SLS 4.5)
      case ScopedKey1(scalaHome.key | scalaVersion.key) => ()
                                ^
existential.scala:34: error: type mismatch;
 found   : Foo.this.ScopedKey[String]
 required: Foo.this.Init[Any]
Note: String <: Any, but trait Init is invariant in type T.
You may wish to define T as +T instead. (SLS 4.5)
      case ScopedKey1(scalaHome.key | scalaVersion.key) => ()
                                                   ^
two errors found
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 23, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5399?orig=1
Reporter: @dragos
Affected Versions: 2.10.0
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 23, 2012

@odersky said:
In fact, my suspicion is that it's the virtual pattern matcher. Not sure whether the pattern matcher is right to refuse or not. Assigning to Adriaan.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 23, 2012

@dragos said:
I'm not sure either.

For the record, I opened related ticket #5400. It might be a duplicate as it involves the same actors, but the error is different.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 23, 2012

@gkossakowski said:
AFAIK, virtual pattern matcher kicks in only -Yvirtpatmat is supplied. It's off by default.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 24, 2012

@paulp said:
This also regressed with r25935 aka scala/scala@22d125f

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 24, 2012

@paulp said:
Closed #5400 as a duplicate since it regressed in the same commit. Here's the source for an additional test case.

class Test {
  type AnyCyclic = Execute[Task]#CyclicException[_]

  trait Task[T]

  trait Execute[A[_] <: AnyRef] {
    class CyclicException[T](val caller: A[T], val target: A[T])
  }

  def convertCyclic(c: AnyCyclic): String =
    (c.caller, c.target) match {
      case (caller: Task[_], target: Task[_]) => "bazinga!"
    }
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jan 24, 2012

@paulp said:
Another test case for when this is fixed.

  trait TFn1B {
    type In
    type Out
    type Apply[T <: In] <: Out
  }

  trait TFn1[I, O] extends TFn1B {
    type In = I
    type Out = O
  }

  trait >>[F1 <: TFn1[_, _], F2 <: TFn1[_, _]] extends TFn1[F1#In, F2#Out] {
    type Apply[T] = F2#Apply[F1#Apply[T]]
  }
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Feb 23, 2012

@adriaanm said:
minimal version of the AnyCyclic test case:

class Test {
  class A[T]
  class B[T](val a: A[T])

  case class CaseClass[T](x: T)

  def break(existB: B[_]) =
    CaseClass(existB.a) match { case CaseClass(_) => }
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jun 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment