cgen: fix expr_as_cast for int/float literals (#12067)
parent
8d1ba52d0c
commit
7555b337b9
|
@ -2240,7 +2240,12 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
|
||||||
got_styp)
|
got_styp)
|
||||||
g.inside_cast_in_heap--
|
g.inside_cast_in_heap--
|
||||||
} else {
|
} else {
|
||||||
got_styp := g.cc_type(got_type, true)
|
mut got_styp := g.cc_type(got_type, true)
|
||||||
|
got_styp = match got_styp {
|
||||||
|
'int' { 'int_literal' }
|
||||||
|
'f64' { 'float_literal' }
|
||||||
|
else { got_styp }
|
||||||
|
}
|
||||||
exp_styp := exp_sym.cname
|
exp_styp := exp_sym.cname
|
||||||
mut fname := '/*$exp_sym*/I_${got_styp}_to_Interface_$exp_styp'
|
mut fname := '/*$exp_sym*/I_${got_styp}_to_Interface_$exp_styp'
|
||||||
if exp_sym.info.is_generic {
|
if exp_sym.info.is_generic {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
interface IExample {}
|
||||||
|
|
||||||
|
fn thing(a IExample) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_as_cast_with_literals() {
|
||||||
|
assert thing(true)
|
||||||
|
assert thing(123)
|
||||||
|
assert thing(12.3)
|
||||||
|
assert thing('abc')
|
||||||
|
}
|
Loading…
Reference in New Issue