Skip to content

[Type Error] Null | Type must be cast after a conditional return #456

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

Closed
willemneal opened this issue Feb 3, 2019 · 1 comment
Closed

Comments

@willemneal
Copy link
Contributor

Here is the working example: https://webassembly.studio/?f=zi21djvj57

Consider this example

function orNull(i: i32): Foo | null {
  if (i % 2 == 0)
  return null;
  return new Foo();
}

function example(): Foo | null {
  let x: Foo | null = orNull(1);
  if (x == null){
    return null;
  }
  return id(x); // x is not null, but compiler requires an explicit cast.
}

function id(f: Foo): Foo{
  return f;
}

Not sure how big of a problem this is since it might be better to enforce being explicit, but I thought I'd share it. Also the same is true for if/else branches.

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closing this issue as part of 2020 vacuum because this seems to be fixed meanwhile by extending null checks, at least when using ===, with everything further being tracked in the respective issues dealing with changing the semantics of triple equals.

@dcodeIO dcodeIO closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants