fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.93k stars 301 forks source link

importValueDynamic fails to import some functions #3919

Open joprice opened 1 month ago

joprice commented 1 month ago

Description

importValueDynamic fails at either runtime or compile time for functions with more than a single argument.

Repro code

I reproduced in a separate repository, since it requires multiple files:

https://github.com/joprice/fable-repro/blob/435dff0128f35b968b49d89efbd0ced9fbe85e2f/Program.fs#L12

Expected and actual results

With the following definitions,

let x (a: int) = 1
let y (a: int, b: string) = 2
let z (a: int) (b: string) = 3

The first succeeds

let! x = importValueDynamic Client.x
x (1)

The second fails at compile time with

./Program.fs(10,17): (10,44) error FABLE: The imported value is not coming from a different file
let! y = importValueDynamic Client.y
y (1, "a")

The third fails at runtime with

TypeError: z(...) is not a function"
let! z = importValueDynamic Client.z
z 1 "a"

In the case of the dynamic failure, I would expect any public value to be able to be imported and have the call semantics line up (e.g. not try to call a multiple arity function as a curried function).

In the case of the static failure, I wonder if the inliner is getting in the way, so that the value is detected as being from the same file?

Related information