Skip to content

fix: support class instances and typed arrays returned from function calls#201

Merged
cs01 merged 1 commit intomainfrom
fix-class-return-from-function
Mar 11, 2026
Merged

fix: support class instances and typed arrays returned from function calls#201
cs01 merged 1 commit intomainfrom
fix-class-return-from-function

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Functions returning class instances or typed arrays (e.g. KV[]) previously caused segfaults or LLVM errors because the compiler lost type information at the call site.

What was broken:

  • const x = makeObj() where makeObj() returns a class → segfault (field access read wrong memory)
  • const tree = buildTree() with self-referential class fields → segfault on deep member access
  • const pairs = buildPairs(50) returning KV[] → LLVM opt error (ptr vs double type mismatch)

Root cause: The variable allocator and global variable declarations didn't handle call expressions that return class instances or typed arrays — only new and method_call were supported.

Fix:

  • allocateClassInstance now handles call by looking up the function's return type to determine the class name
  • Global variable declarations now detect class and array return types from function calls
  • Added 3 test fixtures covering all crash patterns

@cs01 cs01 merged commit 1a506d4 into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix-class-return-from-function branch March 11, 2026 01:10
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