This is a follow up question of Part1:
In Part 2, the definition of the family class become slightly more complex:
trait OuterSpike {
class Thing
case class Inner(v: Thing) {
// val outer = self
}
}
object OuterSpike {
{
def cp(src: OuterSpike#Inner): OuterSpike#Inner = {
src.copy()
}
def cp2[O <: OuterSpike](src: O#Inner): O#Inner = src.copy()
val outer = new OuterSpike {
val inner = this.Inner(new Thing)
}
cp(outer.inner)
}
}
So the old trick no longer works, the above compiles with the following error:
[Error] /home/peng/git/shapesafe/graph-commons/src/main/scala/com/tribbloids/graph/commons/util/reflect/format/OuterSpike.scala:18: type mismatch;
found : com.tribbloids.graph.commons.util.reflect.format.OuterSpike#Thing
required: _1.Thing where val _1: com.tribbloids.graph.commons.util.reflect.format.OuterSpike
[Error] /home/peng/git/shapesafe/graph-commons/src/main/scala/com/tribbloids/graph/commons/util/reflect/format/OuterSpike.scala:21: type mismatch;
found : O#Thing
required: _1.Thing where val _1: O
two errors found
How to make it compile in this case?
Seems you are refining
OuterSpike
withval inner
which is dependent onouter
instanceso try with dependent types instead of type projection