v icon indicating copy to clipboard operation
v copied to clipboard

cgen error for `println( var or { 100 } )`, when `var := ?int(none)`

Open spytheman opened this issue 2 years ago • 1 comments

V doctor:

OS: linux, Ubuntu 20.04.5 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
CC version: cc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

getwd: /v/vclean
vmodules: /home/delian/.vmodules
vroot: /v/vnew
vexe: /v/vnew/v
vexe mtime: 2023-03-07 15:18:05
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 1a48d08.784592a

Git version: git version 2.39.0
Git vroot status: weekly.2023.10-2-g784592af-dirty (5 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do? v -g -o vdbg cmd/v && vdbg var.v

var := ?int(none)
println( var or { 100 } )


What did you expect to see?

Compiled program that can be run without errors, printing 100

What did you see instead?

==================
/tmp/v_1000/var.8639658087315509316.tmp.c:12301: error: cannot convert 'int' to 'struct _option_int'
...
==================
(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

spytheman avatar Mar 07 '23 17:03 spytheman

Note: println( (var or { 100 }) ) does work without a cgen error. So does: dump( (var or { 100 }) ) and dump(var or { 100 }) .

spytheman avatar Mar 07 '23 18:03 spytheman