Skip to content

Operator += is not implemented for generic type alias type V2 = vec.Vec2[f32], even though vlib/math/vec/vec2.v:75 implements it for the parent type Vec2[T] #23965

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

Closed
spytheman opened this issue Mar 17, 2025 · 2 comments · Fixed by #23967
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Operator Overload Type Aliases Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@spytheman
Copy link
Member

spytheman commented Mar 17, 2025

V version: V 0.4.9 21874f9, press to see full `v doctor` output
V full version V 0.4.9 c69b125.21874f9
OS linux, Ubuntu 20.04.6 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
Memory 0.42GB/15.05GB
V executable /home/delian/v/v
V last modified time 2025-03-17 07:08:53
V home dir OK, value: /home/delian/v
VMODULES OK, value: /home/delian/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/delian/v
env VFLAGS "-no-parallel"
Git version git version 2.48.1
V git status weekly.2025.11-48-g5978cbcf-dirty
.git/config present true
cc version cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
gcc version gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
clang version clang version 10.0.0-4ubuntu1
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.31-0ubuntu9.16) 2.31

What did you do?
./v -g -o vdbg cmd/v && ./vdbg b.v && b

import math.vec

type V2 = vec.Vec2[f32]

///// When this is uncommented, the program compiles and runs properly
//fn (a V2) + (b V2) V2 { return a.add(b) }

fn main() {
	a := V2{1,1}
	b := V2{10,20}
	mut c := a + b
	dump(c)
	c += a
	dump(c)
	assert c.x == 12
	assert c.y == 22
}
	

What did you see?

b.v:13:4: error: undefined operation `V2` + `V2`
   11 |     mut c := a + b
   12 |     dump(c)
   13 |     c += a
      |       ~~
   14 |     dump(c)
   15 |     assert c.x == 12

What did you expect to see?

A compiled program, since math.vec does define the + operator in vlib/math/vec/vec2.v:75.
Note also that c := a + b works, it is only c += a that does not get inferred correctly and produces an error.

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Operator Overload Type Aliases Unit: Checker Bugs/feature requests, that are related to the type checker. labels Mar 17, 2025
Copy link

Connected to Huly®: V_0.6-22360

@Delta456
Copy link
Member

I know what causes the issue. I will get to this.

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. Generics[T] Bugs/feature requests, that are related to the V generics. Operator Overload Type Aliases 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