Skip to content

Commit 83865b9

Browse files
committed
fix implementation (fixing a bug surfaced by Python 🙏)
1 parent 4df5fc8 commit 83865b9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Fable.Transforms/FableTransforms.fs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,19 @@ let canInlineArg (com: Compiler) identName value body =
242242
| _ ->
243243
let refCount = countReferencesUntil 2 identName body
244244

245+
// Inlining a plain identifier reference is always safe (it's just a rename),
246+
// regardless of whether the ident is captured in a closure.
247+
let isIdentValue =
248+
match value with
249+
| IdentExpr _ -> true
250+
| _ -> false
251+
245252
// Don't inline even side-effect-free values when they're captured in a closure (e.g. object expression
246253
// getter): inlining would create a new value on each closure invocation instead of sharing one instance.
247-
(refCount <= 1 && not (canHaveSideEffects com value) && not (isIdentCaptured identName body))
254+
// Exception: plain ident values are always safe to inline (they don't create new objects).
255+
(refCount <= 1
256+
&& not (canHaveSideEffects com value)
257+
&& (isIdentValue || not (isIdentCaptured identName body)))
248258
// If it can have side effects, make sure is at least referenced once so the expression is not erased
249259
|| (refCount = 1
250260
&& noSideEffectBeforeIdent identName body

0 commit comments

Comments
 (0)