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

Invalid output code when using a generic type alias to a struct union #914

Closed
Tarmil opened this issue Feb 21, 2018 · 4 comments
Closed
Assignees

Comments

@Tarmil
Copy link
Member

Tarmil commented Feb 21, 2018

This issue appeared recently, I suspect the fix for #906 to be causing it.

    type Result<'T> = Result<'T,string>

    let get() : Result<int>= Ok 42

    let test() =
        match get() with
            | Ok y -> string y
            | _ -> "Error"

The above returns "Error"; without the Result<int> type annotation, it returns "42".

// Faulty output (with type alias annotation)
 HelloWorld.test=function()
 {
  HelloWorld.get();
  return void 0==0?Global.String(void 0):"Error";
 };

// Correct output (without type alias annotation)
 HelloWorld.test=function()
 {
  var m;
  m=HelloWorld.get();
  return m.$==0?Global.String(m.$0):"Error";
 };

(Thanks @cata for reporting this on gitter and working together on a repro!)

@Tarmil
Copy link
Member Author

Tarmil commented Feb 21, 2018

Also to note is that this only happens if the aliased type is a struct.

@Tarmil Tarmil changed the title Invalid output code when using a generic type alias Invalid output code when using a generic type alias to a struct union Feb 21, 2018
Tarmil added a commit that referenced this issue Feb 21, 2018
@Tarmil
Copy link
Member Author

Tarmil commented Feb 21, 2018

Actually this still fails when reverting the #906 fix, so that's not the cause.

@Tarmil Tarmil closed this as completed in fd4b5b9 Feb 22, 2018
@Jand42
Copy link
Member

Jand42 commented Feb 22, 2018

Issue was not all uses of looking at F# types resolved type aliases. For example accessing a struct union is wrapped in an AddressOf case by FCS, and the code ignoring this when it is a local variable was not resolving type aliases.

@cata
Copy link
Contributor

cata commented Feb 22, 2018

@Tarmil - Thanks for fixing this!

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