SBT中的Scala参数类型推断错误(0.7.x与0.11.x)

时间:2012-08-16 13:17:16

标签: scala sbt

此代码仅使用SBT 0.7.x系列(在本例中为0.7.7)进行编译,但对于SBT 0.11.x系列(在本例中为0.11.3)则不编译。在这两种情况下,使用相同的Scala 2.9.x系列(2.9.1)

似乎SBT 0.11.3无法推断出参数的类型。 Eclipse也不行。 我的猜测是编码存在问题。或者是SBT回归?

(目前,我正在使用Eclipse 4.2和Scala插件的“不稳定”版本。但是,我在Eclipse 3.7和插件的“稳定”版本中遇到了同样的错误。)

// either using the "override" reserved keyword or not, this code will compile with SBT 0.7.7 but not with 11.3


 sealed trait FacetJoin[T1, T1S, T2S] {
    def facetJoin (a: T1S, b: T1S
      , fVals: (T1, T1) => T2S
      , fFacets: (Formula, T1S, T1S, Formula, T1S, T1S) => T2S
      , fBothL: (T1S, Formula, T1S, T1S) => T2S
      , fBothR: (Formula, T1S, T1S, T1S) => T2S
      , fOther: (T1S, T1S) => T2S): T2S
  }
  object FacetJoin {
    implicit object BoolBoolFacetJoin
    extends FacetJoin[Boolean, Formula, Formula] {

// Eclipse complaint for next line: 
//// Multiple markers at this line
////    - only classes can have declared but undefined 
////     members
////    - ':' expected but ',' found.

      override def facetJoin (a, b, fVals, fFacets, fBothL, fBothR, fOther): Formula = {
 ...

// Eclipse complaint for next line: 
//// Multiple markers at this line
////    - identifier expected but '}' 
////     found.
////    - not found: type <error>
        }
      }
    }
 }

1 个答案:

答案 0 :(得分:2)

def facetJoin (a, b, fVals, fFacets, fBothL, fBothR, fOther): Formula 

如果未在Scala中指定参数类型,则无法定义方法。这不能由任何Scala版本编译。 ...也表示你在这里遗漏了东西。尝试提供完全自包含的示例(例如,添加trait Formula)。随着输入的类型,它编译没有问题:

trait Formula

sealed trait FacetJoin[T1, T1S, T2S] {
  def facetJoin (a: T1S, b: T1S
    , fVals: (T1, T1) => T2S
    , fFacets: (Formula, T1S, T1S, Formula, T1S, T1S) => T2S
    , fBothL: (T1S, Formula, T1S, T1S) => T2S
    , fBothR: (Formula, T1S, T1S, T1S) => T2S
    , fOther: (T1S, T1S) => T2S): T2S
}
object FacetJoin {
  implicit object BoolBoolFacetJoin
  extends FacetJoin[Boolean, Formula, Formula] {

  override def facetJoin (a: Formula, b: Formula
    , fVals: (Boolean, Boolean) => Formula
    , fFacets: (Formula, Formula, Formula, Formula, Formula, Formula) => Formula
    , fBothL: (Formula, Formula, Formula, Formula) => Formula
    , fBothR: (Formula, Formula, Formula, Formula) => Formula
    , fOther: (Formula, Formula) => Formula): Formula = sys.error( "TODO" )
    }
 }