-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
AutofreeBugs/feature requests, that are related to -autofree.Bugs/feature requests, that are related to -autofree.BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.
Description
Describe the bug
compile a program which re-assignment a mut array, when compile with autofree, it will fail with error: '{' expected (got ";")
Reproduction Steps
a.v
module main
struct MyS {
a int
}
fn need_free(mut x []MyS) {
x = []MyS{}
}
fn main() {
mut xx := []MyS{}
need_free(mut xx)
}v a.v -autofree -showcc -keepc
Expected Behavior
compile & run ok
Current Behavior
$ v a.v -autofree -showcc -keepc
> C compiler cmd: '/media/HD/github/lang/v/thirdparty/tcc/tcc.exe' '@/tmp/v_1000/a.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/a.tmp.c.rsp":
-fwrapv -o "/home/mars/v/bug/autofree/a" "/tmp/v_1000/a.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -bt25
> C compiler cmd: 'cc' '@/tmp/v_1000/a.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/a.tmp.c.rsp":
-fwrapv -o '/home/mars/v/bug/autofree/a' "/tmp/v_1000/a.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/a.tmp.c:5879: error: '{' expected (got ";")
=================================================================
(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 .
Possible Solution
No response
Additional Information/Context
generated C code:
VV_LOC void main__need_free(Array_main__MyS* x) {
array _sref67 = (x); // free array on re-assignment2
*x = builtin____new_array_with_default(0, 0, sizeof(main__MyS), 0);
builtin__array_free(&_sref67);
}V version
V 0.4.12 8fa8354
Environment details (OS name and version, etc.)
| V full version | V 0.4.12 8fa8354 |
|---|---|
| OS | linux, Ubuntu 24.04.3 LTS |
| Processor | 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz |
| Memory | 10.3GB/15.51GB |
| V executable | /media/HD/github/lang/v/v |
| V last modified time | 2025-09-21 15:13:19 |
| V home dir | OK, value: /media/HD/github/lang/v |
| VMODULES | OK, value: /home/mars/.vmodules |
| VTMP | OK, value: /tmp/v_1000 |
| Current working dir | OK, value: /home/mars/v/bug/autofree |
| Git version | git version 2.43.0 |
| V git status | 0.4.12-9-g8fa8354b |
| .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.5) 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.
Avey777Avey777
Metadata
Metadata
Assignees
Labels
AutofreeBugs/feature requests, that are related to -autofree.Bugs/feature requests, that are related to -autofree.BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.