Scala 找到的单位:必需[某些内容]

Scala 找到的单位:必需[某些内容],scala,type-mismatch,Scala,Type Mismatch,我有下面的scala函数,我认为它不会编译,因为它发现这个单元甚至很难达到它所需要的[SomethingElse] def combine(trees: List[CodeTree]): List[CodeTree] = { if(trees.length < 2) trees else isortForTrees(trees.+:(new Fork(trees.head, trees.tail.head, chars(trees.head).:::(chars(trees.ta

我有下面的scala函数,我认为它不会编译,因为它发现这个单元甚至很难达到它所需要的[SomethingElse]

def combine(trees: List[CodeTree]): List[CodeTree] = {

  if(trees.length < 2) trees
  else isortForTrees(trees.+:(new Fork(trees.head, trees.tail.head, chars(trees.head).:::(chars(trees.tail.head)), weight(trees.head) + weight(trees.tail.head)))) 

  def isortForTrees(myList: List[CodeTree]): List[CodeTree] = {
    if(myList.isEmpty) Nil
    else insertForTrees(myList.head, isortForTrees(myList.tail))
  }

  def insertForTrees(toBeInserted: CodeTree, lisToBe: List[CodeTree]): List[CodeTree] = {
    if(lisToBe.isEmpty || weight(toBeInserted) < weight(lisToBe.head)) toBeInserted :: lisToBe
    else lisToBe.head :: insertForTrees(toBeInserted, lisToBe.tail)
  }

}
def合并(树:列表[CodeTree]):列表[CodeTree]={
如果(trees.length<2)树
else isortForTrees(trees.+:(新叉(trees.head,trees.tail.head,chars(trees.head)):(chars(trees.tail.head)),weight(trees.head)+weight(trees.tail.head)))
def isortForTrees(myList:List[CodeTree]):List[CodeTree]={
如果(myList.isEmpty)为零
else插入树(myList.head,isortForTrees(myList.tail))
}
def insertForTrees(toBeInserted:CodeTree,lisToBe:List[CodeTree]):List[CodeTree]={
如果(lisToBe.isEmpty | | weight(toBeInserted)

我不明白为什么一个单位会被退回?if语句的两端都返回一个列表[CodeTree]。我可能犯了一个愚蠢的错误,但我就是找不到。这里缺少什么?

方法中的最后一个表达式是返回
单元的方法定义。快走

if(trees.length < 2) trees
else isortForTrees(trees.+:(new Fork(trees.head, trees.tail.head, chars(trees.head).:::(chars(trees.tail.head)), weight(trees.head) + weight(trees.tail.head))))
if(trees.length<2)树
else isortForTrees(trees.+:(新叉(trees.head,trees.tail.head,chars(trees.head)):(chars(trees.tail.head)),weight(trees.head)+weight(trees.tail.head)))
到方法的底部,它应该工作