Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Nim

Visibility

unlisted

Author

legacy-anonymous

Created

2017-01-23T09:20:02Z

Updated

2017-01-23T09:20:02Z

import typeinfo

type CustomAny* = object
    value: pointer
    rawType: pointer

proc customToAny*[T](x: var T): CustomAny {.inline.} =
  result = cast[CustomAny](toAny(x))

proc compareRuntimeTypes[A, B](a: var A, b: var B): bool =
  result = customToAny(a).rawType == customToAny(b).rawType

type
  Parent = ref object {.inheritable.}
  Derived = ref object of Parent

var a: Parent = Parent()
var b: Parent = Derived()
echo "a == b? " & $(compareRuntimeTypes(a, b)) # ==> true, expected false
INFO