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

Cannot inference existential type in 2.10 #6679

Closed
scabug opened this issue Nov 17, 2012 · 7 comments
Closed

Cannot inference existential type in 2.10 #6679

scabug opened this issue Nov 17, 2012 · 7 comments

Comments

@scabug
Copy link

scabug commented Nov 17, 2012

This code compiles in 2.9.2, and does not compile in 2.10.x

class ExistentialTypeInference[A](a: A) {
  type Type = A
}

object ExistentialTypeInference {

  def main(args: Array[String]) {
    val arraySeq = Seq[Array[_]](
      Array(1, 2),
      Array("2", "3"))
    for (array <- arraySeq) {
      val t = new ExistentialTypeInference(array)
      val array2:t.Type = array: t.Type
    }
  }
}
@scabug
Copy link
Author

scabug commented Nov 17, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6679?orig=1
Reporter: @Atry
Affected Versions: 2.10.0-M1, 2.10.0-M2, 2.10.0-M3, 2.10.0-M4, 2.10.0-M5, 2.10.0-M6, 2.10.0-M7, 2.10.0-RC1, 2.10.0-RC2
See #5120

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@retronym said (edited on Nov 17, 2012 9:59:34 PM UTC):
Perhaps the same as: #5330, which will have a fix in 2.10.1

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@retronym said:
This still fails on the 2.10.x branch which includes the fix for #5330, #6014.

@scabug
Copy link
Author

scabug commented Nov 18, 2012

@retronym said:
The regression is prehistoric as so far as scala-bisector is concerned; from builds I have at hand it's in the range: scala/scala@4afae5b...278a225

@scabug
Copy link
Author

scabug commented Nov 19, 2012

@retronym said:
The fix for #5120 prevents this from working. It might be that this is a 'feature' rather than a 'bug'; I'll leave that determination to Adriaan.

scala/scala@b7b81ca2

@scabug
Copy link
Author

scabug commented Dec 9, 2012

@paulp said:
The unwillingness to compile is correct. I reformulated the example a little to show a soundness failure; I'm not sure it's similar enough to convince everyone. The key is that the type system must not lose sight of the fact that these Arrays have an element type which is unknown and unknowable - if anyone ever thinks he has a value of the right type, then unsoundness has occurred (because that value would be assignable to both Array[Int] and Array[String]).

Allowing "Type" to be equated to type parameter "A" and then to go on its merry way unsoundly materializes that unknowable type.

class ExistentialTypeInference[A](val a: Array[A]) {
  type Type = A
  def put(x: Type) = a(0) = x
  // Even 2.9 knows better than to let this through:
  // def put(x: A) = a(0) = x
}

object ExistentialTypeInference {
  def main(args: Array[String]) {
    val arraySeq = Seq[Array[_]](Array(1, 2), Array("2", "3"))
    val t1       = new ExistentialTypeInference(arraySeq.head)
    val t2       = new ExistentialTypeInference(arraySeq.last)

    t1 put t2.a(0)
  }
}
/***
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source)
	at scala.runtime.ScalaRunTime$.array_update(ScalaRunTime.scala:69)
	at ExistentialTypeInference.put(b.scala:3)
	at ExistentialTypeInference$.main(b.scala:12)
	at ExistentialTypeInference.main(b.scala)
***/

And in 2.10, we fail as we must.

% rcscalac b.scala 
b.scala:12: error: type mismatch;
 found   : _$1
 required: t1.Type
    (which expands to)  _$1
    t1 put t2.a(0)
               ^
one error found

@scabug
Copy link
Author

scabug commented Dec 9, 2012

@paulp said:
Closing as Not a Bug unless moors shows up with some kind of O'Henry-style plot twist before final curtain.

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