vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

Allows annonymous struct type to be passed as args #21703

Open XiaoPangxie732 opened 1 week ago

XiaoPangxie732 commented 1 week ago

Describe the feature

Allows passing anonymous struct type where a method parameter requires a type

Use Case

For example the json decoding:

json_text := '{ "a": "b" }'
b := json.decode(struct {
    a string
}, json_text)!.a

there's no need to create a named struct type if the decoding of this type only exists here

Proposed Solution

No response

Other Information

https://discord.com/channels/592103645835821068/700746775962714232/1252377577083895919

Acknowledgements

Version used

V 0.4.6 58f4e12

Environment details (OS name and version, etc.)

V full version: V 0.4.6 30d6f7b.58f4e12 OS: windows, Microsoft Windows 11 רҵ�� v22631 64 λ Processor: 12 cpus, 64bit, little endian,

getwd: xxx vexe: E:\Programs\v\v.exe vexe mtime: 2024-06-19 12:43:43

vroot: OK, value: E:\Programs\v VMODULES: OK, value: C:\Users\xxx.vmodules VTMP: OK, value: C:\Users\xxx\AppData\Local\Temp\v_0

Git version: git version 2.38.1.windows.1 Git vroot status: weekly.2023.24-2387-g58f4e126 .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.