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

Erased union pattern matching fails on a union with a [<Constant null>] case #948

Closed
Tarmil opened this issue May 10, 2018 · 1 comment
Closed
Assignees

Comments

@Tarmil
Copy link
Member

Tarmil commented May 10, 2018

The following:

type MyType =
    | [<Constant(null)>] NullCase
    | NonNullCase

let f (x: Union<Dom.Node, MyType>) =
    match x with
    | Union1Of2 _ -> "it's not my type"
    | Union2Of2 _ -> "it's my type"

compiles to this:

f=function(x)
 {
  return x.constructor===Global.Object?"it's my type":"it's not my type";
 };

The problem is that if we call f (Union2Of2 NullCase), then x is null and the access to .constructor fails.

This issue causes crashes in WebSharper.UI here.

@Tarmil
Copy link
Member Author

Tarmil commented May 11, 2018

Fixed the example -- this happens with Union<_, MyType>, not with Union<MyType, _> as I originally posted.

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

2 participants