Skip to content

Commit 3e628d0

Browse files
authored
checker: fix cast from an empty struct to option (fix #25566) (#25581)
1 parent bfd36f8 commit 3e628d0

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎vlib/v/checker/checker.v‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
35503550
c.warn('casting to struct is deprecated, use e.g. `Struct{...expr}` instead',
35513551
node.pos)
35523552
}
3553-
if !c.check_struct_signature(from_sym.info, to_sym.info) {
3553+
if from_type.idx() != to_type.idx()
3554+
&& !c.check_struct_signature(from_sym.info, to_sym.info) {
35543555
c.error('cannot convert struct `${from_sym.name}` to struct `${to_sym.name}`',
35553556
node.pos)
35563557
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct Struct {}
2+
3+
fn main() {
4+
s := ?Struct(Struct{})
5+
a := s or { panic('none') }
6+
assert a == Struct{}
7+
}

0 commit comments

Comments
 (0)