Skip to content

Fix Edit Lambda for calls with omitted arguments#174

Open
jimmytacks wants to merge 1 commit into
mainfrom
issue-151-edit-lambda-omitted-args
Open

Fix Edit Lambda for calls with omitted arguments#174
jimmytacks wants to merge 1 commit into
mainfrom
issue-151-edit-lambda-omitted-args

Conversation

@jimmytacks
Copy link
Copy Markdown
Collaborator

Closes #151.

Summary

When Edit Lambda expanded a call like =EXPLODE(A1) where the LAMBDA declared more parameters (text, [chunk_size], [horizontal]) than the caller supplied, the omitted parameters were left as free references inside the body — making the generated LET invalid.

The fix:

  • Detect the canonical IF(ISOMITTED(p), default, p) wrapper anywhere in the LAMBDA body for each omitted parameter p. Extract default and bind p, default at the top of the LET. Replace the IF wrapper with a bare p so the LET stays clean and round-trips through LET to LAMBDA without re-adding the wrapper unless the user re-checks "Optional".
  • If no pattern is found for an omitted parameter (hand-written LAMBDA without the canonical pattern, or a missing required arg), fall back to binding p, "" so the LET is at least valid and the hole is visible to the author.
  • Standalone ISOMITTED(p) references not wrapped in the IF pattern (e.g. Help?, ISOMITTED(text)) are left alone — when the param is provided in the call, ISOMITTED evaluates to FALSE on the bound name, which is the right semantics.
  • The spec-0002 LetToLambdaBuilder wraps optional params as a LET binding named after the param (e.g. y, IF(ISOMITTED(y), 10, y)). After stripping, that becomes y, y — a no-op shadow of the outer binding. Drop those during flattening to keep the output clean.

Test plan

  • dotnet build addin/lambda-boss.slnx clean (0 errors)
  • dotnet test addin/lambda-boss.Tests/lambda-boss.Tests.csproj — 827/827 passing
  • Added new tests covering: omitted optional with extracted default, multiple omitted optionals, default expressions containing nested commas, omitted optional inside an inner LET, standalone ISOMITTED on a provided param (not rewritten), IF(ISOMITTED) appearing inside a string literal (not rewritten), spec-0002 round-trip with the y, y shadow dropped, and missing-arg fallback to "".
  • Manual smoke test in Excel against EXPLODE: call =EXPLODE(A1) then run /Edit Lambda — the produced LET should bind chunk_size, 1 and horizontal, FALSE with the IF wrappers stripped from _size/_horiz.

🤖 Generated with Claude Code

When the LAMBDA call provided fewer args than the LAMBDA declared, the
generated LET referenced free parameter names (e.g. `chunk_size`,
`horizontal` inside EXPLODE's body) and was invalid. Bind each omitted
parameter at the top of the LET to a default extracted from the
canonical `IF(ISOMITTED(p), default, p)` wrapper in the body, then
strip the wrapper to a bare `p` so the LET round-trips cleanly through
LET to LAMBDA. When no pattern is detected, fall back to `""` as a
visible placeholder. Drop the no-op `p, p` shadow that the spec-0002
LetToLambdaBuilder leaves behind after the wrapper is removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jimmytacks jimmytacks force-pushed the issue-151-edit-lambda-omitted-args branch from 4a97d60 to a8d8a6b Compare May 12, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edit Lambda doesn't deal correctly with omitted arguments

1 participant