#How come unsafe "clone" isn't working on a fixed array?

1 messages · Page 1 of 1 (latest)

mossy bane
#

I have the following code:

fn main(){
    x := [10]int{}
    y := unsafe {x}
    println(y)
}

Results in: /tmp/v_1000/main.2328365305198486257.tmp.c:12262: error: '{' expected (got ";")

Although the following works without an error

fn main(){
    x := []int{}
    y := unsafe {x}
    println(y)
}
#

How come unsafe "clone" isn't working on a fixed array?

delicate escarp
#

remove the unsafe {}, it is not implemented for fixed arrays

#

and file an issue

#

it should have been either a checker error, or a nop op; not a cgen error

mossy bane
#

thanks, i'll open an issue 🙂

delicate escarp
#

thanks

mint fox
#

will the checker error be temporary as they are not implemented in the code generation stage?

delicate escarp
#

if there is a checker error, the compilation will stop, and so cgen will not error

mint fox
#

but it should be implemented right?

delicate escarp
#

I think you have answered your own question

mint fox
#

I got confused actually

delicate escarp
#

there are several alternatives - a checker error, or a cgen implementation; if one is implemented, the other is not needed; one can reasonably choose either of them

#

note, that fixed arrays unlike dynamic ones, can not share memory blocks, so the unsafe {} copy op, that is needed sometimes for the dynamic ones, is not useful for fixed arrays - they can just use a2 := a1 without unsafe{}, which already works, and thus a2 := unsafe { a1 } can be a NOP - it does not need to do anything more/different than what a2 := a1 already does

#

I hope that clears your confusion.

mint fox
#

it does clear my confusion