Skip to content

Ignore binding Kotlin synthetic default constructors #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jpobst opened this issue Aug 21, 2020 · 2 comments · Fixed by #700
Closed

Ignore binding Kotlin synthetic default constructors #694

jpobst opened this issue Aug 21, 2020 · 2 comments · Fixed by #700
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jpobst
Copy link
Contributor

jpobst commented Aug 21, 2020

Context: dotnet/android#3776

When using a Kotlin default constructor like:

class MaterialDialog(
  val windowContext: Context,
  val dialogBehavior: DialogBehavior = DEFAULT_BEHAVIOR
) : Dialog(windowContext, inferTheme(windowContext, dialogBehavior)) 
{ ... }

Kotlin will create 2 constructors, the "real" one and a synthetic one denoting which constructor is the default constructor using a kotlin.jvm.internal.DefaultConstructorMarker parameter:

<constructor deprecated="not deprecated" final="false" name="MaterialDialog" static="false" visibility="public" bridge="false" synthetic="false" jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;)V">
  <parameter name="windowContext" type="android.content.Context" jni-type="Landroid/content/Context;" not-null="true"/>
  <parameter name="dialogBehavior" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;" not-null="true"/>
</constructor>
<constructor deprecated="not deprecated" final="false" name="MaterialDialog" static="false" visibility="public" bridge="false" synthetic="true" jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;ILkotlin/jvm/internal/DefaultConstructorMarker;)V">
  <parameter name="p0" type="android.content.Context" jni-type="Landroid/content/Context;"/>
  <parameter name="p1" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;"/>
  <parameter name="p2" type="int" jni-type="I"/>
  <parameter name="p3" type="kotlin.jvm.internal.DefaultConstructorMarker" jni-type="Lkotlin/jvm/internal/DefaultConstructorMarker;"/>
</constructor>

The kotlin.jvm.internal.DefaultConstructorMarker type is not available in the Xamarin.Kotlin.StdLib NuGet package because the type in internal.

Thus when trying to bind the constructor, ApiXmlAdjuster reports this "error":

Error while processing '[Constructor] MaterialDialog(android.content.Context p0, com.afollestad.materialdialogs.DialogBehavior p1, int p2, kotlin.jvm.internal.DefaultConstructorMarker p3)' in '[Class] com.afollestad.materialdialogs.MaterialDialog': Type 'kotlin.jvm.internal.DefaultConstructorMarker' was not found.

This is actually good, as we shouldn't bind this synthetic constructor, but we should detect this Kotlin-ism and not emit the "error", as it misleads users into thinking they need to do something to fix it.

@jpobst jpobst added enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.) labels Aug 21, 2020
jonpryor pushed a commit that referenced this issue Aug 28, 2020
…700)

Fixes: #694

Context: dotnet/android#3776

When using a Kotlin default constructor like:

	class MaterialDialog(
	  val windowContext: Context,
	  val dialogBehavior: DialogBehavior = DEFAULT_BEHAVIOR
	) : Dialog(windowContext, inferTheme(windowContext, dialogBehavior)) 
	{ ... }

Kotlin will create 2 constructors, the "real" one, and a synthetic one
denoting which constructor is the default constructor using a
`kotlin.jvm.internal.DefaultConstructorMarker` parameter:

	<constructor deprecated="not deprecated" final="false"
	    name="MaterialDialog" static="false" visibility="public"
	    bridge="false" synthetic="false"
	    jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;)V">
	  <parameter name="windowContext" type="android.content.Context" jni-type="Landroid/content/Context;" not-null="true"/>
	  <parameter name="dialogBehavior" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;" not-null="true"/>
	</constructor>
	<constructor deprecated="not deprecated" final="false"
	    name="MaterialDialog" static="false" visibility="public"
	    bridge="false" synthetic="true"
	    jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;ILkotlin/jvm/internal/DefaultConstructorMarker;)V">
	  <parameter name="p0" type="android.content.Context" jni-type="Landroid/content/Context;"/>
	  <parameter name="p1" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;"/>
	  <parameter name="p2" type="int" jni-type="I"/>
	  <parameter name="p3" type="kotlin.jvm.internal.DefaultConstructorMarker" jni-type="Lkotlin/jvm/internal/DefaultConstructorMarker;"/>
	</constructor>

Additionally, the `kotlin.jvm.internal.DefaultConstructorMarker` type
is not available in the `Xamarin.Kotlin.StdLib` NuGet package, because
the type is `internal`.

Consequently, when trying to bind the constructor, `ApiXmlAdjuster`
reports this "error":

	Error while processing '[Constructor] MaterialDialog(android.content.Context p0, com.afollestad.materialdialogs.DialogBehavior p1, int p2, kotlin.jvm.internal.DefaultConstructorMarker p3)' in '[Class] com.afollestad.materialdialogs.MaterialDialog': Type 'kotlin.jvm.internal.DefaultConstructorMarker' was not found.

This is actually good, as we shouldn't bind this synthetic constructor,
but we should detect this Kotlin-ism and not emit the "error", as it
misleads users into thinking they need to do something to fix it.

Update `Xamarin.Android.Tools.Bytecode` to *hide* constructors for
which the final two parameter types are `int, DefaultConstructorMarker`,
thus ensuring that `ApiXmlAdjuster` & co. won't process such members
or attempt to resolve the unresolvable `DefaultConstructorMarker` type.
jonpryor pushed a commit that referenced this issue Aug 31, 2020
…700)

Fixes: #694

Context: dotnet/android#3776

When using a Kotlin default constructor like:

	class MaterialDialog(
	  val windowContext: Context,
	  val dialogBehavior: DialogBehavior = DEFAULT_BEHAVIOR
	) : Dialog(windowContext, inferTheme(windowContext, dialogBehavior))
	{ ... }

Kotlin will create 2 constructors, the "real" one, and a synthetic one
denoting which constructor is the default constructor using a
`kotlin.jvm.internal.DefaultConstructorMarker` parameter:

	<constructor deprecated="not deprecated" final="false"
	    name="MaterialDialog" static="false" visibility="public"
	    bridge="false" synthetic="false"
	    jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;)V">
	  <parameter name="windowContext" type="android.content.Context" jni-type="Landroid/content/Context;" not-null="true"/>
	  <parameter name="dialogBehavior" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;" not-null="true"/>
	</constructor>
	<constructor deprecated="not deprecated" final="false"
	    name="MaterialDialog" static="false" visibility="public"
	    bridge="false" synthetic="true"
	    jni-signature="(Landroid/content/Context;Lcom/afollestad/materialdialogs/DialogBehavior;ILkotlin/jvm/internal/DefaultConstructorMarker;)V">
	  <parameter name="p0" type="android.content.Context" jni-type="Landroid/content/Context;"/>
	  <parameter name="p1" type="com.afollestad.materialdialogs.DialogBehavior" jni-type="Lcom/afollestad/materialdialogs/DialogBehavior;"/>
	  <parameter name="p2" type="int" jni-type="I"/>
	  <parameter name="p3" type="kotlin.jvm.internal.DefaultConstructorMarker" jni-type="Lkotlin/jvm/internal/DefaultConstructorMarker;"/>
	</constructor>

Additionally, the `kotlin.jvm.internal.DefaultConstructorMarker` type
is not available in the `Xamarin.Kotlin.StdLib` NuGet package, because
the type is `internal`.

Consequently, when trying to bind the constructor, `ApiXmlAdjuster`
reports this "error":

	Error while processing '[Constructor] MaterialDialog(android.content.Context p0, com.afollestad.materialdialogs.DialogBehavior p1, int p2, kotlin.jvm.internal.DefaultConstructorMarker p3)' in '[Class] com.afollestad.materialdialogs.MaterialDialog': Type 'kotlin.jvm.internal.DefaultConstructorMarker' was not found.

This is actually good, as we shouldn't bind this synthetic constructor,
but we should detect this Kotlin-ism and not emit the "error", as it
misleads users into thinking they need to do something to fix it.

Update `Xamarin.Android.Tools.Bytecode` to *hide* constructors for
which the final two parameter types are `int, DefaultConstructorMarker`,
thus ensuring that `ApiXmlAdjuster` & co. won't process such members
or attempt to resolve the unresolvable `DefaultConstructorMarker` type.
jonpryor added a commit to dotnet/android that referenced this issue Aug 31, 2020
Fixes: dotnet/java-interop#694
Fixes: #3776
Fixes: #4989

Changes: dotnet/java-interop@a92fd18...b4c2a67

  * dotnet/java-interop@b4c2a67c: [Xamarin.Android.Tools.Bytecode] Hide Kotlin synthetic constructors (#700)
  * dotnet/java-interop@4141d848: [Java.Interop] Avoid double-disposing PeerReferences (#690)
@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android SDK version 11.1.0.3.

Fix included on Windows in Visual Studio 2019 version 16.8 Preview 3. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 3. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android SDK version 11.1.0.17.

Fix included on Windows in Visual Studio 2019 version 16.8. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants