v icon indicating copy to clipboard operation
v copied to clipboard

error: could not infer generic type `U` in call to `myfunc`

Open impopular-guy opened this issue 1 year ago • 0 comments

Describe the bug

See Reproduction for code

If I replace struct MyData[T] with struct MyData[U] in its definition, code works. Or If replace U with T in function myfunc definition, code also works.

I saw in the C code, how no matter what single-capital letter i use for generic, it is always replaced by T, but it seems like it is not working in this case.

Expected Behavior

run successfully

Current Behavior

vtest ❯ v run .\generic1.v
generic1.v:23:5: error: could not infer generic type `U` in call to `myfunc`
   21 | fn main() {
   22 |     d1 := MyData[int]{}
   23 |     myfunc(d1)
      |     ~~~~~~~~~~
   24 | }

Reproduction Steps

module main

struct MyData[T] {
}

fn myfunc[U](a MyData[U]){
    println(a)
}

fn main() {
    d1 := MyData[int]{}
    myfunc(d1)
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.3 2597efa

Environment details (OS name and version, etc.)

OS: windows, Microsoft Windows 11 Home Single Language v22621 64-bit
Processor: 8 cpus, 64bit, little endian,
CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
 cmd: cc --version

getwd: C:\Users\dhrit\Desktop\ToReead\vtest
vmodules: C:\Users\dhrit\.vmodules
vroot: C:\BIN\v
vexe: C:\BIN\v\v.exe
vexe mtime: 2023-03-08 06:39:31
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 2597efa

Git version: git version 2.35.1.windows.2
Git vroot status: weekly.2023.09-49-g2597efa7
.git/config present: true
thirdparty/tcc status: thirdparty-windows-amd64 e90c2620

impopular-guy avatar Mar 08 '23 06:03 impopular-guy