vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.51k stars 2.15k forks source link

using float/int sumtype cast results in C error #14428

Closed boonsboos closed 1 year ago

boonsboos commented 2 years ago

writing a bug report due to an issue posted in the discord. message link

What did you do? a.v

fn cast(a int | f64) f64 {
    return f64(a)
}

println(cast(10))

v run a.v

What did you expect to see? 10. in the console

What did you see instead?

/tmp/v_1000/a.18217470816788589904.tmp.c:11611: error: invalid aggregate type for register load
builder error:
==================

which is the C representation of the function:

f64 main__cast(main___v_anon_sum_type_f64_int a) {
    f64 _t1 = ((f64)(a));
    return _t1;
}

VS Code squiggles this cast, so i suspect this to be a cgen error. using a non-anonymous sumtype results in the same error and C code.

V version: V 0.2.4 bc397bb OS: Arch Linux 5.16.16-arch-1 Compiler used: tcc

changrui commented 2 years ago

Oh, No, It may be a as f64.

DevrosTheOne commented 2 years ago

[changrui] f64(a as int) for int parameter

changrui commented 2 years ago

[changrui] f64(a as int) for int parameter

YES, Sir. @DevrosTheOne