-
Notifications
You must be signed in to change notification settings - Fork 292
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
Local Function Name Clashes with Global JavaScript Functions Leading to Incorrect Behavior #3775
Comments
A workaround is to use open Browser
open Browser
let clearTimeout () =
None
|> Option.iter window.clearTimeout It will generates: import { iterate } from "fable-library-js/Seq.js";
import { toArray } from "fable-library-js/Option.js";
export function clearTimeout() {
iterate((handle) => {
window.clearTimeout(handle);
}, toArray(void 0));
} You could also create a local alias to the function: open Browser
let jsClearTimeout = Fable.Core.JS.clearTimeout
let inline jsClearTimeoutInlined delay = Fable.Core.JS.clearTimeout delay
let clearTimeout () =
None
|> Option.iter jsClearTimeout
let clearTimeout2 () =
None
|> Option.iter jsClearTimeoutInlined I think current Fable mechanism for detecting name clashing don't catch this situation because Fable/src/Fable.Core/Fable.Core.JS.fs Lines 771 to 775 in c287b15
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
When defining a local F# function in a Fable project with a name that matches a global JavaScript function (e.g.,
setTimeout
,clearTimeout
), Fable always references the local function, even in contexts where the global JavaScript function is intended to be used. This behavior can lead to unexpected errors, such as "RangeError: Maximum call stack size exceeded", due to recursive calls when the local function tries to use the global one indirectly.Repro code:
Expected and actual results:
Expected: The
clearTimeout
call within the localclearTimeout
function should reference the global JavaScriptclearTimeout
function, allowing for the proper clearing of timeouts set withsetTimeout
.Actual: The local
clearTimeout
function is recursively calling itself instead of the global JavaScriptclearTimeout
, leading to a "RangeError: Maximum call stack size exceeded" error.Suggested Solution:
It might be beneficial for Fable to provide clearer warnings or errors during compilation when local function names shadow global JavaScript functions, or potentially offer a way to explicitly reference global functions in such cases.
Related information:
The text was updated successfully, but these errors were encountered: