summary refs log tree commit diff stats
path: root/tests/gc/stackrefleak.nim
Commit message (Expand)AuthorAgeFilesLines
* fixes the recently discovered GC memory leaksZahary Karadjov2012-12-201-2/+0
* added 2 GC leak test casesZahary Karadjov2012-11-221-0/+33
'>30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
discard """
  output: '''Subobject test called
5'''
"""

type
  TClassOfTCustomObject {.pure, inheritable.} = object
    base* : ptr TClassOfTCustomObject
    className* : string
  TClassOfTobj = object of TClassOfTCustomObject
    nil
  TCustomObject = ref object {.inheritable.}
    class* : ptr TClassOfTCustomObject
  TObj = ref object of TCustomObject
    data: int

var ClassOfTObj: TClassOfTObj

proc initClassOfTObj() =
  ClassOfTObj.base = nil
  ClassOfTObj.className = "TObj"

initClassOfTObj()

proc initialize*(self: TObj) =
  self.class = addr ClassOfTObj
  # this generates wrong C code: && instead of &

proc newInstance(T: typedesc): T =
  mixin initialize
  new(result)
  initialize(result)

var o = TObj.newInstance()

type
    TestObj* = object of TObject
        t:int
    SubObject* = object of TestObj

method test*(t:var TestObj) =
    echo "test called"

method test*(t:var SubObject) =
    echo "Subobject test called"
    t.t= 5

var a: SubObject

a.test()
echo a.t