EvalVariable should also evaluate package variables
This commit is contained in:
parent
fd08e96b24
commit
fe054b2f0f
@ -57,9 +57,11 @@ func foobar(baz string, bar FooBar) {
|
||||
)
|
||||
|
||||
barfoo()
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, b1, b2, baz, neg, i8, u8, u16, u32, u64, up, f32, c64, c128, i32, bar, f, ms, ba)
|
||||
fmt.Println(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, b1, b2, baz, neg, i8, u8, u16, u32, u64, up, f32, c64, c128, i32, bar, f, ms, ba, p1)
|
||||
}
|
||||
|
||||
var p1 = 10
|
||||
|
||||
func main() {
|
||||
foobar("bazburzum", FooBar{Baz: 10, Bur: "lorem"})
|
||||
}
|
||||
|
||||
@ -240,6 +240,20 @@ func (thread *Thread) EvalVariable(name string) (*Variable, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to evaluate name as a package variable.
|
||||
if memberName != "" {
|
||||
return thread.EvalPackageVariable(name)
|
||||
} else {
|
||||
loc, err := thread.Location()
|
||||
if err == nil && loc.Fn != nil {
|
||||
v, err := thread.EvalPackageVariable(loc.Fn.PackageName() + "." + name)
|
||||
if err == nil {
|
||||
v.Name = name
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("could not find symbol value for %s", name)
|
||||
}
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@ func assertVariable(t *testing.T, variable *Variable, expected varTest) {
|
||||
}
|
||||
|
||||
if variable.Type != expected.varType {
|
||||
t.Fatalf("Expected %s got %s\n", expected.varType, variable.Type)
|
||||
t.Fatalf("Expected %s got %s (for variable %s)\n", expected.varType, variable.Type, expected.name)
|
||||
}
|
||||
|
||||
if variable.Value != expected.value {
|
||||
t.Fatalf("Expected %#v got %#v\n", expected.value, variable.Value)
|
||||
t.Fatalf("Expected %#v got %#v (for variable %s)\n", expected.value, variable.Value, expected.name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +68,8 @@ func TestVariableEvaluation(t *testing.T) {
|
||||
{"f", "main.barfoo", "func()", nil},
|
||||
{"ba", "[]int len: 200, cap: 200, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+136 more]", "struct []int", nil},
|
||||
{"ms", "main.Nest {Level: 0, Nest: *main.Nest {Level: 1, Nest: *main.Nest {...}}}", "main.Nest", nil},
|
||||
{"main.p1", "10", "int", nil},
|
||||
{"p1", "10", "int", nil},
|
||||
{"NonExistent", "", "", fmt.Errorf("could not find symbol value for NonExistent")},
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user