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

Enforce stricter enum type checks #56

Open
kegsay opened this issue Sep 3, 2024 · 0 comments
Open

Enforce stricter enum type checks #56

kegsay opened this issue Sep 3, 2024 · 0 comments

Comments

@kegsay
Copy link
Contributor

kegsay commented Sep 3, 2024

When helping a colleague fix their usage of Go bindings, I was surprised that the types on enums were so weak as to be practically useless:

type SlidingSyncVersion interface {
	Destroy()
}
type SlidingSyncVersionNone struct {
}

func (e SlidingSyncVersionNone) Destroy() {
}

type SlidingSyncVersionProxy struct {
	Url string
}

func (e SlidingSyncVersionProxy) Destroy() {
	FfiDestroyerString{}.Destroy(e.Url)
}

type SlidingSyncVersionNative struct {
}

func (e SlidingSyncVersionNative) Destroy() {
}

Since the interface is just Destroy(), and most (all?) generated types have said function, it means there's no guidance into using the correct types. We could improve this if the bindings had a private named function e.g:

type SlidingSyncVersion interface {
	Destroy()
	slidingSyncVersion()
}
type SlidingSyncVersionNone struct {
}

func (e SlidingSyncVersionNone) slidingSyncVersion() {}

func (e SlidingSyncVersionNone) Destroy() {
}

type SlidingSyncVersionProxy struct {
	Url string
}

func (e SlidingSyncVersionProxy) slidingSyncVersion() {}

func (e SlidingSyncVersionProxy) Destroy() {
	FfiDestroyerString{}.Destroy(e.Url)
}

type SlidingSyncVersionNative struct {
}

func (e SlidingSyncVersionNative) slidingSyncVersion() {}

func (e SlidingSyncVersionNative) Destroy() {
}

Keeping it private avoids polluting the public API.

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