v
v copied to clipboard
Pushing none onto mutable list of optional types results in compiler error.
Describe the bug
Creating a mutable list of optional types then pushing none
onto it results in a compilation error.
Let's suppose we have the following code:
mut vals := []?string{cap: 4}
vals << none
vals << "Fizz"
vals << "Buzz"
vals << "FizzBuzz"
However, the compiler errors out instead of inferring the type of none
to be ?string(none)
.
Expected Behavior
I would expect it to be equivalent to the following code:
mut vals := [?string(none), "Fizz", "Buzz", "FizzBuzz"]
Current Behavior
The compiler errors out saying it is a compiler error after running it with v -cg file.v
The actual error is this:
/tmp/v_1000/main.13467963317378719974.tmp.c:12466: error: cannot convert 'extern struct IError' to 'struct string'
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
[...]
I left out the how to report information. ([...]
)
Reproduction Steps
Make an array of type []?type
where type
can be probably any type, only tested with int
and string
.
Try pushing none
on that array.
mut arr = []?int{cap: 10}
arr << none
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 b71c131
Environment details (OS name and version, etc.)
x86_64 Linux - Fedora 36
The output of v doctor
:
V full version: V 0.3.3 30c205e.b71c131
OS: linux, Linux version 6.1.14-100.fc36.x86_64 ([email protected]) (gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4), GNU ld version 2.37-37.fc36) #1 SMP PREEMPT_DYNAMIC Sun Feb 26 00:31:11 UTC 2023
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
getwd: /home/kintrix/Documents/test-coding/vlang
vexe: /home/kintrix/bin/v/v
vexe mtime: 2023-03-14 16:06:13
vroot: OK, value: /home/kintrix/bin/v
VMODULES: OK, value: /home/kintrix/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.39.2
Git vroot status: weekly.2023.11-2-gb71c1316
.git/config present: true
CC version: cc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3