Skip to content

Fix generalization of call-argument lambdas causing type errors#9243

Open
Anton-4 wants to merge 2 commits intomainfrom
fix-unexpected-type-mismatch
Open

Fix generalization of call-argument lambdas causing type errors#9243
Anton-4 wants to merge 2 commits intomainfrom
fix-unexpected-type-mismatch

Conversation

@Anton-4
Copy link
Collaborator

@Anton-4 Anton-4 commented Mar 6, 2026

See https://roc.zulipchat.com/#narrow/channel/231634-beginners/topic/Unexpected.20type.20mismatch.20with.20parameterised.20function/near/577730388

Lambdas passed as call arguments (e.g. list.fold_rev(dest, |item, acc| ...))
were independently generalized at an inner rank, setting their type vars to
rank 0. When those vars were then unified with outer scope vars via Rank.min
in merge, the outer vars were pulled to rank 0, preventing the enclosing
function from generalizing. This caused spurious TYPE MISMATCH errors when
a polymorphic function with nested lambdas was tested from within its own
module (via expect), while working correctly from external modules.

Skip generalization for standalone lambdas that are direct call arguments,
since they are consumed immediately and don't need independent generalization.
Their type vars remain at the enclosing scope's rank and generalize together
with the enclosing function.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Anton-4 and others added 2 commits March 6, 2026 19:30
Lambdas passed as call arguments (e.g. `list.fold_rev(dest, |item, acc| ...)`)
were independently generalized at an inner rank, setting their type vars to
rank 0. When those vars were then unified with outer scope vars via Rank.min
in merge, the outer vars were pulled to rank 0, preventing the enclosing
function from generalizing. This caused spurious TYPE MISMATCH errors when
a polymorphic function with nested lambdas was tested from within its own
module (via expect), while working correctly from external modules.

Skip generalization for standalone lambdas that are direct call arguments,
since they are consumed immediately and don't need independent generalization.
Their type vars remain at the enclosing scope's rank and generalize together
with the enclosing function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The existing test only covered cross-module usage (importing the function).
Add an expect inside the module itself and a CLI test that runs `roc test`
on it, covering the case that was previously broken.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant