Some months ago I did some plain tests with newruntime but gave up soon because of very basic bugs as
https://github.com/nim-lang/Nim/issues/11356
Now that many bugs are already fixed I tried a similar example again like this:
type
O = object
i: int
R = ref O
proc main =
var s: seq[owned R]
s.add(R(i: 0))
s.add(R(i: 1))
#s[1] = nil
s.delete(1)
s[0] = R(i: 7)
echo s[0].i
main()
/home/stefan/Nim/lib/system.nim(2144, 46) Error: '=' is not available for type <owned R>; requires a copy because it's not the last read of 'x[j144802 + 1]'; routine: delete
Do we have an idea what the problem with delete is? Setting the ref to nil seems to compile.
(I can not remember why I tried code like that at all some months ago, I guess it was related somehow to using gintro with newruntime. Maybe that is indeed stupid code which will never occur in real Nim programming...)
Setting the ref to nil seems to compile.
It doesn't work either way under version 0.20.2; I think it only works on HEAD version, perhaps because there was a patch as a response to the issue you raised before - so I can't try it...
If it works when the value being changed is set to nil first, then the reason is that the copy semantics have perhaps been changed to allow a owned copy when there is no l-value being copied over with the setting to nil causing a destruction of the old value so that it becomes the accepted case. I think it's working as it should.
The reported error is then correct as the delete is (at least perceptually) trying to copy a nil into the value at index one, which is explicitly disallowed.