debug: fix variable dereferencing (#20594)

This commit is contained in:
Felipe Pena 2024-01-21 02:53:30 -03:00 committed by GitHub
parent 9d048792fe
commit 135e2f1cc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 101 additions and 4 deletions

View 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

View 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)
}

View 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

View 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)
}

View File

@ -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 {
''