Strange Scala error.
- by Lukasz Lew
I tried to create abstract turn based Game and abstract AI:
abstract class AGame {
type Player
type Move // Player inside
def actPlayer : Player
def moves (player : Player) : Iterator[Move]
def play (move : Move)
def undo ()
def isFinished : Boolean
def result (player : Player) : Double
}
abstract class Ai[Game <: AGame] {
def genMove (player : Game#Player) : Game#Move
}
class DummyGame extends AGame {
type Player = Unit
type Move = Unit
def moves (player : Player) = new Iterator[Move] {
def hasNext = false
def next = throw new Exception ("asd")
}
def actPlayer = ()
def play (move : Move) {
}
def undo () {
}
def isFinished = true
def result (player : Player) = 0
}
class DummyAi[Game <: AGame] (game : Game) extends Ai[Game] {
override def genMove (player : Game#Player) : Game#Move = {
game.moves (player).next
}
}
I thought that I have to use this strange type accessors like Game#Player.
I get very puzzling error. I would like to understand it:
[error] /home/lew/Devel/CGSearch/src/main/scala/Main.scala:41: type mismatch;
[error] found : Game#Player
[error] required: DummyAi.this.game.Player
[error] game.moves (player).next
[error] ^