I get no compiler error for your example (maybe there is some problem in your
full code), just a run-time error from dispatcher, because you didn't allocate
the object for `a` (via `new`, as the variable is of reference (pointer) type,
not object itself). The full code:
type
Something = object
a: int
special: Special
Special = ref object {.inheritable.}
SpecialisedTA = ref object of Special
abc: string
SpecialisedTB = ref object of Special
def: string
import json
method foo(s: Special, node: JsonNode) {.base.} = assert(false, "Kinda
abstract")
method foo(s: SpecialisedTA, node: JsonNode) =
s.abc = node["abc"].getStr()
method foo(s: SpecialisedTB, node: JsonNode) =
s.def = node["def"].getStr()
var a = new SpecialisedTA
var jsonNode = parseJSON"""{"abc": "5", "def": "7"}"""
echo jsonNode
foo(a, jsonNode)
echo a.repr
Run
Wrapping your code in posts with "```nim" and "```" makes it highlighted.