diff --git a/compiler/forget/src/Inference/InlineUseMemo.ts b/compiler/forget/src/Inference/InlineUseMemo.ts index 2e6b5b7e80..582c0cfe4c 100644 --- a/compiler/forget/src/Inference/InlineUseMemo.ts +++ b/compiler/forget/src/Inference/InlineUseMemo.ts @@ -100,6 +100,14 @@ export function inlineUseMemo(fn: HIRFunction): void { lambda.loc ); } + + if (body.loweredFunc.params.length > 0) { + CompilerError.invariant( + "Did not expect any arguments to useMemo callback", + body.loc + ); + } + // We know this function is used for useMemo and can prune it later useMemoFunctions.add(lambda.identifier.id); diff --git a/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.expect.md new file mode 100644 index 0000000000..79491f7ea1 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.expect.md @@ -0,0 +1,20 @@ + +## Input + +```javascript +// @inlineUseMemo +function component(a, b) { + let x = useMemo((c) => a, []); + return x; +} + +``` + + +## Error + +``` +[ReactForget] Invariant: Did not expect any arguments to useMemo callback (3:3) +``` + + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.js b/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.js new file mode 100644 index 0000000000..5d4ec61469 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.js @@ -0,0 +1,5 @@ +// @inlineUseMemo +function component(a, b) { + let x = useMemo((c) => a, []); + return x; +}