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

toml: cannot decode array of tables #22633

Open
gechandesu opened this issue Oct 23, 2024 · 0 comments
Open

toml: cannot decode array of tables #22633

gechandesu opened this issue Oct 23, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs. Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@gechandesu
Copy link
Contributor

gechandesu commented Oct 23, 2024

Describe the bug

toml.decode() does not marshal arrays of tables into arrays of structs.

Reproduction Steps

module main

import toml

struct Item {
	name string
}

struct Doc {
	items []Item
}

fn main() {
	doc := Doc{
		items: [
			Item{
				name: 'item #1'
			},
			Item{
				name: 'item #2'
			},
			Item{
				name: 'item #3'
			},
		]
	}
	encoded := toml.encode[Doc](doc)
	decoded := toml.decode[Doc](encoded)!

	assert decoded == doc
}

Expected Behavior

decoded equals to original doc.

Current Behavior

decoded.items is empty:

~ $ v run toml_issue.v
toml_issue.v:30: FAIL: fn main.main: assert decoded == doc
   left value: decoded = Doc{
    items: []
}
  right value: doc = Doc{
    items: [Item{
        name: 'item #1'
    }, Item{
        name: 'item #2'
    }, Item{
        name: 'item #3'
    }]
}
V panic: Assertion failed...
v hash: 97c6cd0
/tmp/v_1000/toml_issue.01JAX498M3PSMX160CZW3VP9QK.tmp.c:10322: at _v_panic: Backtrace
/tmp/v_1000/toml_issue.01JAX498M3PSMX160CZW3VP9QK.tmp.c:30329: by main__main
/tmp/v_1000/toml_issue.01JAX498M3PSMX160CZW3VP9QK.tmp.c:30648: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 97c6cd0

Environment details (OS name and version, etc.)

V full version: V 0.4.8 5ec9bb5.97c6cd0
OS: linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor: 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P

getwd: /home/ge
vexe: /home/ge/.vlang/v
vexe mtime: 2024-10-23 16:44:23

vroot: OK, value: /home/ge/.vlang
VMODULES: OK, value: /home/ge/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1
Git vroot status: weekly.2024.42-69-g97c6cd09
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

Huly®: V_0.6-21082

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.

@gechandesu gechandesu added the Bug This tag is applied to issues which reports bugs. label Oct 23, 2024
@felipensp felipensp added the Unit: vlib Bugs/feature requests, that are related to the vlib. label Oct 23, 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: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

2 participants