Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to call Go methods with nil as an argument #309

Open
SolarLune opened this issue Jan 9, 2025 · 1 comment
Open

Impossible to call Go methods with nil as an argument #309

SolarLune opened this issue Jan 9, 2025 · 1 comment

Comments

@SolarLune
Copy link

It's impossible currently to call a Go function and use nil as an argument, even if the argument to the function in Go takes any or a pointer as an argument (so places where a nil should be accepted grammatically).

For example, this gives the error panic: reflect: Call using zero Value argument:

package main

import (
	"context"
	"fmt"

	"github.com/risor-io/risor"
)

type A struct{}

func (a *A) Test(arg any) {}

func main() {

	src := `A.Test(nil)`

	_, err := risor.Eval(context.Background(), src, risor.WithGlobal("A", &A{}))
	fmt.Println(err)

}
@SolarLune SolarLune changed the title Impossible to call Go code with nil Impossible to call Go methods with nil as an argument Jan 9, 2025
@dnbsd
Copy link

dnbsd commented Jan 18, 2025

I think A has to implement object.Module to be able to use it as you do. Look inside the modules directory how the existing modules expose their methods to get a better idea how to write your own modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants