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

Support optional types #246

Closed
3 of 5 tasks
Tracked by #534
Manishearth opened this issue Aug 31, 2022 · 3 comments · Fixed by #632
Closed
3 of 5 tasks
Tracked by #534

Support optional types #246

Manishearth opened this issue Aug 31, 2022 · 3 comments · Fixed by #632
Assignees
Labels
enhancement New feature or request

Comments

@Manishearth
Copy link
Contributor

Manishearth commented Aug 31, 2022

We support optional opaques, but we do not support optional primitives and structs. We should; exposing it as std::optional in C++ and

We will likely want to do the same thing as #245 where it's automatic when found in parameters, though we will have to require people to use DiplomatOption in struct types.

We could also make it so that you can force opaques into optionals if you really want (currently opaque+optional = nullable opaque)

Status:

I shall consider this issue fixed when Dart, C, and CPP have landed.

@robertbastian
Copy link
Collaborator

#132

@robertbastian robertbastian closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@Manishearth
Copy link
Contributor Author

I'm going to reopen this, #132 only added them in return types. I'd like these to be supported everywhere.

This reduces the need for #247

@Manishearth
Copy link
Contributor Author

What I'm going to try and do is make it so that:

(assume T is not a pointer type)

  • DiplomatOption<T> = DiplomatResult<T, ()>
  • Option<T> or DiplomatOption<T> in a return type returns a result type, akin to the current behavior of -> Option<T>
  • Option<Ptr> always is a nullable pointer, in any position (as it is now)
  • DiplomatOption<Ptr> is forbidden
  • Option<T> in param lists is autoconverted to DiplomatOption<T>
  • Option<T> in struct fields is an error.

This means that some mixing of the two will magically work but in cases where the distinction matters you have to use the right type. We can document that.

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

Successfully merging a pull request may close this issue.

2 participants