Closed kbkpbot closed 3 months ago
I think compiler is right, limited overload
.
I think compiler is right,
limited overload
.
No, I think there should has some bug in the compiler.
Change voidptr
to f64
, this will make compile OK
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
I agree that there is a bug in the compiler.
Aliasing a type, should work fine, with then doing an operator overload on the type alias, even if the original type is voidptr
.
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)
}
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