Repository navigation
C errorΒ #23403
Copy link
Copy link
Closed
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: cgenBugs/feature requests, that are related to the default C generating backend.Bugs/feature requests, that are related to the default C generating backend.
Description
V version: V 0.4.9 9fc8352, press to see full `v doctor` output
| V full version | V 0.4.9 6ac1d08.9fc8352 |
|---|---|
| OS | linux, "Void Linux" |
| Processor | 4 cpus, 64bit, little endian, Intel(R) Pentium(R) Gold 7505 @ 2.00GHz |
| Memory | 17.37GB/23.16GB |
| V executable | /home/nopana/v/v |
| V last modified time | 2025-01-07 23:24:19 |
| V home dir | OK, value: /home/nopana/v |
| VMODULES | OK, value: /home/nopana/.vmodules |
| VTMP | OK, value: /tmp/v_1000 |
| Current working dir | OK, value: /home/nopana/projects/notOnlyNots |
| Git version | git version 2.47.1 |
| V git status | weekly.2024.52-90-g9fc83526 |
| .git/config present | true |
| cc version | cc (GCC) 13.2.0 |
| gcc version | gcc (GCC) 13.2.0 |
| clang version | N/A |
| 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.39 |
What did you do?
./v -g -o vdbg cmd/v && ./vdbg main.v && main
above is the command v bug uses, but I used : v run main.v
import gg
struct App {
mut:
ctx &gg.Context = unsafe { nil }
}
fn main() {
mut app := &App{}
app.ctx = gg.new_context(
user_data: app
event_fn: on_event
)
}
fn on_event(e &gg.Event, mut app App) {
_ := match [0, 0]! {
[0, 1]! {
0
}
else {
panic('')
}
}
}
What did you see?
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01JH1KEX3FBGZXDNT5792TSTVY.tmp.c:11467: error: expression expected before '{'
=================================================================
(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 .
What did you expect to see?
No C error
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.This bug has been confirmed to be valid by a contributor.Unit: cgenBugs/feature requests, that are related to the default C generating backend.Bugs/feature requests, that are related to the default C generating backend.
Activity
jorgeluismireles commentedon Jan 8, 2025
Wow! C appart, and fixed arrays appart, I didn't know V permitted to set non-constant match options!
This code is accepted:
even though in
check(1,1,1)call variablesbandcare equal which is not permitted normally.Next code is rejected but is weird:
produces:
JalonSolov commentedon Jan 8, 2025
Well,
awill always matcha...You
a, b, cexample works because they are separate variables, even if they have the same contents. Otherwise,check(1, 1, 2)wouldn't work, neither wouldcheck(2, 1, 2), etc.check(1, 2, 3)will fall into theelse, since the contents ofadon't match either of the other 2.In fact, you can match on ranges, on the results of fn calls, etc. - anything that matches the type of the variable you're matching against.
jorgeluismireles commentedon Jan 8, 2025
This code is accepted and always prints
a. Never1, neverelse... even though the programmer thinks they would be possible.jorgeluismireles commentedon Jan 8, 2025
This program can print
1, otherwise justa, but neverelsebecause I moved1as first match!JalonSolov commentedon Jan 8, 2025
Incorrect. It will only print
1if you call it withcheck_4(1). Otherwise, it will printa, sinceaalways matchesa.output is
JalonSolov commentedon Jan 8, 2025
Your
check_3will always printa, becauseaalways matchesa, and that is checked first.jorgeluismireles commentedon Jan 8, 2025
JalonSolov: For
fn check_4(a int) string {I said the same you said. Anyway, imho the possibility of dead code is important so I open issue #23404 to consider to send a warning.Returning to the origin of this post, seems to me the branch of
0is dead code, because never[0,0]!will be equal to[0,1]!:Yes, if and only if the compiler accepts such fixed array as comparable variables.
cgen: fix codegen for array fixed comparison on MatchExpr (fix #23403) (