定义隐式方法时Wrong top statement declaration错误

Wrong top statement declaration error when defining an implicit method

我有最简单的代码

sealed trait WhereCondition
final case class StringWhereCondition(condition: String) extends WhereCondition

implicit def fromStrToWhereCondition (str: String): WhereCondition = StringWhereCondition(str)

不幸的是,隐式方法行给出了错误

Wrong top statement declaration

来自 IntelliJ,但我不知道它有什么问题?

def 行不能是顶级行(在 Scala 2 中)。例如将它放入某个对象中。