diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 218200bab4..aebb52f23e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 { diff --git a/vlib/v/tests/as_cast_literal.v b/vlib/v/tests/as_cast_literal.v new file mode 100644 index 0000000000..44f82e27e7 --- /dev/null +++ b/vlib/v/tests/as_cast_literal.v @@ -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') +}