Skip to content

Compiler panics on empty struct #24404

@xTheFreeZe

Description

@xTheFreeZe

Describe the bug

This bug has likely been fixed by: 24403

When trying to compile this code:

pub struct Foo {
pub mut:
   
}

the compiler panics with the following message:

V panic: array.last: array is empty
v hash: 8cb0fc7
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:19671: at _v_panic: Backtrace
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:19250: by array_last
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:16838: by v__parser__Parser_struct_decl
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12956: by v__parser__Parser_top_stmt
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12588: by v__parser__Parser_parse
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12551: by v__parser__parse_file
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12652: by v__parser__parse_files
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50366: by v__builder__Builder_parse_imports
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50247: by v__builder__Builder_front_stages
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50302: by v__builder__Builder_front_and_middle_stages
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52833: by v__builder__cbuilder__gen_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52805: by v__builder__cbuilder__build_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52796: by v__builder__cbuilder__compile_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52713: by v__builder__Builder_rebuild
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:51866: by v__builder__compile
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53231: by main__rebuild
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53186: by main__main
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53934: by main

Interestingly enough, this code compiles:

pub struct Foo {
    
}

Reproduction Steps

To reproduce this bug, try to compile this code:

pub struct Foo {
pub mut:
    
}

Expected Behavior

The code either compiles or the compiler throws an error

Current Behavior

The compiler panics:

V panic: array.last: array is empty
v hash: 8cb0fc7
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:19671: at _v_panic: Backtrace
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:19250: by array_last
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:16838: by v__parser__Parser_struct_decl
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12956: by v__parser__Parser_top_stmt
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12588: by v__parser__Parser_parse
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12551: by v__parser__parse_file
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:12652: by v__parser__parse_files
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50366: by v__builder__Builder_parse_imports
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50247: by v__builder__Builder_front_stages
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:50302: by v__builder__Builder_front_and_middle_stages
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52833: by v__builder__cbuilder__gen_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52805: by v__builder__cbuilder__build_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52796: by v__builder__cbuilder__compile_c
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:52713: by v__builder__Builder_rebuild
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:51866: by v__builder__compile
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53231: by main__rebuild
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53186: by main__main
/tmp/v_1000/v2.01JTCZDYBXFHGHJ09J5ZEQ008B.tmp.c:53934: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V version: V 0.4.10 8cb0fc7

Environment details (OS name and version, etc.)

|V full version      |V 0.4.10 1cb76c9.8cb0fc7
|:-------------------|:-------------------
|OS                  |linux, "Fedora Linux 42 (Workstation Edition)"
|Processor           |12 cpus, 64bit, little endian, AMD Ryzen 5 2600 Six-Core Processor
|Memory              |14.11GB/23.39GB
|                    |
|V executable        |/home/marwin/v/v
|V last modified time|2025-05-04 06:23:44
|                    |
|V home dir          |OK, value: /home/marwin/v
|VMODULES            |OK, value: /home/marwin/.vmodules
|VTMP                |OK, value: /tmp/v_1000
|Current working dir |OK, value: /home/marwin
|                    |
|Git version         |git version 2.49.0
|V git status        |weekly.2025.16-91-g8cb0fc7c
|.git/config present |true
|                    |
|cc version          |cc (GCC) 15.1.1 20250425 (Red Hat 15.1.1-1)
|gcc version         |gcc (GCC) 15.1.1 20250425 (Red Hat 15.1.1-1)
|clang version       |clang version 20.1.3 (Fedora 20.1.3-1.fc42)
|tcc version         |tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
|tcc git status      |thirdparty-linux-amd64 0134e9b9
|emcc version        |N/A
|glibc version       |ldd (GNU libc) 2.41

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

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions