fable-compiler / Fable

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

Delegate parameter is invoked when it shouldn't be #3862

Closed Preston159 closed 4 months ago

Preston159 commented 4 months ago

Description

When a function takes another function as a parameter, which in turn takes a function as a parameter, and attempts to call that function by passing in a function, Fable incorrectly calls the innermost function and passes in its return value rather than passing the function itself.

Repro code

REPL

Expected and actual results

Expected console output

Actual console output

Related information

ncave commented 4 months ago

@Preston159 This seems to only affect delegates, as changing the type from

type DelegateType = delegate of unit -> unit

to

type DelegateType = unit -> unit

, and the call site from del.Invoke () to del () works as expected.

Not a fix, obviously, just a workaround if using delegates is not critical.

ncave commented 4 months ago

@Preston159 Thanks for reporting the issue, should be resolved in the next release.

Preston159 commented 4 months ago

@ncave Happy to help. Thanks for the quick resolution, both the workaround and the fix!

OnurGumus commented 1 month ago

I think this change caused some regressions. Trying to come up with a repro case.

OnurGumus commented 1 month ago

@ncave

ncave commented 1 month ago

@OnurGumus Perhaps, let me know if you can find an example. The original code was done to resolve #2400.

OnurGumus commented 1 month ago

@ncave Hi, I reproduced the problem with minimal example and created issue. It's not related to this bug I think.

https://github.com/fable-compiler/Fable/issues/3915