Fable: function is translate to IIFE in a particular case

Created on 17 Nov 2017  ·  5Comments  ·  Source: fable-compiler/Fable

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

Most helpful comment

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 ☝️

All 5 comments

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!

@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

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 ☝️

@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. 🤦‍♂️

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! 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomcl picture tomcl  ·  26Comments

dbrattli picture dbrattli  ·  54Comments

ncave picture ncave  ·  35Comments

alfonsogarciacaro picture alfonsogarciacaro  ·  26Comments

alfonsogarciacaro picture alfonsogarciacaro  ·  30Comments