mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: fix mutable ptr sumtype (#24021)
This commit is contained in:
parent
e733c007bf
commit
cc5f32f1ca
2 changed files with 31 additions and 1 deletions
|
@ -2757,7 +2757,7 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp ast.Ty
|
|||
mut mutable_idx := 0
|
||||
|
||||
is_not_ptr_and_fn := !got_is_ptr && !got_is_fn
|
||||
is_sumtype_cast := is_not_ptr_and_fn && fname.contains('_to_sumtype_')
|
||||
is_sumtype_cast := !got_is_fn && fname.contains('_to_sumtype_')
|
||||
is_comptime_variant := is_not_ptr_and_fn && expr is ast.Ident
|
||||
&& g.comptime.is_comptime_variant_var(expr)
|
||||
|
||||
|
|
30
vlib/v/tests/sumtypes/sumtype_mutable_test.v
Normal file
30
vlib/v/tests/sumtypes/sumtype_mutable_test.v
Normal file
|
@ -0,0 +1,30 @@
|
|||
module main
|
||||
|
||||
type MySumType = MyStructA | MyStructB
|
||||
|
||||
struct MyStructA {
|
||||
mut:
|
||||
test bool
|
||||
}
|
||||
|
||||
struct MyStructB {
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut my_struct := &MyStructA{
|
||||
test: false
|
||||
}
|
||||
if $d('mutable_sumtype', false) {
|
||||
assert my_struct.test == false
|
||||
my_struct.test = true
|
||||
assert my_struct.test == true
|
||||
but_why(mut my_struct)
|
||||
assert my_struct.test == false
|
||||
}
|
||||
}
|
||||
|
||||
fn but_why(mut passed MySumType) {
|
||||
if mut passed is MyStructA {
|
||||
passed.test = false
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue