Skip to content

Commit e1147c7

Browse files
authored
cgen: move sort fn after interface definitions(fix #24465) (#24967)
1 parent da0485f commit e1147c7

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,6 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
634634
b.write_string2('\n// V result_xxx definitions:\n', g.out_results.str())
635635
}
636636
b.write_string2('\n// V definitions:\n', g.definitions.str())
637-
if g.sort_fn_definitions.len > 0 {
638-
b.write_string2('\n// V sort fn definitions:\n', g.sort_fn_definitions.str())
639-
}
640637
if !pref_.parallel_cc {
641638
b.writeln('\n// V global/const non-precomputed definitions:')
642639
for var_name in g.sorted_global_const_names {
@@ -651,6 +648,9 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
651648
if interface_table.len > 0 {
652649
b.write_string2('\n// V interface table:\n', interface_table)
653650
}
651+
if g.sort_fn_definitions.len > 0 {
652+
b.write_string2('\n// V sort fn definitions:\n', g.sort_fn_definitions.str())
653+
}
654654
if g.hotcode_definitions.len > 0 {
655655
b.write_string2('\n// V hotcode definitions:\n', g.hotcode_definitions.str())
656656
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
interface Person {
2+
identify() int
3+
}
4+
5+
struct Boy {}
6+
7+
fn (self Boy) identify() int {
8+
return 0
9+
}
10+
11+
struct Girl {}
12+
13+
fn (self Girl) identify() int {
14+
return 1
15+
}
16+
17+
fn test_main() {
18+
mut ppl := []Person{}
19+
ppl << &Girl{}
20+
ppl << Boy{}
21+
ppl[0].identify()
22+
ppl.sort(a.identify() < b.identify())
23+
assert ppl == [Person(Boy{}), Girl{}]
24+
println(ppl)
25+
}

0 commit comments

Comments
 (0)