vfmt: stabilise the attribute sorting order (sort first by length of atributes, then in alphabetical order of their names)

pull/13758/merge
Delyan Angelov 2022-04-14 14:52:59 +03:00
parent f1f75897b3
commit bf62b2e33e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 6 additions and 3 deletions

View File

@ -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..])

View File

@ -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 {