Skip to content

[BUG] Can't declare variable/parameter of type pointer to function #718

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
ntrel opened this issue Oct 2, 2023 · 4 comments · Fixed by #1183
Closed

[BUG] Can't declare variable/parameter of type pointer to function #718

ntrel opened this issue Oct 2, 2023 · 4 comments · Fixed by #1183
Labels
bug Something isn't working

Comments

@ntrel
Copy link
Contributor

ntrel commented Oct 2, 2023

Describe the bug
cppfront errors when attempting to do this.

To Reproduce

f: (a: *() -> int) = {}
callback.cpp2(3,9): error: '*'/'const' type qualifiers must be followed by a type name or '_' wildcard (at '(')

Using a type alias also fails:

F: type == () -> int;
f: (a: *F) = {}
callback.cpp2(1,13): error: a 'type ==' alias declaration must be followed by a type name
@ntrel ntrel added the bug Something isn't working label Oct 2, 2023
@JohelEGP
Copy link
Contributor

JohelEGP commented Oct 2, 2023

This is #711 and #343.

@ntrel
Copy link
Contributor Author

ntrel commented Oct 2, 2023

Those use std::function, a template type, whereas this is about parsing a pointer to function type. Though it looks like #526 would fix this too.

@JohelEGP
Copy link
Contributor

JohelEGP commented Oct 2, 2023

They're all about being able to name function types.
To name a pointer to function type,
you need to name a function type.

@hsutter
Copy link
Owner

hsutter commented Jul 27, 2024

Thanks! Your code is now working with PR #1183:

F: type == () -> int;
f1: (a: *F)         = std::cout << a();
f2: (a: *() -> int) = std::cout << a();

g: () -> int = 42;

main: () = {
    f1(g&);
    f2(g&);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants