-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V gets confused when dealing with Optional Sum Types and spits invalid C code #23349
Comments
You V is at least 15 commits behind the current. Do When I tried your first example here, it worked fine, with no errors from V or C. I saved it as
|
Sorry, i forgot the question mark before |
The C error is produced when an unwrapped option is tried to be converted with type Sum = int | string
fn sum() ?Sum { return Sum(5) }
a := sum()?
println(a as int) // 5
b := sum()
println(b) // Option(Sum(5))
println(b? as int) // 5
println(b as int) // C error In the last line
|
So just a := sum()
println(a as int) doesn't trigger the error? |
Just tested, it does |
Yes, simply these two lines: type Sum = int | string
println(?Sum(5) as int) |
Please file another issue for this. |
Isn't it the same thing? |
Doesn't appear to be. Just tried with latest update, and got
|
Describe the bug
When using
?SumType
, the compiler sometimes gets confused and generates invalid C code. I found two scenarios where this happens.Reproduction Steps
?T
toU
whenT = U | Other
:T
to?T
and checking if?T
isU
(whenT = U | Other
:Expected Behavior
The V compiler should error on both situations, preventing the error from propagating into the generated C code, which is harder to analyse
Current Behavior
In my current codebase, it gave these errors:
The code contained both cases in it.
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.9 7b9b3dd
Environment details (OS name and version, etc.)
V full version: V 0.4.9 b487986.7b9b3dd OS: termux, 3.18.140-SIMPLE-KERNEL_V1.1, #1 SMP PREEMPT Sun Apr 18 03:22:59 -03 2021
Processor: 8 cpus, 64bit, little endian getwd: /storage/emulated/0/Documents/hex vexe: /data/data/com.termux/files/home/.v/v vexe mtime: 2024-12-31 18:09:35 vroot: OK, value: /data/data/com.termux/files/home/.v VMODULES: OK, value: /data/data/com.termux/files/home/.vmodules
VTMP: OK, value: /data/data/com.termux/files/usr/tmp/v_10246 Git version: git version 2.47.1 Git vroot status: weekly.2024.53 (15 commit(s) behind V master)
.git/config present: true
CC version: clang version 19.1.6 emcc version: N/A
thirdparty/tcc status: thirdparty-unknown-unknown de82a13
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: