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

Open
OmarTawfik opened this issue Jan 9, 2025 · 0 comments
Open

constructors that return result<> #436

OmarTawfik opened this issue Jan 9, 2025 · 0 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

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