The compiler sometimes needs a little bit of help to prove that what you are doing is legal when using path dependent types. I.e., as you said, the compiler is missing flow analysis, so we must tell it explicitly that we aren't just using any World
, we are using exactly SomeWorld
so that we can use SomeWorld.initialState
.
In your case, if you change Algorithm
like so:
class Algorithm[W <: World](world: W) {
def process(s: world.State) {
val s1 = world.evolve(s)
// ... do something with s and s1
}
}
Then the following compiles:
object SomeWorld extends World {...}
new Algorithm[SomeWorld.type](SomeWorld).process(SomeWorld.initialState)