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

Generic function fails to be created on second use of generic function #20847

Closed
jcweaver997 opened this issue Feb 16, 2024 · 1 comment · Fixed by #20878
Closed

Generic function fails to be created on second use of generic function #20847

jcweaver997 opened this issue Feb 16, 2024 · 1 comment · Fixed by #20878
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@jcweaver997
Copy link

jcweaver997 commented Feb 16, 2024

Describe the bug

There is a bug with the generics where it will not produce the generic function for the second use of the generic function. In this case, func2[Struct1] is generated, but func2[Struct2] is not, causing a compilation error

Reproduction Steps

The following code will produce the issue

module main

struct ClassInfo {
	func fn () = unsafe { nil }
}

pub fn func2[T]() {
}

pub fn func1[T]() {
	ci := ClassInfo{
		func: func2[T]
	}
	ci.func()
}

struct Struct1 {}

struct Struct2 {}

pub fn main() {
	func1[Struct1]()
	func1[Struct2]()
}

Expected Behavior

successful compile

Current Behavior

Fails to compile with the following error

PS C:\Users\jcwea\Documents\git\vtest> v -cg run .    
C:/Users/jcwea/AppData/Local/Temp/v_0/vtest.01HPSP98VD487P3GG4CG3VMKQV.tmp.c:497: warning: WINVER redefined
C:/Users/jcwea/AppData/Local/Temp/v_0/vtest.01HPSP98VD487P3GG4CG3VMKQV.tmp.c:6880: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/jcwea/AppData/Local/Temp/v_0/vtest.01HPSP98VD487P3GG4CG3VMKQV.tmp.c:13104: error: 'main__func2_T_main__Struct2' undeclared
builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.4 1d3147e

Environment details (OS name and version, etc.)

V full version: V 0.4.4 afd74ad.1d3147e
OS: windows, Microsoft Windows 11 Pro v26058 64-bit
Processor: 24 cpus, 64bit, little endian, 

getwd: C:\Users\jcwea\Documents\git\vtest
vexe: C:\Users\jcwea\Documents\git\v\v.exe
vexe mtime: 2024-02-16 19:26:43

vroot: OK, value: C:\Users\jcwea\Documents\git\v
VMODULES: OK, value: C:\Users\jcwea\.vmodules
VTMP: OK, value: C:\Users\jcwea\AppData\Local\Temp\v_0

Git version: git version 2.40.0.windows.1
Git vroot status: weekly.2024.06-86-g1d3147e1
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 b99a453d

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.

@jcweaver997 jcweaver997 added the Bug This tag is applied to issues which reports bugs. label Feb 16, 2024
@jcweaver997
Copy link
Author

This one has a workaround, just create a local variable with the function

module main

struct ClassInfo {
	func fn () = unsafe { nil }
}

pub fn func2[T]() {
}

pub fn func1[T]() {
	f := func2[T]
	ci := ClassInfo{
		func: f
	}
	ci.func()
}

struct Struct1 {}

struct Struct2 {}

pub fn main() {
	func1[Struct1]()
	func1[Struct2]()
}

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

Successfully merging a pull request may close this issue.

1 participant