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

function type generic cannot have a different generic letter when used as a parameter #22306

Open
Trakis196 opened this issue Sep 25, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@Trakis196
Copy link

Trakis196 commented Sep 25, 2024

Describe the bug

A generic function type with type T errors if used as a parameter for another function that has a different generic letter to T. A version of this with a struct does work.

struct Foo[T] {
	a T
}

fn f[X](foo Foo[X]) X {
	return foo.a
}

fn main() {
	foo := Foo[int]{10}
	println(f[int](foo))

}

however the function type version does not. This leads me to believe even though it is a V error instead of a builder or c error that this is a bug, as I don't see any reason why function types should be excluded from this behavior that structs have.

Reproduction Steps

type Fn[T] = fn () T

fn problem[X](f Fn[X]) X {
	return f[X]()
}

fn foo() int {
	return 1
}

fn main() {
	t := problem[int](foo)
	println(t)
}

Expected Behavior

To print 1

Current Behavior

error: generic type name T is not mentioned in fn problem[X]

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 9088970.4248fc5

Environment details (OS name and version, etc.)

OS: linux, "Arch Linux"
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

vroot: OK
VMODULES: OK
VTMP: OK
Git version: git version 2.46.0
Git vroot status: weekly.2024.37-64-g4248fc55
.git/config present: true

CC version: cc (GCC) 14.2.1 20240805
thirdparty/tcc status: thirdparty-linux-amd64 a0799a5b

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.

@Trakis196 Trakis196 added the Bug This tag is applied to issues which reports bugs. label Sep 25, 2024
@Trakis196 Trakis196 changed the title function type generic cannot have another generic letter when used as a parameter function type generic cannot have a different generic letter when used as a parameter Sep 25, 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.
Projects
None yet
Development

No branches or pull requests

1 participant