Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimsuggest - Methods marked with {.base.} trigger error on chk #23581

Open
richardhallett opened this issue May 7, 2024 · 3 comments
Open

Nimsuggest - Methods marked with {.base.} trigger error on chk #23581

richardhallett opened this issue May 7, 2024 · 3 comments

Comments

@richardhallett
Copy link

Description

When working with dynamic dispatch base methods, IDE integrations which use nimsuggest and/or nimsuggest via the CLI trigger an error on the following code:

type
  Expression = ref object of RootObj ## abstract base class for an expression
  Literal = ref object of Expression
    x: int
  PlusExpr = ref object of Expression
    a, b: Expression

# watch out: 'eval' relies on dynamic binding
method eval(e: Expression): int {.base.} =
  # override this base method
  quit "to override!"

method eval(e: Literal): int = e.x
method eval(e: PlusExpr): int = eval(e.a) + eval(e.b)

proc newLit(x: int): Literal = Literal(x: x)
proc newPlus(a, b: Expression): PlusExpr = PlusExpr(a: a, b: b)

echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4)))

This code is directly lifted from tutorial https://nim-lang.org/docs/tut2.html#object-oriented-programming-dynamic-dispatch

The error in question is
method is not a base

When running nimsuggest chk on this code it reports (path was changed for privacy reasons)

> chk "example.nim"
chk	skUnknown		Hint	???	0	-1	">> (toplevel): import(dirty): /home/user/example/example.nim [Processing]"	0
chk	skUnknown		Error	/home/user/example/example.nim 9	7	"method is not a base"	0

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d
active boot switches: -d:release -d:danger --gc:markAndSweep

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

This manifested for me initially with the VSCode extension https://github.com/nim-lang/vscode-nim but own investigation appeared to be in nimsuggest

@jmgomez
Copy link
Collaborator

jmgomez commented May 10, 2024

Cant be reproed in the v4 of the protocol. Tools should use that one instead as it has many other enhancements

nimsuggest --v4 example.nim

@Seanld
Copy link

Seanld commented May 13, 2024

I had the same problem as OP, but I guess the problem is that I was using nimlsp, the author of which hasn't kept it up to date with the latest nimsuggest protocol updates (as far as I can tell, even V3 hasn't been implemented). So the answer was to switch to nimlangserver. After switching, the {.base.} error is gone.

@richardhallett
Copy link
Author

So I can confirm if I run with explicit --v4 as above then yes it appears to work as expected.
So perhaps the error is instead within the handling by nimlangserver? However based upon what @Seanld said this worked for them.

For me running either vscode integration or neovim with nimlangserver still shows errors.

I've tried to see if I can find the protocol being chosen but my best guess is:
https://github.com/nim-lang/langserver/blob/97ffd6da89c658abaf6043e29ac6aeab1afda8f9/suggestapi.nim#L268

Running:
nimsuggest --info:protocolVer
Returns:
4

As an aside Why is the default protocol still v2? If v4 is generally better, shouldn't that be the default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants