Skip to content

fix: propagate arrow function return types and fix lambda pointer codegen#237

Merged
cs01 merged 2 commits intomainfrom
fix-closure-return-codegen
Mar 11, 2026
Merged

fix: propagate arrow function return types and fix lambda pointer codegen#237
cs01 merged 2 commits intomainfrom
fix-closure-return-codegen

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Summary

  • Arrow functions with explicit return type annotations (e.g., (): string => { ... }) now propagate the return type through the codegen pipeline
  • Parser extracts return type from arrow function declarations and stores in ArrowFunctionNode.returnType
  • inferReturnTypeFromBody now handles binary string concat in return statements
  • Closure calls use correct return type instead of hardcoded double — string-returning closures now call with i8* return type
  • Return statements properly bitcast lambda function pointers to i8* instead of emitting bare function names

Previously, return (): string => { return "hello"; } would emit ret i8* __lambda_0 (invalid LLVM IR — missing @ prefix and type mismatch). Now emits proper bitcast.

Test plan

  • npm run verify:quick passes (tests + self-hosting Stage 1)
  • No regressions in existing closure tests

@cs01 cs01 force-pushed the fix-closure-return-codegen branch from 8d8a294 to e94fa4c Compare March 11, 2026 18:32
@cs01 cs01 merged commit 975fc9d into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix-closure-return-codegen branch March 12, 2026 05:34
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