Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

carray_to_varray inside unsafe block warns about requiring an unsafe block #21893

Closed
TheOnlySilverClaw opened this issue Jul 18, 2024 · 0 comments · Fixed by #21898
Closed

carray_to_varray inside unsafe block warns about requiring an unsafe block #21893

TheOnlySilverClaw opened this issue Jul 18, 2024 · 0 comments · Fixed by #21898
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@TheOnlySilverClaw
Copy link

TheOnlySilverClaw commented Jul 18, 2024

Describe the bug

A warning is emitted when carray_to_varray is used to convert an array of references.

Reproduction Steps

module main

import arrays

struct Blah {}

fn main() {
	pointers := [&int(1234)]
	length := 1
	array := unsafe { arrays.carray_to_varray[&Blah](pointers, length) }
	println(array)
}

Expected Behavior

No warning when inside unsafe block.

Current Behavior

/opt/v/vlib/arrays/arrays.v:705:17: warning: arrays of references need to be initialized right away, therefore len: cannot be used (unless inside unsafe, or if you also use init:)
703 | @[unsafe]
704 | pub fn carray_to_varray[T](c_array_data voidptr, items int) []T {
705 | mut v_array := []T{len: items}
| ~~~~
706 | total_size := items * isize(sizeof(T))
707 | unsafe { vmemcpy(v_array.data, c_array_data, total_size) }
[&Blah{}]

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.6 510500d

Environment details (OS name and version, etc.)

not relevant

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@TheOnlySilverClaw TheOnlySilverClaw added the Bug This tag is applied to issues which reports bugs. label Jul 18, 2024
@felipensp felipensp added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Jul 20, 2024
@felipensp felipensp self-assigned this Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
2 participants