Scala:IntelliJ [无法解析符号] Class 问题中的方法

Scala: Method within Class issues within IntelliJ [Cannot Resolve Symbol]

我的代码工作正常并且正在执行,我的问题是 IntelliJ 在 class.

的方法上给我一个 'cannot resolve symbol' 错误

代码如下:

// Q1. Create a Sailboat class with methods to raise and lower the sails,
// printing Sails raised, and Sails lowered, respectively.
// Create a Motorboat class with methods to start and stop the motor,
// returning Motor on, and Motor off, respectively. Create an object (instance)
// of the Sailboat class. Use assert for verification:

class Sailboat {
  def raise  = "Sails raised"
  def lower = "Sails lowered"
}

val sailboat = new Sailboat
val r1 = sailboat.raise
assert(r1.equals("Sails raised"), "Expected Sails raised, Got " + r1)
val r2 = sailboat.lower
assert(r2.equals("Sails lowered"), "Expected Sails lowered, Got " + r2)

请参阅随附的 inteliJ 错误屏幕截图,这发生在方法和 equals 方法上。 InteliJ Error

我有一个非常相似的脚本,基本上是相同的东西,但它没有给出任何错误:

class Motorboat {
  def on  = "Motor on"
  def off = "Motor off"
}

val motorboat = new Motorboat
val s1 = motorboat.on
assert(s1 == "Motor on", "Expected Motor on, Got " + s1)
val s2 = motorboat.off
assert(s2 == "Motor off", "Expected Motor off, Got " + s2)

见附件类似代码的截图,没有错误: Similar code with no error in IntelliJ

我试过的;

  1. 重写 class 和方法
  2. 正在重新启动 IDE
  3. 正在重启我的笔记本电脑
  4. 正在更新 IntelliJ
  5. google 搜索发生这种情况的原因

任何关于如何解决这个问题的想法将不胜感激

谢谢!

非常奇怪的行为,但我通过在同一个文件中添加第三个 class 设法解决了这个问题;

class Flare {
  def light = "Flare used!"
}

val flare = new Flare
val f1 = flare.light
assert(f1 == "Flare used!", "Expected Flare used!, Got " + f1)

这已经消除了帆船的错误 class 并且 IntelliJ 上的代码很清晰

很奇怪....