Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamain.Android.Tools.Bytecode] Hide private Kotlin default ctors (#1206
) Context: f6c12ba `Kotlin.Stdlib` contains [`kotlin.io.encoding.Base64`][0], a public class which is not intended to be instantiated by external users. Thus it only contains a `private` default constructor: // Kotlin public open /* partial */ class Base64 private constructor( internal val isUrlSafe: Boolean, internal val isMimeScheme: Boolean ) { // … public companion object Default : Base64(isUrlSafe = false, isMimeScheme = false) { // … } } which compiles into the equivalent Java code: // Java public /* partial */ class Base64 { private Base64 (boolean isUrlSafe, boolean isMimeScheme) {…} public Base64(boolean isUrlSafe, boolean isMimeScheme, kotlin.jvm.internal.DefaultConstructorMarker $constructor_marker) {…} // ^ synthetic constructor } Previously (f6c12ba) we believed that a synthetic default constructor would always end in an `int, DefaultConstructorMarker)` parameter pair, however this one does not. This synthetic constructor causes us to generate some bizarre "usable but shouldn't be used" constructors: // C# partial class Base64 { [Register (".ctor", "(ZZLkotlin/jvm/internal/DefaultConstructorMarker;)V", "")] public unsafe Base64 (bool isUrlSafe, bool isMimeScheme, global::Kotlin.Jvm.Internal.DefaultConstructorMarker? _constructor_marker) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) { // … } } Fix this by extending our Kotlin default constructor marker detection logic to look for any synthetic constructor whose final parameter is `DefaultConstructorMarker` to handle this additional case. With the change, `Kotlin.IO.Encoding.Base64` no longer generates a `public` constructor. [0]: https://github.com/JetBrains/kotlin/blob/3fbb7bc92086bdf3bde123a8f774bce25b19ef37/libraries/stdlib/src/kotlin/io/encoding/Base64.kt
- Loading branch information