You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a rather bizarre issue. When I use the following code, if the User struct does not include a time.Time field, or if the field is defined as []map[string]Any instead of []map[string]?Any, it runs normally without any errors.
Reproduction Steps
importjsonimporttimetypeAny=string| []map[string]?Any | time.Time
structUsers {
mut:
id string
created_at time.Time
}
data_all:= [Users{
id: '123'
created_at : time.now()
}, Users{
id: 'asd'
created_at : time.now()
}]
mutresult:= []map[string]?Any{}
for raw in data_all {
mutdata:=map[string]?Any{}
data['id'] = raw.id
data['time'] = raw.created_at
result << data
}
println(result)
msg:= json.encode(result)
println(msg)
[root_cn@archlinux json_null]$ v test_none.v -cg
/tmp/v_1000/test_none.01JRDKHSCE9ZJ2EKMDKRKYCFSX.tmp.c:2551: error: cannot convert 'struct main__Any' to 'struct _option_main__Any'
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
[root_cn@archlinux json_null]$ v test_none.v -show-c-output
======== Output of the C Compiler (/mnt/d/file/vlang/v/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/test_none.01JRDKJEY77SZTADGV5TDTXSPQ.tmp.c:2545: error: cannot convert 'struct main__Any' to 'struct _option_main__Any'
=======================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/test_none.01JRDKJEY77SZTADGV5TDTXSPQ.tmp.c: In function ‘json__decode__option_main__Any’:
/tmp/v_1000/test_none.01JRDKJEY77SZTADGV5TDTXSPQ.tmp.c:2545:39: error: incompatible types when assigning to type ‘_option_main__Any’ from type ‘main__Any’
2545 | res = time__Time_to_sumtype_main__Any(&_t6);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===============================================
Describe the bug
This is a rather bizarre issue. When I use the following code, if the
User
struct does not include a time.Time field, or if the field is defined as[]map[string]Any
instead of[]map[string]?Any
, it runs normally without any errors.Reproduction Steps
Expected Behavior
like this:
Current Behavior
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.10 55b16fb
Environment details (OS name and version, etc.)
in linux:
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.
The text was updated successfully, but these errors were encountered: