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

spurious type error involving type variable pattern #9498

Closed
scabug opened this issue Sep 30, 2015 · 4 comments
Closed

spurious type error involving type variable pattern #9498

scabug opened this issue Sep 30, 2015 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 30, 2015

trait Inv[A] { def head: A }
trait Cov[+A] { def head: A }

class Test {
  def inv(i: Inv[Inv[String]]) = i match {
    case l: Inv[a] =>
      val x: a = l.head
      x.head: String // okay
  }

  def cov(c: Cov[Cov[String]]) = c match {
    case l: Cov[a] =>
      val x: a = l.head
      x.head: String // was: found A, required String
  }

  def cov1(c: Cov[Cov[String]]) = c match {
    case l: Cov[a] => l.head.head
  }
  cov1(null): String // was: found A, required String

  def cov3(c: Cov[Cov[String]]): String = c match {
    case l: Cov[a] => val l1: l.type = l; l1.head.head
  }
}

Patch pending

@scabug
Copy link
Author

scabug commented Sep 30, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9498?orig=1
Reporter: @retronym
Affected Versions: 2.11.7

@scabug
Copy link
Author

scabug commented Sep 30, 2015

@SethTisue said:
bug spotted by Andrew Phillips. List[List[String]] is used in SLS 8.3 as an example in the discussion of type variables, so we were surprised that it didn't behave as advertised. (Jason's boil-down substitutes Cov for List.)

@scabug
Copy link
Author

scabug commented Sep 30, 2015

@SethTisue said:
Jason's PR with fix: scala/scala#4774

@scabug
Copy link
Author

scabug commented Sep 30, 2015

@demobox said (edited on Sep 30, 2015 12:20:50 PM UTC):
Thanks for spending time on this, @retronym and @SethTisue - much appreciated. I'm sure you both have more commonly-used fish to fry ;-)

@scabug scabug closed this as completed Oct 5, 2015
@scabug scabug added this to the 2.12.0-M3 milestone Apr 7, 2017
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