mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
proc: return error when assigning between function variables (#2692)
Fixes #2691
This commit is contained in:
committed by
GitHub
parent
1893c9769b
commit
bdcbcc6836
@ -383,6 +383,13 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error {
|
||||
real, _ := constant.Float64Val(constant.Real(srcv.Value))
|
||||
imag, _ := constant.Float64Val(constant.Imag(srcv.Value))
|
||||
return dstv.writeComplex(real, imag, dstv.RealType.Size())
|
||||
case reflect.Func:
|
||||
if dstv.RealType.Size() == 0 {
|
||||
if dstv.Name != "" {
|
||||
return fmt.Errorf("can not assign to %s", dstv.Name)
|
||||
}
|
||||
return errors.New("can not assign to function expression")
|
||||
}
|
||||
}
|
||||
|
||||
// nilling nillable variables
|
||||
|
||||
@ -5681,3 +5681,18 @@ func TestWatchpointStackBackwardsOutOfScope(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetOnFunctions(t *testing.T) {
|
||||
// The set command between function variables should fail with an error
|
||||
// Issue #2691
|
||||
withTestProcess("goroutinestackprog", t, func(p *proc.Target, fixture protest.Fixture) {
|
||||
setFunctionBreakpoint(p, t, "main.main")
|
||||
assertNoError(p.Continue(), t, "Continue()")
|
||||
scope, err := proc.GoroutineScope(p, p.CurrentThread())
|
||||
assertNoError(err, t, "GoroutineScope")
|
||||
err = scope.SetVariable("main.func1", "main.func2")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when assigning between function variables")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user