[omitempty] for strings causes compilation error
Closed this issue · 1 comments
tobyjwebb commented
V doctor:
OS: linux, Pop!_OS 21.04
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
CC version: cc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
getwd: /home/me/Desktop
vmodules: /home/me/.vmodules
vroot: /home/me/REPOS/v/v
vexe: /home/me/REPOS/v/v/v
vexe mtime: 2021-11-24 19:19:36
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 fbe2b5c.11d7062
Git version: git version 2.30.2
Git vroot status: weekly.2021.47-15-g11d70624
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 333c14de
What did you do?
v -g -o vdbg cmd/v && vdbg omitempty.v
import json
struct Foo {
foo int [omitempty]
}
struct Bar {
foo string [omitempty] // This line causes the file not to compile
}
five := json.encode(&Foo{5})
println('$five') // {"foo":5}
empty := json.encode(&Foo{0})
println('$empty') // {}
empty_str := json.encode(&Bar{})
println('$empty_str') // EXPECTED: {}
What did you expect to see?
The file to compile
What did you see instead?
==================
/tmp/v_1000/omitempty.15370911601244302045.tmp.c:1983: error: invalid operand types for binary operation
/tmp/v_1000/omitempty.15370911601244302045.tmp.c:1983: error: invalid aggregate type for register load
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
enghitalo commented
now
[/home/hitalo/v/vlib/x/json2/json2.v:78] err: cannot encode value with &Foo type
null
[/home/hitalo/v/vlib/x/json2/json2.v:78] err: cannot encode value with &Foo type
null
[/home/hitalo/v/vlib/x/json2/json2.v:78] err: cannot encode value with &Bar type
null