diff --git a/compiler/forget/src/Inference/InferReferenceEffects.ts b/compiler/forget/src/Inference/InferReferenceEffects.ts index fb379f1d2b..1f851f5530 100644 --- a/compiler/forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/forget/src/Inference/InferReferenceEffects.ts @@ -308,7 +308,8 @@ class InferenceState { case Effect.Capture: { if ( valueKind === ValueKind.Frozen || - valueKind === ValueKind.MaybeFrozen + valueKind === ValueKind.MaybeFrozen || + valueKind === ValueKind.Immutable ) { effect = Effect.Read; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/destructure-capture-global.expect.md b/compiler/forget/src/__tests__/fixtures/hir/destructure-capture-global.expect.md index 499ebec08f..9f0d022a43 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/destructure-capture-global.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/destructure-capture-global.expect.md @@ -15,18 +15,15 @@ function component(a) { ```javascript let someGlobal = {}; function component(a) { - const $ = React.unstable_useMemoCache(3); - const t0 = someGlobal; + const $ = React.unstable_useMemoCache(2); const c_0 = $[0] !== a; - const c_1 = $[1] !== t0; let x; - if (c_0 || c_1) { - x = { a: a, someGlobal: t0 }; + if (c_0) { + x = { a: a, someGlobal: someGlobal }; $[0] = a; - $[1] = t0; - $[2] = x; + $[1] = x; } else { - x = $[2]; + x = $[1]; } return x; }