Skip to content

Commit

Permalink
starlark: if a built-in Callable defines Position method, use it (goo…
Browse files Browse the repository at this point in the history
…gle#49)

...when printing a frame or backtrace.

This is more of a low-risk usability hack than a specified feature at
this point. I don't think it warrants a (breaking) change to the
Callable interface.
  • Loading branch information
adonovan authored Dec 7, 2018
1 parent d1cdecf commit 4a64267
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions starlark/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ func (fr *Frame) Position() syntax.Position {
if fr.posn.IsValid() {
return fr.posn // leaf frame only (the error)
}
if fn, ok := fr.callable.(*Function); ok {
return fn.funcode.Position(fr.callpc) // position of active call
switch c := fr.callable.(type) {
case *Function:
// Starlark function
return c.funcode.Position(fr.callpc) // position of active call
case interface{ Position() syntax.Position }:
// If a built-in Callable defines
// a Position method, use it.
return c.Position()
}
return syntax.MakePosition(&builtinFilename, 1, 0)
}
Expand Down

0 comments on commit 4a64267

Please sign in to comment.