diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bbd9679f59..9e27b27858 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2872,7 +2872,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { 'a variadic' } c.error('cannot type cast ${msg}', node.pos) - } else if !c.inside_unsafe && to_type.is_ptr() && from_type.is_ptr() + } else if !c.inside_unsafe && to_type.is_ptr() && from_type.is_ptr() && to_type != from_type && to_type.deref() != ast.char_type && from_type.deref() != ast.char_type { ft := c.table.type_to_str(from_type) tt := c.table.type_to_str(to_type) diff --git a/vlib/v/slow_tests/inout/cast_to_reference_type.out b/vlib/v/slow_tests/inout/cast_to_reference_type.out new file mode 100644 index 0000000000..66f826d044 --- /dev/null +++ b/vlib/v/slow_tests/inout/cast_to_reference_type.out @@ -0,0 +1 @@ +&&nil diff --git a/vlib/v/slow_tests/inout/cast_to_reference_type.vv b/vlib/v/slow_tests/inout/cast_to_reference_type.vv new file mode 100644 index 0000000000..b7aa911898 --- /dev/null +++ b/vlib/v/slow_tests/inout/cast_to_reference_type.vv @@ -0,0 +1,5 @@ +fn main() { + a := &&char(unsafe { nil }) + b := &&char(a) + println(b) +}