mojo icon indicating copy to clipboard operation
mojo copied to clipboard

Bug in the example code in the manual: The __copyinit__ and __moveinit__ special methods

Open abhinav-upadhyay opened this issue 1 year ago • 2 comments

Bug Description

The example code is:

struct MyString:
    var data: Pointer[Int8]

    # StringRef has a data + length field
    def __init__(self&, input: StringRef):
        let data = Pointer[Int8].alloc(input.length+1)
        data.memcpy(first.data, input.length)
        data[input.length] = 0
        self.data = Pointer[Int8](data)

    def __del__(owned self):
        self.data.free()

The following line is wrong:

        data.memcpy(first.data, input.length)

should have been

        data.memcpy(input.data, input.length)

Steps to Reproduce

Context

abhinav-upadhyay avatar May 05 '23 10:05 abhinav-upadhyay

Thanks for filing! @ZolotukhinM can you fix this plz?

lattner avatar May 05 '23 17:05 lattner

This should be fixed in the next update, thanks for the report!

ZolotukhinM avatar May 05 '23 23:05 ZolotukhinM

This this be closed @ZolotukhinM ?

lattner avatar May 07 '23 01:05 lattner

I moved it to "Ready" and was going to close it when we release the next update, but I can close now!

ZolotukhinM avatar May 07 '23 01:05 ZolotukhinM