|
@@ -62,6 +62,10 @@ var (
|
|
|
errMustBeInteger = errors.New("must be integer")
|
|
|
)
|
|
|
|
|
|
+// CallableType should be set from the eval package to the type of
|
|
|
+// eval.Callable. It is not initialized here to avoid creating an import cycle.
|
|
|
+var CallableType reflect.Type
|
|
|
+
|
|
|
// ScanToGo converts an Elvish value, and stores it in the destination of ptr,
|
|
|
// which must be a pointer.
|
|
|
//
|
|
@@ -102,9 +106,10 @@ func ScanToGo(src any, ptr any) error {
|
|
|
return fmt.Errorf("internal bug: need pointer to scan to, got %T", ptr)
|
|
|
}
|
|
|
dstType := ptrType.Elem()
|
|
|
- if dstType.String() == "eval.Callable" && ValueOf(src) == ValueOf(nil) {
|
|
|
- // A Callable option is a special-case that allows assignment from $nil.
|
|
|
- ptr = nil
|
|
|
+ if dstType == CallableType && ValueOf(src) == ValueOf(nil) {
|
|
|
+ // Allow using the nil value of an empty interface (which is the
|
|
|
+ // value of Elvish's $nil) as a Callable.
|
|
|
+ ValueOf(ptr).Elem().Set(reflect.Zero(dstType))
|
|
|
return nil
|
|
|
}
|
|
|
if !TypeOf(src).AssignableTo(dstType) {
|