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

type error: unable to call method on type (check pointer receiver) #305

Open
SolarLune opened this issue Jan 7, 2025 · 0 comments
Open

Comments

@SolarLune
Copy link

SolarLune commented Jan 7, 2025

Hello - I'm sure this is already a known issue, but I don't see any active issues about this. It's currently impossible to set a value or call a method on a non-pointer struct. That's a bit of a problem if you're working with an external Golang library that doesn't directly deal with pointers; not sure if there's anything that can be done about this.

For example, the following is impossible:

package main

import (
	"context"
	"fmt"

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

type Object struct {
	A int
}

func (o Object) Set(other Object) Object {
	o.A = other.A
	return o
}

type Creator struct{}

func (c *Creator) NewObject() Object {
	return Object{}
}

func main() {

	src := `
	obj := Creator.NewObject()
	obj2 := Creator.NewObject()
	obj3 := obj.Set(obj2)
	`

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

}
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

1 participant