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

builtin sort with a, b cannot call functions #22988

Closed
Le0Developer opened this issue Nov 27, 2024 · 1 comment · Fixed by #22989
Closed

builtin sort with a, b cannot call functions #22988

Le0Developer opened this issue Nov 27, 2024 · 1 comment · Fixed by #22989
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@Le0Developer
Copy link
Member

Le0Developer commented Nov 27, 2024

V doctor:

V full version: V 0.4.8 c1df71a.844d89f
OS: macos, macOS, 15.1.1, 24B2091
Processor: 10 cpus, 64bit, little endian, Apple M4

getwd: /Users/leodev/v
vexe: /Users/leodev/v/v
vexe mtime: 2024-11-27 11:44:37

vroot: OK, value: /Users/leodev/v
VMODULES: OK, value: /Users/leodev/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.47.0
Git vroot status: weekly.2024.48-8-g844d89fd
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.4)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

What did you do?
./v -g -o vdbg cmd/v && ./vdbg repro.v

struct AB {
	a int
	b int
}

fn (ab AB) value() int {
	return ab.a + ab.b
}

fn main() {
	mut values := [AB{1, 2}, AB{3, 4}, AB{5, 6}]
	values.sort(a.value() < b.value())
	println(values)
}

What did you expect to see?

Successful compilation

What did you see instead?

repro.v:13:9: error: `.sort()` can only use ident, index or selector as argument, 
e.g. `arr.sort(a < b)`, `arr.sort(a.id < b.id)`, `arr.sort(a[0] < b[0])`
   11 | fn main() {
   12 |     mut values := [AB{1, 2}, AB{3, 4}, AB{5, 6}]
   13 |     values.sort(a.value() < b.value())
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   14 |     println(values)
   15 | }

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.

Huly®: V_0.6-21429

@Le0Developer Le0Developer added the Bug This tag is applied to issues which reports bugs. label Nov 27, 2024
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Nov 27, 2024
@felipensp felipensp self-assigned this Nov 27, 2024
@JalonSolov
Copy link
Contributor

There has been a sort_with_compare function available for a long, long time. Seems like that could've been used, instead of modifying the regular sort routine.

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. Status: Confirmed This bug has been confirmed to be valid by a contributor. 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.

3 participants