Skip to content

Channel incorrectly allows non-copyable types #25323

@arnetheduck

Description

@arnetheduck

Nim Version

2.2.4

Description

Using a move-only type with Channel should not compile, since Channel, in fact, copies the item (just that it hacks the type system instead of using language features) - this leads to all kinds of guarantees being violated, for example pointer stability:

type RefBuf = object
  buf*: seq[byte]

proc `=copy`(a: var RefBuf, b: RefBuf) {.error.}

var pos: ptr byte
var xxxx: ptr Channel[RefBuf]

xxxx = create(Channel[RefBuf])

xxxx[].open()

block:
  var v = RefBuf(buf: newSeq[byte](10))
  pos = addr v.buf[0]
  xxxx[].send(move(v))

block:
  var v = xxxx[].recv()

  assert pos == addr v.buf[0]

Current Output


Expected Output


Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions