Skip to content

x.json2 error: Any has no variant VariantData #24165

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

Open
Avey777 opened this issue Apr 9, 2025 · 2 comments
Open

x.json2 error: Any has no variant VariantData #24165

Avey777 opened this issue Apr 9, 2025 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation)

Comments

@Avey777
Copy link

Avey777 commented Apr 9, 2025

Describe the bug

error: Any has no variant VariantData

Reproduction Steps

module main

import x.json2

type Any = string | int | bool | []string | map[string]int

fn main() {
	mut data_list := []map[string]Any{}

	mut item := map[string]Any{}
	item['key'] = 'value'
	item['another_key'] = 42
	item['yet_another_key'] = 425
	item['key1'] = 'value1'
	item['key2'] = ['d', 'g']

	data_list << item
	dump(json2.encode(data_list))
}

Expected Behavior

[map_any.v:38] json.encode(data_list): [{"key":"value","another_key":42,"yet_another_key":425,"key1":"value1","key2":["d","g"]}]

Current Behavior

/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/x/json2/encoder.v:136:13: error: `Any` has no variant `VariantData`
  134 |         $if v is $sumtype {
  135 |             $for variant_value in v.variants {
  136 |                 if v is variant_value {
      |                         ~~~~~~~~~~~~~
  137 |                     e.encode_value_with_level(v, level + 1, mut buf)!
  138 |                 }

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 2ce2e58

Environment details (OS name and version, etc.)

V full version V 0.4.10 86536e4.2ce2e58
OS linux, Deepin 23
Processor 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory 0.31GB/7.61GB
V executable /home/Jengro/.vmr/versions/v_versions/v_latest/v
V last modified time 2025-04-08 10:48:26
V home dir OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest
VMODULES OK, value: /home/Jengro/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/Jengro/Documents/Dev/v-product/vprod-workspase/example
Git version git version 2.45.2
V git status weekly.2025.14-26-g2ce2e586
.git/config present true
cc version cc (Deepin 12.3.0-17deepin8) 12.3.0
gcc version gcc (Deepin 12.3.0-17deepin8) 12.3.0
clang version Deepin clang version 17.0.6 (5deepin5)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Debian GLIBC 2.38-6deepin7) 2.38

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.

@Avey777 Avey777 added the Bug This tag is applied to issues which reports bugs. label Apr 9, 2025
Copy link

Connected to Huly®: V_0.6-22554

@jorgeluismireles
Copy link

Even this simpler case cannot proceed (tested in playground):

import x.json2

fn main() {
	mut data_list := []map[string]json2.Any{}
	mut item := map[string]json2.Any{}
	data_list << item
	dump(json2.encode(data_list))
}
type []map[string]json2.Any cannot be array encoded
[code.v:7] x.json2.encode(data_list): ["null"

@felipensp felipensp added the Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) label Apr 12, 2025
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: x.json2 Bugs related to *only* x.json2 (the pure V implementation)
Projects
None yet
Development

No branches or pull requests

3 participants