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

Runtime error when pushed in array some structure fileds, error clone() not displayed #9374

Closed
Lathanao opened this issue Mar 19, 2021 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@Lathanao
Copy link
Contributor

Lathanao commented Mar 19, 2021

V full version: V 0.2.2 2e84773
OS: linux, "Manjaro Linux"

What did you do?

module main

struct Product {
mut:
	schema1 []string = ['id']
	schema2 []string = ['sku']
}

pub fn (p Product) do_somthing() Product {
	mut schema := p.schema1
	schema << p.schema2
	return p
}

fn  main() {
	mut p := Product{}
	println(p.do_somthing())
}

What did you expect to see?
The Product structure

What did you see instead?

7ffff7de2ad3 : at ???: RUNTIME ERROR: invalid memory access
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:1694: by strings__Builder_write_string
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:4927: by Array_string_str
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:1526: by indent_main__Product_str
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:1517: by main__Product_str
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:8736: by main__main
/tmp/v/struct_generic_iterator_without_generic_bug_array.13372961394880386484.tmp.c:8821: by main

Addendum
With:

mut schema := p.schema1.clone()

The code works well.

The clone() is missing, and the error should be the same than:

module main

fn  main() {

	schema1 := ['id']
	schema2 := ['sku']

	mut schema := schema1
	schema << schema2
}

get error like:

test/bug.v:8:13: error: use `array2 := array1.clone()` instead of `array2 := array1` (or use `unsafe`)
    6 |     schema2 := ['sku']
    7 | 
    8 |     mut schema := schema1
      |                ~~
    9 |     schema << schema2
   10 | }
@Lathanao Lathanao added the Bug This tag is applied to issues which reports bugs. label Mar 19, 2021
@crthpl
Copy link
Member

crthpl commented May 16, 2021

Closing as duplicate of #10011, since it has more discussion.

@crthpl crthpl closed this as completed May 16, 2021
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.
Projects
None yet
Development

No branches or pull requests

2 participants