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

function is translate to IIFE in a particular case #1234

Closed
zaaack opened this issue Nov 17, 2017 · 5 comments
Closed

function is translate to IIFE in a particular case #1234

zaaack opened this issue Nov 17, 2017 · 5 comments

Comments

@zaaack
Copy link
Contributor

zaaack commented Nov 17, 2017

Description

A function is translate to IIFE and cause f is not function error

Repro code

repl

import { createAtom } from "fable-core/Util";
import { getValue, defaultArg } from "fable-core/Option";
import { printf } from "fable-core/String";
export let lastModel = createAtom(null);
export const hasUpdate = defaultArg(defaultArg(lastModel(), null, function (a) {
  return !(1 === a);
})/* function */, true);
replLog(printf("%A"))(hasUpdate);
let setInternalState = createAtom(null);
export function withReact() {
  let lastModel_1 = null;

  const setState_1 = function () {
    if (setInternalState() == null) {
      throw new Error("withReact init failed.");
    } else {
      const setState = getValue(setInternalState());
      const hasUpdate_1 = defaultArg(defaultArg(lastModel_1, null, function (a) {
        return !(1 === a);
      }())/* IIFE */, true);
      replLog(printf("%A"))(hasUpdate_1);
    }
  };

  setState_1();
}

Expected and actual results

Function should alway be a function. :)

Related information

  • Fable version (dotnet fable --version):1.3.0
  • Operating system: macOS sierra
@alfonsogarciacaro
Copy link
Member

The linked code is working with latest REPL (based on Fable 1.3), can you please check again if it works with CLI version? Thanks!

@zaaack
Copy link
Contributor Author

zaaack commented Nov 19, 2017

@alfonsogarciacaro The linked code is not working, the generated code might not easy to read... I can confirm it's the same in dotnet-fable 1.3 with fable-splitter.

image

Here is the example that would cause f is not a function error: repl link

@alfonsogarciacaro
Copy link
Member

Ah, thanks! I got indeed confused by the code 😅 Interestingly the problem here was the inline local function. If you remove inline from notEqual it will work. In any case hopefully the problem should have been fixed with the commit linked above ☝️

@zaaack
Copy link
Contributor Author

zaaack commented Nov 19, 2017

@alfonsogarciacaro Thanks for your quick fix! Sorry that I should describe it more clear at first time, this problem makes me a little confused at that time. 🤦‍♂️

@alfonsogarciacaro
Copy link
Member

No worries, I know sometimes it's difficult to isolate the problem, but it does help a lot to have code without dependencies to reproduce the issue, thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants