mirror of
https://github.com/vlang/v.git
synced 2025-09-13 17:36:52 -04:00
debug: fix variable dereferencing (#20594)
This commit is contained in:
parent
9d048792fe
commit
135e2f1cc6
13
vlib/v/debug/tests/mut_sumtype.expect
Normal file
13
vlib/v/debug/tests/mut_sumtype.expect
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env expect
|
||||
source "common.tcl"
|
||||
|
||||
expect "Break on *main* test in ${test_file}:8\r\n"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "p f\n"
|
||||
expect "f = Test(Test2{}) (main.Test)"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "p t\n"
|
||||
expect "t = Test(Test2{}) (&main.Test)"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "q\n"
|
||||
expect eof
|
14
vlib/v/debug/tests/mut_sumtype.vv
Normal file
14
vlib/v/debug/tests/mut_sumtype.vv
Normal file
@ -0,0 +1,14 @@
|
||||
struct Test2 {}
|
||||
|
||||
struct Test3 {}
|
||||
|
||||
type Test = Test2 | Test3
|
||||
|
||||
fn (f Test) test(mut t Test) {
|
||||
$dbg;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut a := Test(Test2{})
|
||||
a.test(mut a)
|
||||
}
|
35
vlib/v/debug/tests/option.expect
Normal file
35
vlib/v/debug/tests/option.expect
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env expect
|
||||
source "common.tcl"
|
||||
|
||||
expect "Break on *main* test in ${test_file}:8\r\n"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "p f\n"
|
||||
expect "f = Test(Test2{}) (main.Test)"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "p t\n"
|
||||
expect "t = Option(Test(Test2{})) (?main.Test)"
|
||||
expect "${test_file}:8 vdbg> "
|
||||
send "c\n"
|
||||
|
||||
expect "${test_file}:16 vdbg> "
|
||||
send "p a\n"
|
||||
expect "a = Option(none) (?int)"
|
||||
expect "${test_file}:16 vdbg> "
|
||||
send "c\n"
|
||||
|
||||
expect "${test_file}:16 vdbg> "
|
||||
send "p a\n"
|
||||
expect "a = Option(1) (?int)"
|
||||
expect "${test_file}:16 vdbg> "
|
||||
send "c\n"
|
||||
|
||||
expect "${test_file}:12 vdbg> "
|
||||
send "p f\n"
|
||||
expect "f = Test(Test2{}) (main.Test)"
|
||||
expect "${test_file}:12 vdbg> "
|
||||
send "p t\n"
|
||||
expect "t = Option(none) (?&main.Test)"
|
||||
|
||||
expect "${test_file}:12 vdbg> "
|
||||
send "q\n"
|
||||
expect eof
|
28
vlib/v/debug/tests/option.vv
Normal file
28
vlib/v/debug/tests/option.vv
Normal file
@ -0,0 +1,28 @@
|
||||
struct Test2 {}
|
||||
|
||||
struct Test3 {}
|
||||
|
||||
type Test = Test2 | Test3
|
||||
|
||||
fn (f Test) test(t ?Test) {
|
||||
$dbg;
|
||||
}
|
||||
|
||||
fn (f Test) test2(t ?&Test) {
|
||||
$dbg;
|
||||
}
|
||||
|
||||
fn test_int(a ?int) {
|
||||
$dbg;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut a := ?Test(Test2{})
|
||||
a?.test(a)
|
||||
|
||||
test_int(?int(none))
|
||||
test_int(?int(1))
|
||||
|
||||
b := ?&Test(none)
|
||||
a?.test2(b)
|
||||
}
|
@ -4012,14 +4012,21 @@ fn (mut g Gen) debugger_stmt(node ast.DebuggerStmt) {
|
||||
values.write_string('${func}(*(${base_typ}*)${obj.name}.data)}')
|
||||
} else {
|
||||
_, str_method_expects_ptr, _ := cast_sym.str_method_info()
|
||||
deref := if str_method_expects_ptr && !obj.typ.is_ptr() {
|
||||
|
||||
// eprintln(">> ${obj.name} | str expects ptr? ${str_method_expects_ptr} | ptr? ${var_typ.is_ptr()} || auto heap? ${obj.is_auto_heap} | auto deref? ${obj.is_auto_deref}")
|
||||
deref := if var_typ.has_flag(.option) {
|
||||
''
|
||||
} else if str_method_expects_ptr && !obj.typ.is_ptr() {
|
||||
'&'
|
||||
} else if obj.is_auto_heap && var_typ.is_ptr() && str_method_expects_ptr {
|
||||
'*'
|
||||
} else if !obj.is_auto_heap && var_typ.is_ptr() && str_method_expects_ptr {
|
||||
''
|
||||
} else if obj.is_auto_heap && var_typ.is_ptr() {
|
||||
'*'
|
||||
} else if obj.typ.is_ptr() && !obj.is_auto_deref {
|
||||
'&'
|
||||
} else if obj.typ.is_ptr() && obj.is_auto_deref {
|
||||
''
|
||||
} else if obj.is_auto_heap
|
||||
|| (!var_typ.has_flag(.option) && var_typ.is_ptr()) {
|
||||
'*'
|
||||
} else {
|
||||
''
|
||||
|
Loading…
x
Reference in New Issue
Block a user