nimlsp icon indicating copy to clipboard operation
nimlsp copied to clipboard

conflicts about .base. usage

Open heheda123123 opened this issue 9 months ago • 1 comments

I use nim 2.2.4 The below code can compile and run, but nimlsp give me a lint error

Image
type
  Animal = ref object of RootObj
    name: string
    age: int

  Dog = ref object of Animal
    breed: string

method makeSound(self: Animal) {.base.} =
  echo self.name, " makes a generic sound."

method makeSound(self: Dog) =
  echo self.name, " the ", self.breed, " barks: Woof!"

proc newAnimal(name: string, age: int): Animal =
  result = Animal(name: name, age: age)

proc newDog(name: string, age: int, breed: string): Dog =
  result = Dog(name: name, age: age, breed: breed)

# 使用示例
let genericAnimal: Animal = newAnimal("Unknown", 5)
let myDog: Animal = newDog("Buddy", 3, "Labrador") # 多态:Dog赋值给Animal引用

makeSound(genericAnimal) # 输出: Unknown makes a generic sound.
makeSound(myDog) # 输出: Buddy the Labrador barks: Woof!

If I delete {.base.}, still can compile and run, but will have a warning

Image

heheda123123 avatar Jul 13 '25 13:07 heheda123123

I believe this is a nimsuggest bug. NimLSP is mostly just an LSP interface for nimsuggest. You should probably raise the issue in the nimsuggest repo

PMunch avatar Jul 13 '25 17:07 PMunch