-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
operator overloading not work: invalid operator +
to voidptr
and voidptr
#21654
Comments
I think compiler is right, |
No, I think there should has some bug in the compiler. Possible bug may be in the type system. My guess is: c := a + b // `c` is now voidptr, this is not correct, it should be `AF_ARRAY`
d := a * b // `d` is now voidptr, this is not correct, it should be `AF_ARRAY`
z := c + d
|
+
to voidptr
and voidptr
+
to voidptr
and voidptr
I agree that there is a bug in the compiler. |
I will work on this! |
This program works if there's an explicit alias cast. module main
type AF_ARRAY = voidptr
fn (a AF_ARRAY)add(b AF_ARRAY) AF_ARRAY {
mut y := AF_ARRAY(0)
return y
}
fn (a AF_ARRAY)mul(b AF_ARRAY) AF_ARRAY {
mut y := AF_ARRAY(0)
return y
}
fn (a AF_ARRAY) + (b AF_ARRAY) AF_ARRAY {
return a.add(b)
}
fn (a AF_ARRAY) * (b AF_ARRAY) AF_ARRAY {
return a.mul(b)
}
fn main() {
a := AF_ARRAY(0)
b := AF_ARRAY(0)
c := AF_ARRAY(a) +AF_ARRAY(b)
y := AF_ARRAY(a*a) + AF_ARRAY(b*b)
} |
…ases of primitive types (fix vlang#21654) (vlang#21663)
Describe the bug
When overloading operator, the return result seems has bug
Reproduction Steps
test.v
Expected Behavior
compile OK
Current Behavior
Possible Solution
No response
Additional Information/Context
remove line 30, that can compile OK.
change define from
voidptr
to a struct, also compile OKfor test only, the following code compile OK
V version
V full version: V 0.4.6 96751ed.1096173
Environment details (OS name and version, etc.)
V full version: V 0.4.6 96751ed.1096173
OS: linux, Ubuntu 22.04.4 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
getwd: /home/mars/.vmodules/varray/examples/benchmarks
vexe: /media/HD/github/lang/v/v
vexe mtime: 2024-06-02 12:15:49
vroot: OK, value: /media/HD/github/lang/v
VMODULES: OK, value: /home/mars/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.34.1
Git vroot status: weekly.2024.22-38-g096226bf
.git/config present: true
CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5
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.
The text was updated successfully, but these errors were encountered: