diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b97e6de224..59b7cafcda 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2629,7 +2629,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { // node.typ: `Outside` node.expr_type = c.expr(node.expr) // type to be casted - mut from_type := node.expr_type + mut from_type := c.unwrap_generic(node.expr_type) from_sym := c.table.sym(from_type) final_from_sym := c.table.final_sym(from_type) diff --git a/vlib/v/tests/cast_in_comptime_if_test.v b/vlib/v/tests/cast_in_comptime_if_test.v new file mode 100644 index 0000000000..bd3f8d45ea --- /dev/null +++ b/vlib/v/tests/cast_in_comptime_if_test.v @@ -0,0 +1,18 @@ +fn test_cast_in_comptime_if() { + generic_bool(true) +} + +fn generic_bool(val T) { + $if T is bool { + println(byte(val)) + assert byte(val) == 1 + + println(i8(val)) + assert i8(val) == 1 + + println(i16(val)) + assert i16(val) == 1 + } $else { + assert false + } +}