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

json encode double fixed array #22369

Closed
jorgeluismireles opened this issue Sep 30, 2024 · 3 comments · Fixed by #22448
Closed

json encode double fixed array #22369

jorgeluismireles opened this issue Sep 30, 2024 · 3 comments · Fixed by #22448
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Sep 30, 2024

Describe the bug

Code: https://play.vlang.io/p/cae76f07e6

import json

struct Base {
	options  Options
	profiles Profiles
}

struct Options {
	cfg [6]u8
}

struct Profiles {
	cfg [4][7]u8 // <- cause of C error
}

fn main() {
	println(Base{}) // OK
	println(json.encode(Base{})) // C error
}

Reproduction Steps

Run the code at the playground

Expected Behavior

Create json string from the object. Regular print is

Base{
    options: Options{
        cfg: [0, 0, 0, 0, 0, 0]
    }
    profiles: Profiles{
        cfg: [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
    }
}

Current Behavior

Output:

/tmp/v_60000/code.01J923657XT1ASJX52P6NTVDTT.tmp.c:2610: error: '{' expected (got ";")
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
Exited with error status 1

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 aa3ab3f

Environment details (OS name and version, etc.)

V full version: V 0.4.8 aa3ab3f
OS: linux, Debian GNU/Linux 12 (bookworm) (VM)
Processor: 2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz

getwd: /home/admin/playground
vexe: /home/admin/v/v
vexe mtime: 2024-09-30 18:25:27

vroot: OK, value: /home/admin/v
VMODULES: OK, value: .vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.39.5
Git vroot status: Error: fatal: detected dubious ownership in repository at '/home/admin/v'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v
.git/config present: true

CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc
 Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc

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.

@jorgeluismireles jorgeluismireles added the Bug This tag is applied to issues which reports bugs. label Sep 30, 2024
@jorgeluismireles
Copy link
Author

I didn't remember was reported already: #22363

@jorgeluismireles
Copy link
Author

Trying with x.json2 and setting everything pub mut gives another error:

import x.json2

pub struct Base {
pub mut:
	options  Options
	profiles Profiles
}

pub struct Options {
pub mut:
	cfg [6]u8
}

pub struct Profiles {
pub mut:
	cfg [4][7]u8
}

fn main() {
	println(json2.encode(Base{}))
}
/home/jorge/v/vlib/x/json2/encoder.v:313:8: error: could not infer generic type `U` in call to `encode_array`
  311 |                 } $else $if field.is_array {
  312 |                     // TODO: replace for `field.typ is $array`
  313 |                     e.encode_array(value, level + 1, mut buf)!
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  314 |                 } $else $if field.typ is $array {
  315 |                     // e.encode_array(value, level + 1, mut buf)! // FIXME: error: could not infer generic type `U` in call to `encode_array`

@esquerbatua esquerbatua changed the title json encode double array json encode double fixed array Sep 30, 2024
@esquerbatua esquerbatua added Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Sep 30, 2024
@esquerbatua
Copy link
Contributor

I didn't remember was reported already: #22363

seems that it's not related

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. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants