vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.76k stars 2.16k forks source link

Struct reference passed in a function generate invalid C code (ADDR macro args error) #12837

Open SheatNoisette opened 2 years ago

SheatNoisette commented 2 years ago

V doctor:

OS: linux, Linux version 5.15.6-200.fc35.x86_64 (mockbuild@bkernel01.iad2.fedoraproject.org) (gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1), GNU ld version 2.37-10.fc35) #1 SMP Wed Dec 1 13:41:10 UTC 2021
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 5800X 8-Core Processor
CC version: cc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)

getwd: /home/sheat/Documents/Projects/v/sandbox_tests/bug
vmodules: /home/sheat/.vmodules
vroot: /home/sheat/Documents/Tools/v
vexe: /home/sheat/Documents/Tools/v/v
vexe mtime: 2021-12-14 14:03:32
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 045579f.a1efde8

Git version: git version 2.33.1
Git vroot status: weekly.2021.48-108-ga1efde8b
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 333c14de

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

module main

[heap]
struct MyStruct {
    number int
}

fn pass(t &MyStruct) &MyStruct {
    return t
}

fn main() {
    pass(MyStruct{})
}

What did you expect to see?

Successiful build or a unused function result warning.

What did you see instead?

==================
/tmp/v_1000/bug.3129042051684785643.tmp.c:10721: error: macro 'ADDR' used with too many args
...
==================
(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
ken0x0a commented 2 years ago

This build successfully now.

But should this build successfully? I feel this should be compile error at

    pass(MyStruct{})

with "MyStruct, has attr heap, must be initialized with &"