This compiles and runs fine with --newruntime:
    
    
    # nim c --newruntime -r t.nim
    import OS
    type
      Widget = ref object
        i: int
        a: array[1024, int]
    
    var g1: seq[Widget]
    
    proc newWidget(): owned Widget =
      new result
    
    proc addWidget(w:  owned Widget) =
      g1.add(w)
    
    proc main =
      var w: owned Widget
      w = newWidget()
      var x: Widget = w
      addWidget(w)
      w = nil
      echo x.i
    
    main()
    
    
    Run

So x is not a dangling ref. So addWidget() takes ownership -- but for that I 
had expected that g1 must be a seq[owned Widget]. So g1 can not really own the 
Widget, and addWidget() can not really own it also, as it is only a proc, no 
heap storage.

Reply via email to