Skip to content

Non nullable externref are not supported #299

Description

@ottoville

Bug report

I am trying to describe js builtins cast function in rust, the function is defined:

func cast(
  string: externref
) -> (ref extern) {
  // Technically a partially redundant test, but want to be clear the null is
  // not allowed.
  if (string === null ||
      typeof string !== "string")
    trap();

  return string;
}

The function takes externref as input, which can be done with this crane. But the return value is "ref extern", it is an externref that is non nullable. Currently this crane preprocessor cant create a code that has correct return signature for this function, "ref extern" types are not supported. So this code will have error in the runtime when compiling the wasm

#[externref::externref]
#[link(wasm_import_module = "wasm:js-string")]
unsafe extern "C" {
    fn cast(string: &Resource<()>) -> Resource<()>;
}

To support this, all Resource types should carry information if they are nullable, or preprocessor should create wasm code with logic something like this

Option<Resource> -> externref
Resource -> ref extern

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions