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

cgen failure for an empty $for f in Struct.fields {, when Struct contains fields with a fixed array type #19881

Closed
spytheman opened this issue Nov 15, 2023 · 1 comment · Fixed by #19886
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@spytheman
Copy link
Member

spytheman commented Nov 15, 2023

V doctor:

V full version: V 0.4.3 00f2e4a.b8d1298
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/vnew
vexe: /space/v/vnew/v
vexe mtime: 2023-11-15 08:22:31

vroot: OK, value: /space/v/vnew
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.42.0
Git vroot status: weekly.2023.45.1-36-gb8d12985-dirty
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do?
v -g -o vdbg cmd/v && vdbg y.v

struct Another {
	a [3]int
	b [4]u8
	c []int
}

fn test_comptime_types_for_fields_of_another() {
	$for f in Another.fields {
	}
}

What did you expect to see?

a compiled program

What did you see instead?

y.v:8:7: warning: unused variable: `f`
    6 | 
    7 | fn test_comptime_types_for_fields_of_another() {
    8 |     $for f in Another.fields {
      |          ^
    9 |     }
   10 | }
==================
/tmp/v_1000/y.5788582281899540823.tmp.c:1867: warning: type defaults to int
/tmp/v_1000/y.5788582281899540823.tmp.c:1867: error: ';' expected (got "_v_dump_expr_Array_fixed_int_3")
...
==================
(Use `v -cg` to print the entire error message)

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Nov 15, 2023
@spytheman
Copy link
Member Author

After some investigation, this compiles:

struct Another {
    a [3]int
    b [4]u8
    c [2]u32
}

// if I comment any of these functions, there is a cgen error too:
fn fa() [3]int { return [1,2,3]! }
fn fb() [4]u8 { return [u8(1),2,3,4]! }
fn fc() [2]u32 { return [u32(1),2]! }

fn test_comptime_types_for_fields_of_another() {
    $for f in Another.fields {
    }
}

Removing one of the functions with a fixed array return type, also triggers a cgen error.
It seems that Gen.write_array_fixed_return_types is not called, when it should, or that the dump auto generator is called when it should not.

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: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant