cgen: move sort fn after interface definitions(fix #24465) (#24967)

This commit is contained in:
Krchi 2025-07-25 12:27:51 +08:00 committed by GitHub
parent da0485f1d1
commit e1147c73d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View File

@ -634,9 +634,6 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
b.write_string2('\n// V result_xxx definitions:\n', g.out_results.str())
}
b.write_string2('\n// V definitions:\n', g.definitions.str())
if g.sort_fn_definitions.len > 0 {
b.write_string2('\n// V sort fn definitions:\n', g.sort_fn_definitions.str())
}
if !pref_.parallel_cc {
b.writeln('\n// V global/const non-precomputed definitions:')
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
if interface_table.len > 0 {
b.write_string2('\n// V interface table:\n', interface_table)
}
if g.sort_fn_definitions.len > 0 {
b.write_string2('\n// V sort fn definitions:\n', g.sort_fn_definitions.str())
}
if g.hotcode_definitions.len > 0 {
b.write_string2('\n// V hotcode definitions:\n', g.hotcode_definitions.str())
}

View File

@ -0,0 +1,25 @@
interface Person {
identify() int
}
struct Boy {}
fn (self Boy) identify() int {
return 0
}
struct Girl {}
fn (self Girl) identify() int {
return 1
}
fn test_main() {
mut ppl := []Person{}
ppl << &Girl{}
ppl << Boy{}
ppl[0].identify()
ppl.sort(a.identify() < b.identify())
assert ppl == [Person(Boy{}), Girl{}]
println(ppl)
}