nimlsp
nimlsp copied to clipboard
conflicts about .base. usage
I use nim 2.2.4 The below code can compile and run, but nimlsp give me a lint error
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
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