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 and interfaces getting some "could not infer type" error #19951

Closed
Dracks opened this issue Nov 20, 2023 · 0 comments · Fixed by #20098
Closed

Generics and interfaces getting some "could not infer type" error #19951

Dracks opened this issue Nov 20, 2023 · 0 comments · Fixed by #20098
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@Dracks
Copy link
Contributor

Dracks commented Nov 20, 2023

Describe the bug

Code: https://vosca.dev/p/b76f7e2a1f

struct Metadata{}

struct TagOrText {}

pub interface Layout[R] {
	render(content []R) string
}


struct DefaultLayout {
}

pub fn (self DefaultLayout) to_layout() Layout[TagOrText] {
	return self
}

pub fn (self DefaultLayout) render(content []TagOrText) string {
	return "Hello world"
}


DefaultLayout{}.to_layout().render([])

Reproduction Steps

Run the code, not sure if It can be smaller, I had some other interfaces doing similar stuff and works.

Expected Behavior

The code runs correctly

Current Behavior

Output:

code.v:14:2: error: could not infer generic type `R` in interface `Layout`
   12 | 
   13 | pub fn (self DefaultLayout) to_layout() Layout[TagOrText] {
   14 |     return self
      |     ~~~~~~~~~~~
   15 | }
   16 |
Exited with error status 1

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 c3cf9ee.cc220e6

Environment details (OS name and version, etc.)

V full version: V 0.4.3 c3cf9ee.0966fd3
OS: linux, Ubuntu 22.04.2 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz

getwd: /home/pmakhnev/playground
vexe: /home/pmakhnev/v/v
vexe mtime: 2023-11-20 18:00:09

vroot: OK, value: /home/pmakhnev/v
VMODULES: OK, value: /root/.vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.34.1
Git vroot status: weekly.2023.45.1-90-g0966fd3b
.git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
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.

@Dracks Dracks added the Bug This tag is applied to issues which reports bugs. label Nov 20, 2023
@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Nov 21, 2023
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. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants