v
v copied to clipboard
C error when setting an optional alias type
V doctor:
OS: windows, Microsoft Windows 11 Pro v22000 64-bit
Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
CC version: tcc version 0.9.27 (x86_64 Windows)
getwd: C:\dev\in_progress\vmarkdown
vmodules: C:\Users\sharp\.vmodules
vroot: C:\dev\misc\v
vexe: C:\dev\misc\v\v.exe
vexe mtime: 2022-08-22 14:59:54
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 a689641
Git version: git version 2.34.1.windows.1
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false
thirdparty/tcc: N/A
What did you do?
v -g -o vdbg cmd/v && vdbg src/bug.v
type TreeIndex = usize
struct Node {
mut:
next ?TreeIndex
}
fn main() {
mut node := Node {}
node.next = 0
}
What did you expect to see?
no C error
What did you see instead?
==================
C:/Users/sharp/AppData/Local/Temp/v_0/bug.2555758640680499064.tmp.c:7391: warning: cast between pointer and integer of different size
C:/Users/sharp/AppData/Local/Temp/v_0/bug.2555758640680499064.tmp.c:12283: error: cannot convert 'int' to 'struct _option_main__TreeIndex'
...
==================
(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
The same happens when I use a struct instead of a type alias:
struct TreeIndex {index usize}
struct Node {
mut:
next ?TreeIndex
}
fn main() {
mut node := Node {}
node.next = TreeIndex{0}
}
This is similar to: #14185 This does not work for any optional type. You can maybe rename your issue since it's not really about optional alias type.
struct Node {
mut:
next ?usize
}
fn main() {
mut node := Node {}
node.next = 0
}
==================
/tmp/v_1000/bug.17695358547426339078.tmp.c:12107: error: cannot convert 'int' to 'struct _option_usize'
...
==================