vlang/v

Unable to check arguments mismatch errors of array.sorted_with_compare()

Closed this issue · 0 comments

Describe the bug

Unable to check arguments mismatch errors of array.sorted_with_compare().

Reproduction Steps

fn main() {
	names := ['aaa', 'bbb', 'ccc']

	name1 := names.sorted_with_compare(sort_by_file_base)
	println(name1)

	name2 := names.sorted_with_compare(22)
	println(name2)
}

fn sort_by_file_base(a string, b string) int {
	return int(a > b)
}

Expected Behavior

tt1.v:11:24: error: sorted_with_compare callback function parameter `a` with type `string` should be `&string`
    9 | }
   10 | 
   11 | fn sort_by_file_base(a string, b string) int {
      |                        ~~~~~~
   12 |     return int(a > b)
   13 | }
tt1.v:11:34: error: sorted_with_compare callback function parameter `b` with type `string` should be `&string`
    9 | }
   10 | 
   11 | fn sort_by_file_base(a string, b string) int {
      |                                  ~~~~~~
   12 |     return int(a > b)
   13 | }
tt1.v:4:37: error: cannot use `fn (string, string) int` as `fn (voidptr, voidptr) int` in argument 1 to `[]string.sorted_with_compare`
    2 |     names := ['aaa', 'bbb', 'ccc']
    3 | 
    4 |     name1 := names.sorted_with_compare(sort_by_file_base)
      |                                        ~~~~~~~~~~~~~~~~~
    5 |     println(name1)
    6 |
Details: expected argument 1 to be a pointer, but the passed argument 1 is NOT a pointer
tt1.v:7:37: error: cannot use `int literal` as `fn (voidptr, voidptr) int` in argument 1 to `[]string.sorted_with_compare`
    5 |     println(name1)
    6 | 
    7 |     name2 := names.sorted_with_compare(22)
      |                                        ~~
    8 |     println(name2)
    9 | }

Current Behavior

['aaa', 'bbb', 'ccc']
0x00000016: at ???: RUNTIME ERROR: invalid memory access

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 2db53a4

Environment details (OS name and version, etc.)

V full version: V 0.4.7 2db53a4
OS: linux, Deepin 20.9 (VM)
Processor: 6 cpus, 64bit, little endian, AMD Ryzen 7 6800H with Radeon Graphics

getwd: /home/yuyi/test/t1
vexe: /home/yuyi/v/v
vexe mtime: 2024-09-27 09:03:16

vroot: OK, value: /home/yuyi/v
VMODULES: OK, value: /home/yuyi/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.20.1
Git vroot status: weekly.2024.39-30-g2db53a4b
.git/config present: true

CC version: cc (Uos 8.3.0.3-3+rebuild) 8.3.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.