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

Cannot define array of struct when struct definition is another module #19033

Closed
pd-giz-dave opened this issue Aug 1, 2023 · 1 comment · Fixed by #19039
Closed

Cannot define array of struct when struct definition is another module #19033

pd-giz-dave opened this issue Aug 1, 2023 · 1 comment · Fixed by #19039
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@pd-giz-dave
Copy link

pd-giz-dave commented Aug 1, 2023

Describe the bug

I have a struct definition in module consts and in module draw I want to declare an array of Point's like this: mut points := &[]consts.Point{} but it generates a compile error of "unexpected token {, expecting (". Example below:

bug_consts.v:

module bug_consts
pub struct Point {
pub:
	x f32
	y f32
}

bug_draw.v:

module bug_draw
import bug_consts
import consts
type AliasPoint = bug_consts.Point // ToDo: HACK to overcome compiler issue
pub fn bug_compile() []bug_consts.Point {
	mut bad_points := &[]bug_consts.Point{}  // generates compiler error unexpected token `{`, expecting `(`
	mut good_points := &[]AliasPoint{} // compiles OK
	return *bad_points  // I cannot return the type I want, returning good_points is the wrong type, casting using 'as' didn't work
}

Expected Behavior

No compile errors

Current Behavior

Compiler says:

bug_draw/bug_draw.v:9:39: error: unexpected token {, expecting (
7 |
8 | pub fn bug_compile() []bug_consts.Point {
9 | mut bad_points := &[]bug_consts.Point{} // generates compiler error unexpected token {, expecting (
| ^

Reproduction Steps

Compile the two files given in the description

Possible Solution

No response

Additional Information/Context

No response

V version

Current V version: V 0.4.0 ecca3b1, timestamp: 2023-08-01 20:45:50 +0300

Environment details (OS name and version, etc.)

dave@dcn-mini-pc/precious/.../v/canvas >>> v doctor
V full version: V 0.4.0 ecca3b1
OS: linux, "Manjaro Linux"
Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

getwd: /precious/fellsafe/v/canvas
vexe: /home/dave/v/v
vexe mtime: 2023-08-01 19:03:56

vroot: OK, value: /home/dave/v
VMODULES: OK, value: /home/dave/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.40.1
Git vroot status: weekly.2023.23-357-gecca3b15
.git/config present: true

CC version: cc (GCC) 13.1.1 20230429
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

@pd-giz-dave pd-giz-dave added the Bug This tag is applied to issues which reports bugs. label Aug 1, 2023
@shove70 shove70 self-assigned this Aug 2, 2023
shove70 added a commit to shove70/v that referenced this issue Aug 2, 2023
shove70 added a commit to shove70/v that referenced this issue Aug 2, 2023
spytheman pushed a commit that referenced this issue Aug 3, 2023
@pd-giz-dave
Copy link
Author

pd-giz-dave commented Aug 3, 2023 via email

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
2 participants