From d09b0b704242c1d3c480c289368a8e89d5048be3 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Wed, 16 Dec 2020 15:05:49 +0300 Subject: [PATCH] Sort top-level descriptors by name --- .../org/jetbrains/kotlin/cli/klib/DeclarationPrinter.kt | 4 +++- .../org/jetbrains/kotlin/cli/klib/test/ContentsTest.kt | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/DeclarationPrinter.kt b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/DeclarationPrinter.kt index 2298c34926f..d420a603660 100644 --- a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/DeclarationPrinter.kt +++ b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/DeclarationPrinter.kt @@ -47,7 +47,9 @@ class DeclarationPrinter( } override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, data: Unit) { - val children = descriptor.getMemberScope().getContributedDescriptors().filter { it.shouldBePrinted } + val children = descriptor.getMemberScope().getContributedDescriptors() + .filter { it.shouldBePrinted } + .sortedBy { it.name } if (children.isNotEmpty()) { printer.printWithBody(header = headerRenderer.render(descriptor)) { children.forEach { it.accept(this, data) } diff --git a/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/ContentsTest.kt b/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/ContentsTest.kt index 64ea0c3633c..9e4a6db9cc8 100644 --- a/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/ContentsTest.kt +++ b/kotlin-native/klib/src/test/kotlin/org/jetbrains/kotlin/cli/klib/test/ContentsTest.kt @@ -48,6 +48,7 @@ class ContentsTest { package { @A @B fun a() + fun Foo.e() fun f1(x: Foo) fun f2(x: Foo, y: Foo): Int inline fun i1(block: () -> Foo) @@ -62,7 +63,6 @@ class ContentsTest { fun t3(x: T, y: F) inline fun t4(x: T) fun t5(x: T) - fun Foo.e() } """.trimIndent() } @@ -325,9 +325,9 @@ class ContentsTest { fun topLevelPropertiesWithClassesCustomPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesCustomPackage")) { """ package custom.pkg { - typealias MyTransformer = (String) -> Int object Bar class Foo constructor() + typealias MyTransformer = (String) -> Int } package custom.pkg { @@ -343,9 +343,9 @@ class ContentsTest { fun topLevelPropertiesWithClassesRootPackage() = klibContents(testLibrary("TopLevelPropertiesWithClassesRootPackage")) { """ package { - typealias MyTransformer = (String) -> Int object Bar class Foo constructor() + typealias MyTransformer = (String) -> Int } package {