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 method for a generic struct expects the struct's type #20330

Closed
lv37 opened this issue Jan 1, 2024 · 0 comments · Fixed by #20360
Closed

Generic method for a generic struct expects the struct's type #20330

lv37 opened this issue Jan 1, 2024 · 0 comments · Fixed by #20360
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@lv37
Copy link
Contributor

lv37 commented Jan 1, 2024

Describe the bug

module main

// import scanner

struct Test[T] {}

fn (t Test[T]) abc[U]() {
	t.xyz[U]() // using t.xyz[T, U]() works
}

fn (t Test[T]) xyz[U]() {}

fn main() {
	t := Test[string]{}
	t.abc[f32]()
	t.abc[u32]()
}

Reproduction Steps

Try to compile the above code

Expected Behavior

Compile successfully

Current Behavior

src/main.v:8:7: error: expected 2 generic parameters, got 1
    6 | 
    7 | fn (t Test[T]) abc[U]() {
    8 |     t.xyz[U]() // using t.xyz[T, U]() works
      |          ~~~
    9 | }
   10 |
src/main.v:8:4: error: could not infer generic type `U` in call to `xyz`
    6 | 
    7 | fn (t Test[T]) abc[U]() {
    8 |     t.xyz[U]() // using t.xyz[T, U]() works
      |       ~~~~~~~~
    9 | }
   10 |

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 cb28144

Environment details (OS name and version, etc.)

V full version: V 0.4.3 b347f54.cb28144
OS: linux, Linux version 6.6.8-200.fc39.x86_64 (mockbuild@f2936e05dca94a129acf79933fec484d) (gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6), GNU ld version 2.40-13.fc39) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 04:01:49 UTC 2023
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz

getwd: /home/user/Projects/v-testing/mineflayer
vexe: /home/user/.local/lib/v/v
vexe mtime: 2024-01-01 12:28:31

vroot: OK, value: /home/user/.local/lib/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1002

Git version: git version 2.43.0
Git vroot status: weekly.2023.50-133-gcb28144e
.git/config present: true

CC version: cc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

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.

2 participants