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

constructors that return result<> #436

Closed
OmarTawfik opened this issue Jan 9, 2025 · 2 comments
Closed

constructors that return result<> #436

OmarTawfik opened this issue Jan 9, 2025 · 2 comments

Comments

@OmarTawfik
Copy link

Today, the following syntax is illegal, since constructors have no return types:

resource blob {
    constructor(data: list<u8>) -> result<blob, error-type>;
}

However, this is a perfectly valid use case for languages like JS and C++, as result<> return type are lowered into blob directly, using exceptions to propagate error-type values if they occur. This is what happens already with normal methods that return result<>.

Thoughts? I wonder if it is possible to enable this use case. Without it, APIs are forced to use alternative static methods like create: static func(), which is not standard, and hurts readability/discoverability.

Moved from bytecodealliance/wit-bindgen#1114

@lukewagner
Copy link
Member

Totally agreed; we should definitely do this. I believe #285 makes this same point, so perhaps we can dup this to that?

Spec-wise, the change is very simple; we just relax the validation rules for [constructor]...-named functions to also allow result. Most of the work would be in wit-bindgen and related tools. Let me know if anyone is keen to work on this!

@OmarTawfik
Copy link
Author

Thank you. I missed #285. I can close this one as a dup.

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