|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
[scala] Structural refinements containing methods with higher-order type parameters are unsoundHi,
Consider the following definitions: ////////////////////////////////////////////////////////////////////////// class C[T](var y : T) object A { val a : AnyRef { def f[T[_]](x : T[int]) : T[Any] } = A def f[T[+_]](x : T[Int]) : T[Any] = x } ////////////////////////////////////////////////////////////////////////// Scala 2.8.0.r18050-b20090618020144 compiler compiles this without errors. But it seems unsound, as we can write: scala> val c = new C(1) c: C[Int] = C@9e7d46 scala> val c1 = A.a.f[C](c) c1: C[Any] = C@9e7d46 scala> c1.y = "" scala> c.y java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at scala.runtime.BoxesRunTime.unboxToInt(Unknown Source) at .<init>(<console>:7) at .<clinit>(<console>) at RequestResult$.<init>(<console>:4) at RequestResult$.<clinit>(<console>) at RequestResult$result(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.Na... Is it a bug? I also cannot find in SLS exact rules, which determine what values can be assigned to a variable of a structural type. Thanks, Vladimir |
|
|
Re: [scala] Structural refinements containing methods with higher-order type parameters are unsoundVladimir,
You are a monster! ;-) This is all great stuff! Scala is vastly improved by asking the kind of questions you're asking. And you've provided enough brain-candy to last me for a month. Best wishes, --greg On Thu, Jun 18, 2009 at 5:01 AM, Vladimir Reshetnikov <v.reshetnikov@...> wrote: Hi, -- L.G. Meredith Managing Partner Biosimilarity LLC 1219 NW 83rd St Seattle, WA 98117 +1 206.650.3740 http://biosimilarity.blogspot.com |
|
|
Re: [scala] Structural refinements containing methods with higher-order type parameters are unsoundVladimir,
You're right, thanks for being thorough! This seems to arise from the same bug as your original example, though. (#2066) I'm working on fixing it as we speak, but am using the opportunity to combine it with a refactoring that I've been postponing for a while now... ;-)
I'm looking forward to your unleashing your merciless testing on the refactoring :-) cheers adriaan On Thu, Jun 18, 2009 at 2:16 PM, Meredith Gregory <lgreg.meredith@...> wrote: Vladimir, |
| Free embeddable forum powered by Nabble | Forum Help |