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]
Antrikshy
  • 2,918
  • 4
  • 31
  • 65
  • More confusingly the [multimethods example from the tutorial](https://nim-lang.org/docs/tut2.html#object-oriented-programming-dynamic-dispatch) still produces this warning even with `--multimethods:on`. – Fizz Jun 27 '20 at 01:53

2 Answers2

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.

Reimer Behrends
  • 8,600
  • 15
  • 19
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) =
  ...
Alex Boisvert
  • 2,850
  • 2
  • 19
  • 18