mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
eval: getCaller -> mustCaller
This commit is contained in:
parent
5219fbcbdf
commit
a2635d78b7
17
eval/call.go
17
eval/call.go
|
@ -26,15 +26,22 @@ type Caller interface {
|
|||
Call(ec *EvalCtx, args []Value)
|
||||
}
|
||||
|
||||
func getCaller(v Value) Caller {
|
||||
func mustCaller(v Value) Caller {
|
||||
caller, ok := getCaller(v)
|
||||
if !ok {
|
||||
throw(fmt.Errorf("a %s is not callable", v.Kind()))
|
||||
}
|
||||
return caller
|
||||
}
|
||||
|
||||
func getCaller(v Value) (Caller, bool) {
|
||||
if caller, ok := v.(Caller); ok {
|
||||
return caller
|
||||
return caller, true
|
||||
}
|
||||
if indexer, ok := getIndexer(v); ok {
|
||||
return IndexerCaller{indexer}
|
||||
return IndexerCaller{indexer}, true
|
||||
}
|
||||
throw(fmt.Errorf("a %s is not callable", v.Kind()))
|
||||
panic("unreachable")
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (ec *EvalCtx) PCall(f Caller, args []Value) (ex error) {
|
||||
|
|
|
@ -237,7 +237,7 @@ func (cp *compiler) form(n *parse.Form) Op {
|
|||
headValues := headOp(ec)
|
||||
headMust := ec.must(headValues, "the head of command", p)
|
||||
headMust.mustLen(1)
|
||||
headCaller := getCaller(headValues[0])
|
||||
headCaller := mustCaller(headValues[0])
|
||||
|
||||
// args
|
||||
var args []Value
|
||||
|
|
Loading…
Reference in New Issue
Block a user