rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Dynamic import doesn't work with `external` that defines a function

Open anmonteiro opened this issue 1 year ago • 3 comments

#6663 fixed an issue where @module("..") external .. would also emit a static import. But it looks like external + dynamic import isn't very well supported if the external is an arrow. Here's a playground link.

Wondering if that's on purpose or an oversight. Obviously you can extract the arrow to type f = string => unit or something along those lines, but that disables a few optimizations and you can't use attributes such as @unwrap and friends.

anmonteiro avatar Aug 28 '24 04:08 anmonteiro

I guess this is what has been described as a limitation in https://github.com/rescript-lang/rescript-compiler/pull/6664#issuecomment-1976247679

anmonteiro avatar Aug 28 '24 04:08 anmonteiro

I guess this is what has been described as a limitation in #6664 (comment)

Thanks for refreshing my memory. You're right, it's something we didn't implement due to the limitations of our implementation at the time.

mununki avatar Aug 28 '24 04:08 mununki

@mununki to fix this, you can probably attach an attribute to the primitive translation here:

https://github.com/rescript-lang/rescript-compiler/blob/30b38a0aaab27ad4c99f34037b1cc4d61589da8e/jscomp/ml/translcore.ml#L504-L510

that you then use when compiling the lambda

anmonteiro avatar Aug 28 '24 05:08 anmonteiro