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

Ensure nil safety of builtin functions that accept interface or pointer arguments #1870

Open
1 task done
xiaq opened this issue Dec 16, 2024 · 0 comments
Open
1 task done

Comments

@xiaq
Copy link
Member

xiaq commented Dec 16, 2024

What happened, and what did you expect to happen?

#1869 reported an issue where flag:parse doesn't handle nil arguments properly, but there are probably many more builtin functions that need to be fixed and it''s probably quite annoying to fix all of them.

Maybe conversion of Go values to Elvish values should reject nil by default, with some special annotation that allows nil. For example, using a hypothetical annotation syntax:

func f(a vals.List) {
    // this function, when used as an Elvish builtin, doesn't accept nil
}

func g(a @Nilable vals.List) {
    // this function, when used as an Elvish builtin, accepts nil
}

Not quite sure how @Nilable would be implemented with actual Go language features though. One way for this to work syntactically is to define Nilable as a generic wrapper type:

type Nilable[T any] struct {
    Inner T
}

Calling Go functions from Elvish uses reflection, so whether this would work depends on whether we can reliably tell that a runtime concrete type Nilable[T] is actually an instance of Nilable.

Output of "elvish -version"

irrelevant

Code of Conduct

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

No branches or pull requests

1 participant