[#1202] | project: compiler | priority: medium | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Burak | Martin | noise | 2007-07-10 12:49:19.0 | |
subject | existentials not scoped/captured properly | |||
code |
object foo { // example by Cardelli and Wegner val p: (a, (a=>Int)) forSome {type a} = (3,{y:Int=>y+1}) val z:Int = p._2(p._1) } |
|||
what happened | Burak-Emirs-MacBook-Pro:~/Documents/svn/foosvn buraq$ ../scala/build/quick/bin/scalac -d /tmp -explaintypes /tmp\ /ex.scala /tmp/ex.scala:3: error: type mismatch; found : Any required: Nothing val z:Int = p._2(p._1) ^ one error found |
|||
what expected | Since it is the very same p, type a is the same. If this is beyond the "automatic opening", there should be a proper "open" operation that lets us write p._2(p._1) -- maybe use pattern matching?
This is not legal Scala syntax (existentials not allowed in type tests), but might be a good way out.
p match {
case z: (a, (a=>Int)) forSome {type a} = z._2(z._1)
}
|
|||
[back to overview] |
Martin edited on 2007-07-14 13:10:14.0 |
Opening an existential type twice requires indeed a pattern match. Here is how it is done:
object foo { // example by Cardelli and Wegner val p: (a, (a=>Int)) forSome {type a} = (3,{y:Int=>y+1}) val z: Int = p match { case pp: (_, _) => pp._2(pp._1) } } |