Skip to content

constructors that return result<> #436

Closed as duplicate
Closed as duplicate

Description

@OmarTawfik

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

Activity

  1. lukewagner commented on Jan 14, 2025

    @lukewagner
    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!

  2. OmarTawfik commented on Jan 17, 2025

    @OmarTawfik
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions