Skip to content

[json] decoding struct with i32 member results in cgen error: json: i32 is not structย #21161

Closed

Description

@revosw

Describe the bug

x.json2 expects a type to be provided. When the type is a struct with an i32 field, the below error is output:

cgen error: json: i32 is not struct

Reproduction Steps

import json

pub struct StructA {
	kind string
	value string
}
pub struct StructB {
	kind string
	value i32
}

type StructSum = StructA | StructB

fn main() {
	// cgen error: json: i32 is not struct
	json.decode(StructSum, '{"kind": "Int32", value: 100}')!
}

Expected Behavior

json.decode successfully decodes the json into an instance of StructB

Current Behavior

cgen error: json: i32 is not struct

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 5da1fcc

Environment details (OS name and version, etc.)

V full version: V 0.4.5 4687f8c.5da1fcc
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 12 cpus, 64bit, little endian,

getwd: C:\dev\v\winmd
vexe: C:\dev_tools\v\v.exe
vexe mtime: 2024-04-01 17:34:15

vroot: OK, value: C:\dev_tools\v
VMODULES: OK, value: C:\Users\simen.vmodules
VTMP: OK, value: C:\Users\simen\AppData\Local\Temp\v_0

Git version: git version 2.40.0.windows.1
Git vroot status: weekly.2024.13-65-g5da1fcca
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 a39eb79b

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.

Activity

  1. added
    BugThis tag is applied to issues which reports bugs.
    on Apr 1, 2024
  2. changed the title [-][x.json2] decoding struct with i32 member results in `cgen error: json: i32 is not struct`[/-] [+][json] decoding struct with i32 member results in `cgen error: json: i32 is not struct`[/+] on Apr 1, 2024
  3. self-assigned this
    on Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions