Skip to content

optional sumtype struct field builder errorย #20181

Closed

Description

@7underlines

Describe the bug

This code

import json

type Prices = []Price | Price

pub struct ShopResponseData {
    attributes Attributes
}

struct Attributes {
    price ?Prices
}

struct Price {
    net f64
}

fn main() {
    data := '{"attributes": {"price": [{"net": 1}, {"net": 2}]}}'
    entity := json.decode(ShopResponseData, data) or { panic(err) }

    data2 := '{"attributes": {"price": {"net": 1}}}'
    entity2 := json.decode(ShopResponseData, data2) or { panic(err) }

    println(entity)
    println(entity2)
}

Gives this compiler error:
/tmp/v_1000/1.1463261147480528181.tmp.c:2389: error: cannot convert 'struct main__Prices' to 'struct _option_main__Prices'

Reproduction Steps

Use the code from above and v run .

Expected Behavior

successful compilation

Current Behavior

builder error:

v -cg run 1.v
/tmp/v_1000/1.17748602982829807624.tmp.c:2391: error: cannot convert 'struct main__Prices' to 'struct _option_main__Prices'
builder error: 
==================
C error. This should never happen.

Possible Solution

No response

Additional Information/Context

Code was suggested on Discord https://discord.com/channels/592103645835821068/592294828432424960/1184889411259859084

V version

V 0.4.3 c5a6aeb

Environment details (OS name and version, etc.)

V full version: V 0.4.3 25777bd.c5a6aeb
OS: linux, Pop!_OS 22.04 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8305G CPU @ 2.80GHz

getwd: /home/loguser002/a/obereapotheke-import
vexe: /home/loguser002/a/v/v
vexe mtime: 2023-12-15 06:50:31

vroot: OK, value: /home/loguser002/a/v
VMODULES: OK, value: /home/loguser002/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1
Git vroot status: weekly.2023.50-29-gc5a6aebc
.git/config present: true

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

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 Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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