Skip to content

C error: json.decode fails for Option when json.encode was not called previously #24951

@jorgeluismireles

Description

@jorgeluismireles
V version: V 0.4.11 708c73b, press to see full `v doctor` output
V full version V 0.4.11 7dc3889.708c73b
OS linux, Ubuntu 22.04.5 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
Memory 0.53GB/3.7GB
V executable /home/jorge/v/v
V last modified time 2025-07-22 18:55:18
V home dir OK, value: /home/jorge/v
VMODULES OK, value: /home/jorge/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/jorge/bugs
Git version git version 2.34.1
V git status weekly.2025.16-464-g708c73b4
.git/config present true
cc version cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
gcc version gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
clang version Ubuntu clang version 14.0.0-1ubuntu1.1
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.5 ()
glibc version ldd (Ubuntu GLIBC 2.35-0ubuntu3.10) 2.35

What did you do?
./v -g -o vdbg cmd/v && ./vdbg 250722b.v && 250722b

import json

struct Base {
	time ?i64 @[omitempy]
}

fn main() {

	//_ := json.encode(Base{}) // workaround

	d1 := json.decode(Base, '{}')!
	dump(d1)
}

What did you see?

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/250722b.01K0T434TZZNP93QRFWPMC5BE2.tmp.c:2122: warning: implicit declaration of function '_option_ok'
cc: /home/jorge/v/thirdparty/tcc/lib/libgc.a: error: 'GC_noop1_ptr' defined twice
cc: tcc: error: undefined symbol '_option_ok'
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
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 .

What did you expect to see?

Compile.

Workaround

Call previously json.encode(Base{}) it should be over same struct Base:

fn main() {
	_ := json.encode(Base{}) // workaround
	d1 := json.decode(Base, '{}')!
	dump(d1)
}
[250722b.v:10] d1: Base{
    time: Option(none)
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: markusedBugs/feature requests, that are related to the -skip-unused.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions