Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cgen error on multi return using generic reference #21594

Closed
larpon opened this issue May 29, 2024 · 0 comments · Fixed by #21596
Closed

Cgen error on multi return using generic reference #21594

larpon opened this issue May 29, 2024 · 0 comments · Fixed by #21596
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@larpon
Copy link
Contributor

larpon commented May 29, 2024

Describe the bug

==================
/dev/shm/v_1000/ttt.01HZ2AVGWZ3T09RBVJKJS01YQP.tmp.c:13147: error: cannot convert 'struct main__Asset' to 'struct main__Asset *'
...
==================

Reproduction Steps

module main

pub enum AssetGetStatus {
    ok
    error
}

struct Sound {}

struct Asset {}

pub fn get[T]() (T, AssetGetStatus) {
    $if T is Sound {
        return Sound{}, AssetGetStatus.ok
    } $else $if T is &Asset {
        return &Asset{}, AssetGetStatus.ok
    } $else {
        $compile_error('get[T]: only retreival of Sound and &Asset is currently supported')
    }
    // Should not could be reached:
    return T{}, AssetGetStatus.error
}

fn main() {
    asset, status := get[&Asset]()
    dump(asset)
    dump(status)
}

Expected Behavior

Clean compile and dump output

Current Behavior

==================
/dev/shm/v_1000/ttt.01HZ2AVGWZ3T09RBVJKJS01YQP.tmp.c:13147: error: cannot convert 'struct main__Asset' to 'struct main__Asset *'
...
==================

Possible Solution

The &Asset could be wrapped in a stack-based type, e.g: AssetRef but it is a little cumbersome to work with manual wrapping and unwrapping like that 🙂

Additional Information/Context

No response

V version

V 0.4.6 09eaae5

Environment details (OS name and version, etc.)

Linux, EndeavourOS (rolling, Arch based)

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@larpon larpon added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels May 29, 2024
@spytheman spytheman added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label May 29, 2024
@felipensp felipensp self-assigned this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants