I'm writing a custom tree/graph container for smaller serialisation, and i'm getting a compiler error, apparently adding something to a short produces an Int.
def traverse(tree : Tree, level : Short = 0, pos : Short = 0) {
buf(level) += tree
var pos : Short = -1
tree.getChildrenAsList.iterator().foreach { z=>
pos += 1
traverse(z, level + 1 ,pos)
}
}
[error] /Users/hassan/code/scala/avro/src/main/scala/edu/hsyed/nlp/MyTree.scala:33: type mismatch;
[error] found : Int
[error] required: Short
[error] traverse(z, level + 1 ,pos)
I'm having to do this, which seems a bit unusual because of scala's impressive type deduction :
def traverse(tree : Tree, level : Short = 0, pos : Short = 0) {
buf(level) += tree
var pos : Short = -1
tree.getChildrenAsList.iterator().foreach { z=>
pos = (pos + 1).toShort
traverse(z, (level + 1).toShort ,pos)
}
}
edit
Aah the question is, how do I get around this ?