Browse Source

Fixed toReflectType(interface{}) (should do Export() rather than return the original Value)

Dmitry Panov 5 years ago
parent
commit
b622c6a4ca
2 changed files with 19 additions and 2 deletions
  1. 2 2
      runtime.go
  2. 17 0
      runtime_test.go

+ 2 - 2
runtime.go

@@ -1480,11 +1480,11 @@ func (r *Runtime) toReflectValue(v Value, typ reflect.Type) (reflect.Value, erro
 		}
 	}
 
-	if typeValue.AssignableTo(typ) {
+	if typ == typeValue {
 		return reflect.ValueOf(v), nil
 	}
 
-	if typeObject.AssignableTo(typ) {
+	if typ == typeObject {
 		if obj, ok := v.(*Object); ok {
 			return reflect.ValueOf(obj), nil
 		}

+ 17 - 0
runtime_test.go

@@ -752,6 +752,23 @@ func TestToValueFloat(t *testing.T) {
 	}
 }
 
+func TestToValueInterface(t *testing.T) {
+
+	f := func(i interface{}) bool {
+		return i == t
+	}
+	vm := New()
+	vm.Set("f", f)
+	vm.Set("t", t)
+	v, err := vm.RunString(`f(t)`)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if v != valueTrue {
+		t.Fatalf("v: %v", v)
+	}
+}
+
 func TestJSONEscape(t *testing.T) {
 	const SCRIPT = `
 	var a = "\\+1";