Skip to content

builtin sort with a, b cannot call functions #22988

@Le0Developer

Description

@Le0Developer

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

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: CheckerBugs/feature requests, that are related to the type checker.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions