What is a baseless method in Nim?
Asked Answered
R

2

7

I'm new to the language. When trying to compile a new object type with a method (where the first argument is an instance of my new type), the compiler warned me like this:

Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]
Rilke answered 13/3, 2017 at 1:12 Comment(1)
More confusingly the multimethods example from the tutorial still produces this warning even with --multimethods:on.Oracular
M
2

Base methods correspond to what would be the base class for a method in a single-dispatch language. The base method is the most general application of a method to one or more classes. If you are dispatching on just a single argument, the base method should be associated with the type that would normally be the base class containing the method.

Madrid answered 13/3, 2017 at 10:9 Comment(0)
T
0

This warning typically happens to me when I define a method on a derived type -- thinking that I'm overriding behavior from a base type -- but the method signature is wrong and I'm effectively not overriding any method, hence the warning.

e.g.,

type
  Base = ref object of RootObj
  Derived  = ref object of Base

method doSomething(b: Base, n: int) {.base.} =
  ...

# !!! This method gets warning because it's not overriding the base
# !!! doSomething method due to different parameter types
method doSomething(d: Derived, n: string) =
  ...
Thordis answered 4/7, 2017 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.