fix(resolve): rewrite lambda signature types when merging modules - #889
Merged
Merged
Conversation
The stdlib rename pass rewrites every type annotation to its merged, mangled module name so references resolve after packages are combined. The lambda arm rewrote only the body, leaving parameter and return type annotations pointing at the bare, now unmapped name. In package mode a closure whose parameter or return type named a module type then failed resolution with "cannot find `T` in scope", even though the same type resolved as a plain parameter, return, or let annotation. Single-file builds were unaffected because they do not run the merge pass. Because closure parameters must be annotated, this blocked every higher-order library API over a named type (iterator callbacks, event handlers, row mappers). Rewrite the lambda parameter and return type annotations with the full rename map, exactly as rewrite_fn does for a named function, and add a regression test covering a lambda whose parameter and return type come from a merged module.
martian56
force-pushed
the
agent/fix-lambda-signature-types
branch
from
July 14, 2026 15:20
1b46f70 to
9ee515b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A named type used as a closure parameter or return type fails name resolution with
cannot find \T` in scopewhen a project is built throughrvpm(package mode), even though the exact same type resolves correctly as a plain function parameter, a return type, or aletannotation. Single-fileraven build` is unaffected.Because Raven requires closure parameters to be annotated (there is no inference for them), this blocks every higher-order library API expressed over a named type: iterator callbacks, event handlers, ORM row mappers, and so on. A consumer simply cannot write
fun(x: SomeType) -> SomeTypewhen building through rvpm.Minimal reproduction (package mode)
let h: Handler = ...andfun helper(h: Handler)in the same file resolve fine; only the closure signature fails.Root cause
The stdlib expansion pass merges modules and rewrites every type annotation to its mangled, module-qualified name via
rewrite_type.rewrite_fndoes this for named-function parameter and return types,rewrite_stmtdoes it forletannotations, and struct/enum/const/impl are all covered. Therewrite_exprExprKind::Lambdaarm rewrote only the lambda body, never its parameter or return type annotations, so those kept the bare name that no longer exists in the merged module scope.Fix
Rewrite the lambda parameter and return type annotations with the full rename map in the
ExprKind::Lambdaarm, mirroringrewrite_fn. Value parameters still shadow only globals in the body, so the annotations correctly use the unshadowed map.Tests
lambda_parameter_type_from_merged_module_resolvesinsrc/resolve/stdlib.rs: a lambda whose parameter and return type come from a merged module now expands, resolves, type-checks, and lowers.Summary by CodeRabbit