Skip to content

Does not support deeply nested anonymous C structs #25807

@kbkpbot

Description

@kbkpbot

Describe the bug

V language currently lacks support for parsing and converting deeply nested anonymous C structures. When attempting to use V's C interoperability features with C header files containing multi-level nested anonymous structs, parsing errors occur.

related to issue #25788

Reproduction Steps

$ tree .
.
├── deep.h
├── deep.v
└── v.mod

1 directory, 3 files

touch v.mod

deep.h

#ifndef __DEEP_H__
#define __DEEP_H__

struct DeepStruct{
        int A1;
        struct {
                int A2;
                struct {
                       int A3;
                       struct {
                                int A4;
                       } S3;
                } S2;
        } S1;
};
#endif

deep.v

module main

#insert "@VMODROOT/deep.h"

struct C.DeepStruct {
        A1 int
        S1 struct {
                A2 int
                S2 struct {
                        A3 int
                        S3 struct {
                                A4 int
                        }
                }
        }
}

fn main() {
        x := C.DeepStruct{}
        dump(x)
}

Compile deep.v:

v deep.v

Expected Behavior

compile ok

Current Behavior

$ v deep.v
deep.v:9:3: error: struct embedding must be declared at the beginning of the struct body
    7 |     S1 struct {
    8 |         A2 int
    9 |         S2 struct {
      |         ~~
   10 |             A3 int
   11 |             S3 struct {

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 bf7f43f

Environment details (OS name and version, etc.)

V full version V 0.4.12 bf7f43f
OS linux, Ubuntu 24.04.3 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 11.05GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-11-22 12:31:54
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/struct/x
Git version git version 2.43.0
V git status weekly.2025.46-75-gbf7f43f2-dirty
.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.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions