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

tests: add tests for checking fixed array .sort() errors #22656

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 26, 2024

This PR add tests for checking fixed array .sort() errors.

fn main() {
	mut arr := [3, 2, 1]!
	arr.sort(a < b, a)
	arr.sort(a == b)
	arr.sort(a > a)
	arr.sort(c > d)
}

PS D:\Test\v\tt1> v run .
tt1.v:3:6: error: expected 0 or 1 argument, but got 2
    1 | fn main() {
    2 |     mut arr := [3, 2, 1]!
    3 |     arr.sort(a < b, a)
      |         ~~~~~~~~~~~~~~
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
tt1.v:4:6: error: `.sort()` can only use `<` or `>` comparison
    2 |     mut arr := [3, 2, 1]!
    3 |     arr.sort(a < b, a)
    4 |     arr.sort(a == b)
      |         ~~~~~~~~~~~~
    5 |     arr.sort(a > a)
    6 |     arr.sort(c > d)
tt1.v:5:6: error: `.sort()` cannot use same argument
    3 |     arr.sort(a < b, a)
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
      |         ~~~~~~~~~~~
    6 |     arr.sort(c > d)
    7 | }
tt1.v:6:11: error: can not access external variable `c`
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
    6 |     arr.sort(c > d)
      |              ^
    7 | }
tt1.v:6:6: error: `.sort()` can only use `a` or `b` as argument, e.g. `arr.sort(a < b)`
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
    6 |     arr.sort(c > d)
      |         ~~~~~~~~~~~
    7 | }
tt1.v:6:11: error: undefined ident: `c`
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
    6 |     arr.sort(c > d)
      |              ^
    7 | }
tt1.v:6:15: error: undefined ident: `d`
    4 |     arr.sort(a == b)
    5 |     arr.sort(a > a)
    6 |     arr.sort(c > d)
      |                  ^
    7 | }
fn ret_array() [3]int {
	return [1, 3, 2]!
}

fn main() {
	ret_array().sort()
}

PS D:\Test\v\tt1> v run .
tt1.v:6:14: error: the `sort()` method can be called only on mutable receivers, but `ret_array()` is a call expression
    4 |
    5 | fn main() {
    6 |     ret_array().sort()
      |                 ~~~~~~
    7 | }
tt1.v:6:2: error: cannot pass expression as `mut`
    4 |
    5 | fn main() {
    6 |     ret_array().sort()
      |     ~~~~~~~~~~~
    7 | }

Huly®: V_0.6-21105

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.
Thank you 🙇🏻‍♂️ .

@spytheman spytheman merged commit 31c01fe into vlang:master Oct 26, 2024
60 checks passed
@yuyi98 yuyi98 deleted the check_fixed_array_sort_err branch October 26, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants