gpt4 book ai didi

scala - "scala is not an enclosing class"

转载 作者:行者123 更新时间:2023-12-04 14:34:35 27 4
gpt4 key购买 nike

编译本规范时:

import org.specs.Specification
import org.specs.matcher.extension.ParserMatchers

class ParserSpec extends Specification with ParserMatchers {
type Elem = Char

"Vaadin DSL parser" should {
"parse attributes in parentheses" in {
DslParser.attributes must(
succeedOn(stringReader("""(attr1="val1")""")).
withResult(Map[String, AttrVal]("attr1" -> AttrVal("val1", "String"))))
}
}
}

我收到以下错误:
ParserSpec.scala:21
error: scala is not an enclosing class
withResult(Map[String, AttrVal]("attr1" -> AttrVal("val1", "String"))))
^

我根本不明白这里的错误信息。为什么会出现?

Scala 版本是 2.8.1,规范版本是 1.6.7.2。
DslParser.attributes有类型 Parser[Map[String, AttrVal]]和组合器 succeedOnwithResult定义如下:
trait ParserMatchers extends Parsers with Matchers {
case class SucceedOn[T](str: Input,
resultMatcherOpt: Option[Matcher[T]]) extends Matcher[Parser[T]] {
def apply(parserBN: => Parser[T]) = {
val parser = parserBN
val parseResult = parser(str)
parseResult match {
case Success(result, remainingInput) =>
val succParseMsg = "Parser "+parser+" succeeded on input "+str+" with result "+result
val okMsgBuffer = new StringBuilder(succParseMsg)
val koMsgBuffer = new StringBuilder(succParseMsg)
val cond = resultMatcherOpt match {
case None =>
true
case Some(resultMatcher) =>
resultMatcher(result) match {
case (success, okMessage, koMessage) =>
okMsgBuffer.append(" and ").append(okMessage)
koMsgBuffer.append(" but ").append(koMessage)
success
}
}
(cond, okMsgBuffer.toString, koMsgBuffer.toString)
case _ =>
(false, "Parser succeeded", "Parser "+parser+": "+parseResult)
}
}

def resultMust(resultMatcher: Matcher[T]) = this.copy(resultMatcherOpt = Some(resultMatcher))

def withResult(expectedResult: T) = resultMust(beEqualTo(expectedResult))

def ignoringResult = this.copy(resultMatcherOpt = None)
}

def succeedOn[T](str: Input, expectedResultOpt: Option[Matcher[T]] = None) =
SucceedOn(str, expectedResultOpt)

implicit def stringReader(str: String): Reader[Char] = new CharSequenceReader(str)
}

最佳答案

当编译器真正尝试发出类型错误或类型推断失败的信号时,可能会出现此消息。这是 scalac 中的一个错误(或一系列错误)。

为了定位问题,逐步添加显式类型和类型参数;将复杂的表达式分解为更小的子表达式。

对于奖励积分,请生成一个独立的示例并提交错误。

关于scala - "scala is not an enclosing class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5143849/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com