Skip to content

expr.WithContext with nested struct member method #756

@echoface

Description

@echoface
type X struct {}
func (x *X) HelloCtx(ctx context.Context, text string) error {
    fmt.Println("hello:", text)
    return nil
}

Convey("test goexr engine", t, func() {
    env := map[string]any{
        "_goctx_": context.TODO(),
        "_g_": map[string]*X{
            "rpc": &X{},
        },
        "text":    "gonghuan",
    }
    exprStr := `
        let v = _g_.rpc.HelloCtx(_goctx_, text);
   `
    program, err := expr.Compile(exprStr, expr.Env(env), expr.WithContext("_goctx_"))
    So(err, ShouldBeNil)
    _, err := expr.Run(program, env)
    So(err, ShouldBeNil)
})

it will fail call HelloCtx with

    Expected: nil
    Actual:   'reflect: Call with too few input arguments (3:20)
          |    let v = _g_.rpc.HelloCtx(text);

but if level up "rpc" to env map like this:

// this is ok
env := map[string]any{
        "_goctx_": context.TODO(),
        "_g_":  &X{},
        "text":    "gonghuan",
    }

// wrong

env := map[string]any{
        "_goctx_": context.TODO(),
        "_g_": map[string]*X{
            "rpc": &X{},
        },
        "text":    "gonghuan",
    }

is seems like a bug? help pls...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions