Skip to content

[BUG] wrong return value from async function #280

@aj3423

Description

@aj3423

Describe the bug
The code below produces wrong result.

To Reproduce
Steps to reproduce the behavior:

  1. code:
async fn fetch_data() -> string {
    return "some data";
}

fn main() {
    let result = await fetch_data();
    
    println "result: {result}";
    return 0;
}

It shows:

result: @

Expected behavior
It shows wrong result:

result: some data

Screenshots

Environment (please complete the following information):

  • OS: Fedore 43
  • Zen C Version: zc v0.4.2-38-ge4605ce
  • Compiler:
    • gcc (GCC) 15.2.1 20260123
    • clang version 21.1.8

Additional context
A discussion in discord, from Alex:

There's a bug in the compiler.
It outputs

    string *res_ptr = malloc(sizeof(string));
    *res_ptr = _impl_fetch_data();
    free(args);
    return (void*)res_ptr; //<----- cast char** to void*
}

It should be outputting

    string res_ptr = malloc(sizeof(string));
    res_ptr = _impl_fetch_data();
    free(args);
    return (void*)res_ptr; //<---- cast char* to void*

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions