generic code struggles with optional function args #21215
Labels
Bug
This tag is applied to issues which reports bugs.
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Describe the bug
Calling generic higher order functions with optional callbacks leads to all kinds of C compile and runtime errors. I have tried to provide a concrete example that is easy to understand, but this gives issues completely different to the issues I was originally running into. This case still seem like a simpler place to start, before I try and build SSCCEs for the other issues I found.
Reproduction Steps
Expected Behavior
I expect the above code to work, and to print
State { x: 4 }
. I also expect any subset of those four lines to work.Current Behavior
Many things go wrong.
The first thing seems intentional:
Fine, so let's remove line 26.
Now it compiles, but crashes:
so remove line 24, and run again:
State{ x: 4 }
It works. Okay, let's remove line 23 now, and just call the function once.
cgen seems to have screwed something up now. weird!
This may turn out to be one bug or two, but these were just the things I ran into this time. Other times I find these higher order functions work fine, and other times I think I run into other issues. I can experiment more and give more specific bug reports once the general chaos has been fixed a little.
Possible Solution
Good luck.
Additional Information/Context
Similar to #21214 I encountered these issues trying to make a wrapper for
gg
that handled streaming images automatically. Some apps provide event callbacks, other apps just provide do_frame callbacks with no event callbacks. I got it working, with lots of[T]
annotations everywhere, but it was a minefield.V version
V 0.4.5 ad17be5
Environment details (OS name and version, etc.)
V full version: V 0.4.5 386bd77.ad17be5
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 4 cpus, 64bit, little endian,
getwd: C:\Users\Owner\Code\v-experiments
vexe: C:\Program Files\v\v.exe
vexe mtime: 2024-04-07 05:22:56
vroot: contains spaces, value: C:\Program Files\v
VMODULES: OK, value: C:\Users\Owner.vmodules
VTMP: OK, value: C:\Users\Owner\AppData\Local\Temp\v_0
Git version: git version 2.37.2.windows.2
Git vroot status: weekly.2024.14-26-gad17be5d (6 commit(s) behind V master)
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc: N/A
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.
The text was updated successfully, but these errors were encountered: