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

generics not working in external modules #2528

Closed
amalshaji opened this issue Oct 24, 2019 · 8 comments
Closed

generics not working in external modules #2528

amalshaji opened this issue Oct 24, 2019 · 8 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@amalshaji
Copy link
Contributor

V version: V 0.1.21 753fe32
OS:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Codename: bionic

What did you do?
Wrote a sorting function using generics. Worked fine. Made the same function into a module and builds fine. Returns funny error when using the library

What did you expect to see?
Correct Output.

What did you see instead?
test.v:6:24: unexpected token: ,
5| fn main() {
6| nums := [1, 7, 0, 5, 6, 3]
Capture

@amalshaji amalshaji added the Bug This tag is applied to issues which reports bugs. label Oct 24, 2019
@Delta456
Copy link
Member

Can you show the whole code?

@amalshaji
Copy link
Contributor Author

amalshaji commented Oct 24, 2019

Module code Code: bubble_generic_module.v
working code : bubble_generic.v

@medvednikov
Copy link
Member

medvednikov commented Oct 24, 2019

works for me

$ v run bu.v
[0, 1, 3, 5, 6, 7]

@amalshaji
Copy link
Contributor Author

amalshaji commented Oct 24, 2019

Module is working fine? For me bubble_generic.v is ok, but bubble_generic_module.v is not running after the module is imported in another file.

@avitkauskas
Copy link
Contributor

@medvednikov It works only with all code in single file. Try to compile with the module.

import sorty

fn main() {
	mut nums := [1, 7, 0, 5, 6, 3]
	sorty.bubble(nums)
	println(nums)
}

This gives an error:

test1.v:6:19: unexpected token: `,`
    5| fn main() {
    6| 	mut nums := [1, 7, 0, 5, 6, 3]
             	           ^
    7| 	sorty.bubble(nums)
    8| 	println(nums)

@avitkauskas
Copy link
Contributor

Concerning the mutability of the immutable array - this works because of the line in the function bubble<T>(nums []T)

mut var := nums

And then modifying var also modifies nums - but should not, because nums was not declared mut.

@avitkauskas
Copy link
Contributor

avitkauskas commented Oct 24, 2019

Another interesting note. I put the module code in the file sorty/sorty.v and tried to compile it accidentally missing module in the compile comand. And that's what I got:

code/v % v build sorty
V error: function `main` is not declared in the main module

I did not do anything with module main, file sorty.v starts withmodule sorty.

@medvednikov medvednikov changed the title Unexpected token: "," generics not working in external modules Oct 30, 2019
@medvednikov
Copy link
Member

Fixed.

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.
Projects
None yet
Development

No branches or pull requests

4 participants