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

Regression: cannot pattern match on type T[_] when T's type parameter has bounds #7716

Closed
scabug opened this issue Aug 4, 2013 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 4, 2013

Upon entering this code into the REPL:

trait TA[X <: CharSequence]
val ta: TA[_] = new TA[String] {}

ta match {
case _ => "hi"
}

I get this error:

error: type arguments [_$1] do not conform to trait TA's type parameter bounds [X <: CharSequence]
              ta match {
              ^

The code compiles on Scala 2.9.2, but fails on at least 2.10.0 and 2.10.2. Thus it appears to be a regression.

@scabug
Copy link
Author

scabug commented Aug 4, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7716?orig=1
Reporter: Alex Hvostov (argv)
Affected Versions: 2.10.0, 2.10.2
See #7694

@scabug
Copy link
Author

scabug commented Aug 4, 2013

@paulp said:
Some workarounds:

  • compile with -Xoldpatmat
  • val ta: TA[_ <: CharSequence] = new TA[String] {}
  • val ta = new TA[String] {}

In some similar scenarios this already works again in 2.11, e.g.

def f(ta: TA[_]) = ta match { case _ => "hi" }

But the val example isn't compiling even now.

@scabug
Copy link
Author

scabug commented Aug 5, 2013

Alex Hvostov (argv) said:
Sorry about the overstated priority, by the way. JIRA wasn't letting me adjust it from "blocker" for some reason.

@scabug
Copy link
Author

scabug commented Aug 16, 2013

@retronym said:
Another example from the mailing list:

scala> val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS

scala> e match { case _ => 0 }
<console>:9: error: type arguments [_$1] do not conform to class Enum's type parameter bounds [E <: Enum[E]]
              e match { case _ => 0 }
              ^
[[syntax trees at end of                 refchecks]] // <console>
package $line4 {
  object $read extends scala.AnyRef {
    def <init>(): $line4.$read.type = {
      $read.super.<init>();
      ()
    };
    object $iw extends scala.AnyRef {
      def <init>(): type = {
        $iw.super.<init>();
        ()
      };
      object $iw extends scala.AnyRef {
        def <init>(): type = {
          $iw.super.<init>();
          ()
        };
        private[this] val res0: Int = {
          case <synthetic> val x1: Enum[_$1] = $line3.$read.$iw.$iw.e;
          case4(){
            matchEnd3(0)
          };
          matchEnd3(x: Int){
            x
          }
        };
        <stable> <accessor> def res0: Int = $iw.this.res0
      }
    }
  }
}

This is somewhat related to #7694; the pattern matcher translation now happens before refchecks, and the TypeTree in the tpt of the synthetic temporary x1 is subject to bounds checking.

@scabug
Copy link
Author

scabug commented Aug 16, 2013

@retronym said:
scala/scala#2838

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

No branches or pull requests

2 participants