通过 proCall 防止动态方法解析

通过调用内置的 system.procCall 可以防止动态方法解析。 某种程度上它与传统面向对象语言提供的 super 关键字类似。

  1. type
  2. Thing = ref object of RootObj
  3. Unit = ref object of Thing
  4. x: int
  5. method m(a: Thing) {.base.} =
  6. echo "base"
  7. method m(a: Unit) =
  8. # 调用基方法:
  9. procCall m(Thing(a))
  10. echo "1"