Commit 06214ff
authored
[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.kt1 parent cdff2b2 commit 06214ff
File tree
5 files changed
+31
-6
lines changed- src/Xamarin.Android.Tools.Bytecode/Kotlin
- tests/Xamarin.Android.Tools.Bytecode-Tests
- kotlin
5 files changed
+31
-6
lines changedLines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 112 | + | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
95 | 117 | | |
96 | 118 | | |
97 | 119 | | |
| |||
Binary file not shown.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments