cgen: move sort fn after interface definitions(fix #24465) (#24967)
Some checks are pending
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run

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)
}