Skip to content

shared int in a struct can't has a default value #25990

Description

@kbkpbot

Describe the bug

try to assign a default value to a shared int field in a struct, will cause runtime error.

Reproduction Steps

s.v

module main

struct Foo {
mut:
        a shared int = 200
}

fn main() {
        mut x := Foo{}
        dump(x)
}
v run s.v

Expected Behavior

output x.a == 200

Current Behavior

$ v run s.v
/tmp/v_1000/s.01KCKPNE88WDSFWRV83PRMRQ0Q.tmp.c:2891: at indent_main__Foo_str: RUNTIME ERROR: invalid memory access
/tmp/v_1000/s.01KCKPNE88WDSFWRV83PRMRQ0Q.tmp.c:2884: by main__Foo_str
/tmp/v_1000/s.01KCKPNE88WDSFWRV83PRMRQ0Q.tmp.c:2911: by _v_dump_expr_main__Foo
/tmp/v_1000/s.01KCKPNE88WDSFWRV83PRMRQ0Q.tmp.c:8874: by main__main
/tmp/v_1000/s.01KCKPNE88WDSFWRV83PRMRQ0Q.tmp.c:8964: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 967a4a2.c445b0c

Environment details (OS name and version, etc.)

V full version V 0.4.12 967a4a2.c445b0c
OS linux, Ubuntu 24.04.3 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 9.89GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-12-16 13:40:51
V home dir OK, value: /media/HD/github/kbkpbot/v
VMODULES OK, value: /home/mars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/mars/v/bug/autostr
Git version git version 2.43.0
V git status weekly.2025.46-216-g1356b642
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version Ubuntu clang version 18.1.3 (1ubuntu1)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39

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

    BugThis tag is applied to issues which reports bugs.shared types

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions