From bf62b2e33e5e816e06a13f7db9c5d1e573860ac9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 14 Apr 2022 14:52:59 +0300 Subject: [PATCH] vfmt: stabilise the attribute sorting order (sort first by length of atributes, then in alphabetical order of their names) --- vlib/v/fmt/attrs.v | 7 +++++-- vlib/v/tests/create_dll/create_win_dll.v | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vlib/v/fmt/attrs.v b/vlib/v/fmt/attrs.v index 58cdbe4ebe..4b31fd1ea7 100644 --- a/vlib/v/fmt/attrs.v +++ b/vlib/v/fmt/attrs.v @@ -7,8 +7,11 @@ import v.ast pub fn (mut f Fmt) attrs(attrs []ast.Attr) { mut sorted_attrs := attrs.clone() - // Sort the attributes. The ones with arguments come first. - sorted_attrs.sort(a.arg.len > b.arg.len) + // Sort the attributes. The ones with arguments come first + sorted_attrs.sort_with_compare(fn (a &ast.Attr, b &ast.Attr) int { + d := b.arg.len - a.arg.len + return if d != 0 { d } else { compare_strings(b.arg, a.arg) } + }) for i, attr in sorted_attrs { if attr.arg.len == 0 { f.single_line_attrs(sorted_attrs[i..]) diff --git a/vlib/v/tests/create_dll/create_win_dll.v b/vlib/v/tests/create_dll/create_win_dll.v index c8a966aa46..b6684dbde9 100644 --- a/vlib/v/tests/create_dll/create_win_dll.v +++ b/vlib/v/tests/create_dll/create_win_dll.v @@ -13,8 +13,8 @@ pub fn test_tatltuae() int { return test.foo + test.bar } -[export: DllMain] [callconv: stdcall] +[export: DllMain] fn main(hinst voidptr, fdw_reason int, lp_reserved voidptr) bool { match fdw_reason { C.DLL_PROCESS_ATTACH {