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

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

Closed
yuyi98 opened this issue Sep 27, 2024 · 0 comments · Fixed by #22328
Closed

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

yuyi98 opened this issue Sep 27, 2024 · 0 comments · Fixed by #22328
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@yuyi98
Copy link
Member

yuyi98 commented Sep 27, 2024

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.

@yuyi98 yuyi98 added the Bug This tag is applied to issues which reports bugs. label Sep 27, 2024
@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Sep 27, 2024
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