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

Can't take address of generic function instantiation #7287

Closed
ntrel opened this issue Dec 12, 2020 · 3 comments · Fixed by #18180
Closed

Can't take address of generic function instantiation #7287

ntrel opened this issue Dec 12, 2020 · 3 comments · Fixed by #18180
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: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@ntrel
Copy link
Contributor

ntrel commented Dec 12, 2020

V version: recent git
OS: Windows 8

What did you do?

fn g<T>() {
	println(sizeof(T))
}

fn f<T>() {
	p := &g<T>
	p()
}

f<int>()
f<string>()

What did you expect to see?
Successful compilation.

What did you see instead?

sizeofT.v:7:2: error: unexpected name `p`, expecting `(`
    5 | fn f<T>() {
    6 |     p := &g<T>
    7 |     p()
      |     ^
    8 | }
    9 |
@ntrel ntrel added the Bug This tag is applied to issues which reports bugs. label Dec 12, 2020
@ntrel
Copy link
Contributor Author

ntrel commented Dec 12, 2020

This would be useful for #6991

@ntrel ntrel self-assigned this Dec 12, 2020
@ntrel
Copy link
Contributor Author

ntrel commented Dec 12, 2020

Started work on this:
https://github.com/ntrel/V/commits/gen-fn-ptr

@danieldaeschle danieldaeschle added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Jul 21, 2021
@ArtemkaKun
Copy link
Contributor

Updated code

fn g[T]() {
	println(sizeof(T))
}

fn f[T]() {
	p := &g[T]()
	p[T]()
}

f[int]()
f[string]()

Current error

code.v:6:7: error: cannot take the address of g()
    4 | 
    5 | fn f[T]() {
    6 |     p := &g[T]()
      |          ^
    7 |     p[T]()
    8 | }
code.v:7:2: error: unknown function: p
    5 | fn f[T]() {
    6 |     p := &g[T]()
    7 |     p[T]()
      |     ~~~~~~
    8 | }
    9 |

@ArtemkaKun ArtemkaKun added 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. labels Jan 12, 2023
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: 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