1

此代码仅适用于 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 回归?

(目前,我正在使用带有“不稳定”版本的 Scala 插件的 Eclipse 4.2。但是,使用 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>
        }
      }
    }
 }
4

1 回答 1

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

如果不指定 Scala 中的参数类型,就无法定义方法。这不可能由任何 Scala 版本编译。这...也表明您在这里遗漏了一些东西。尝试提供一个完全独立的示例(例如 add 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" )
    }
 }
于 2012-08-16T17:35:50.947 回答