You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This always tries to derive the "raw" type for Bar:
[nuttycom@yggdrasil dependent_case_class]$ ~/bin/scala-2.10.0-M2/bin/scalac -Xexperimental Test.scala
Test.scala:8: error: type mismatch;
found : Bar
required: Bar{type FA = Long}
val barLong: Bar { type FA = Long } = new Bar(new Foo { type FA = Long })
Variants don't appear to work either:
[nuttycom@yggdrasil dependent_case_class]$ cat Test.scala
trait Foo { type FA }
class Bar(val foo: Foo) {
type FA = foo.FA
}
object Test {
def main(argv: Array[String]) {
val barLong: Bar { type FA = Long } = new Bar(new Foo { type FA = Long }) {
override type FA = Long
}
}
}
// vim: set ts=4 sw=4 et:
[nuttycom@yggdrasil dependent_case_class]$ ~/bin/scala-2.10.0-M2/bin/scalac -Xexperimental Test.scala
Test.scala:9: error: overriding type FA in class Bar, which equals this.foo.FA;
type FA has incompatible type
override type FA = Long
^
one error found
The text was updated successfully, but these errors were encountered:
@paulp said:
I don't think this is a bug. Class Bar exposes "val foo: Foo". The extra type information does not cross that boundary. If it were "val foo: Any", you wouldn't be surprised when you passed in a String and still couldn't use it as a String. This is the same.
Both of these work:
// option 1, provide an avenue for more type informationclassBar[F<:Foo](valfoo:F)
// option 2, subclass and refine the typedefnewBar[T<:Foo](x: T) = {
classBar1(overridevalfoo:T= x) extendsBar(foo)
newBar1(x)
}
It appears that dependent types do not correctly propagate through constructors:
This always tries to derive the "raw" type for Bar:
Variants don't appear to work either:
The text was updated successfully, but these errors were encountered: