--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
But you at least got a warning... I was getting the silent treatment by the compiler ;)
/Bjorn
Aha! Good to see it marked critical. But the bug text complains only about the absent warning. What about the false type inferred in my example? Shouldn't the type be Vector[Box[Any]] or something better than Vector[Box[Int]] which is clearly misleading...?
/Bjorn
From: scala...@googlegroups.com [mailto:scala...@googlegroups.com]
On Behalf Of Jason Zaugg
Sent: den 16 maj 2014 19:05
To: Björn Regnell
Cc: scala-user
Subject: Re: [scala-user] Could the compiler help me catch this?
--
The type is correct. The problem is that your partial function matched objects it should not match, because it could not tell the difference due to erasure.
--
How can this type be correct? (Or do I have too high hopes of the regularity of reality?)
Vector[Box[Int]] = Vector(Box(3), Box(x), Box(3.14))
Aha! Good to see it marked critical. But the bug text complains only about the absent warning. What about the false type inferred in my example? Shouldn't the type be Vector[Box[Any]] or something better than Vector[Box[Int]] which is clearly misleading...?
/Bjorn
Yes. But what is the compiler supposed to do when the bug is fixed? Just warn me or refuse?
If it just warns me and the code still compiles, then the inferred type would be the wrong one still?
/Bjorn
From: Jason Zaugg [mailto:jza...@gmail.com]
Sent: den 16 maj 2014 21:34
To: Björn Regnell
Cc: scala-user
--
If we want an escape hatch, couldn't we just pattern match againstcase x =>case x: Seq[_] =>instead ofcase x: T =>case x: Seq[T] =>and then just cast it ourselves after?
I was more thinking of making errors the *default*, and then using manual casting as the "escape":scala> (Nil: List[Any]) match { case is: List[_] => is.asInstanceOf[List[Int]] }
I mean, we already have a way of making unchecked type assertions, it's called casting =P Unless I'm missing something, @unchecked and similar don't actually provide any new capability, just a slightly-different syntax to do the same thing. My theory is that these sort of escape-hatches would be used rarely enough that a bit of verbosity isn't too bad.
> You'd have to write the cast twice if you refer the the bound pattern in a guard and in a case body
Somewhat off topic, but this seems like something parametrized extractors would have fixed, since you could use an identity extractor (pass in an expression as the parameter, get the value of the expression as a name) to bind the casted value to a name that could be used later in the pattern/guard/body. I remember seeing those on the 2.11 roadmap. Any idea what happened to them?
On Fri, May 16, 2014 at 11:02 PM, Haoyi Li <haoy...@gmail.com> wrote:
> You'd have to write the cast twice if you refer the the bound pattern in a guard and in a case body
Somewhat off topic, but this seems like something parametrized extractors would have fixed, since you could use an identity extractor (pass in an expression as the parameter, get the value of the expression as a name) to bind the casted value to a name that could be used later in the pattern/guard/body. I remember seeing those on the 2.11 roadmap. Any idea what happened to them?
> Thanks for reporting!
And thanks for taking time to explain, Jason!
After a second thought, your devised scheme of escalation of warnings seems good. I guess if the compiler would refuse there would be situations that would be too restrictive. A warning is fine by me.
/Bjorn