Skip to content

ability to obtain return type of generic function when it has no dependencies #846

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

Closed
Hejsil opened this issue Mar 20, 2018 · 9 comments
Closed
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Hejsil
Copy link
Contributor

Hejsil commented Mar 20, 2018

test "" {
    var t: @typeOf(@import("std").fmt.parseInt).ReturnType = undefined;
}
zsh: segmentation fault (core dumped)  zig test test.zig
@Hejsil Hejsil added the bug Observed behavior contradicts documented or intended behavior label Mar 20, 2018
@andrewrk
Copy link
Member

I believe this is related to parseInt being a generic function

@Hejsil
Copy link
Contributor Author

Hejsil commented Mar 20, 2018

Oooh ye, that might be it. Tried a few other functions like allocPrint, but ofc, that is also generic.

Here is the bare bones version:

fn a(b: var) void {}

test "" {
    var c : @typeOf(a).ReturnType = undefined;
}

@Hejsil Hejsil changed the title Getting the return type from a function in the standard library causes seg fault. Getting the return type from a generic function causes seg fault. Mar 20, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Mar 21, 2018
@Hejsil
Copy link
Contributor Author

Hejsil commented Apr 28, 2018

@andrewrk Do we mark this as fixed? The compiler doesn't crash on anymore and gives an error message instead.

The real question, if my bare bones example should work or not. After all, void is known, even if b is generic. The compiler just doesn't analyze past b. It's probably a complicated thing to make work, so maybe not.

@andrewrk
Copy link
Member

The real question, if my bare bones example should work or not.

I'm not sure. It's a difficult question that I'm not prepared to address yet. Let's revisit closer to 1.0.0.

@andrewrk andrewrk changed the title Getting the return type from a generic function causes seg fault. unable to obtain return type of generic function even when has no dependencies Aug 27, 2018
@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. and removed bug Observed behavior contradicts documented or intended behavior labels Aug 27, 2018
@andrewrk andrewrk changed the title unable to obtain return type of generic function even when has no dependencies ability to obtain return type of generic function when it has no dependencies Aug 27, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Aug 27, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Nov 21, 2018
@andrewrk
Copy link
Member

andrewrk commented Jul 8, 2019

Possibly related to #2174, but I'm not sure.

@FireFox317
Copy link
Contributor

This would also allow for the proper return types to show up in the generated documentation.

@mitchellh
Copy link
Contributor

I think this is resolved in stage2: #11188

If the return type isn't dependent on generic parameters, it returns the type.

@andrewrk
Copy link
Member

That's correct. The only thing missing to close this issue is to add a behavior test.

@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Aug 24, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Aug 24, 2022
@Vexu
Copy link
Member

Vexu commented Nov 3, 2022

A test for this already exists in test/behavior/type_info.zig:

test "type info: generic function types" {

@Vexu Vexu closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

5 participants