1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix expr_as_cast for int/float literals (#12067)

This commit is contained in:
05st 2021-10-05 01:53:05 -05:00 committed by GitHub
parent 8d1ba52d0c
commit 7555b337b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -2240,7 +2240,12 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
got_styp)
g.inside_cast_in_heap--
} 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
mut fname := '/*$exp_sym*/I_${got_styp}_to_Interface_$exp_styp'
if exp_sym.info.is_generic {

View File

@ -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')
}