Skip to content
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

[Xamarin.Android.Tools.Bytecode] Fix for finding public setters with Kotlin unsigned types. #1156

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Oct 30, 2023

In #1151, we updated the logic that matches a Kotlin public property getter/setter to a generated Java getter/setter that follows this pattern:

// Kotlin
public var type = 0

// Java
private int type = 0;

public int getType () { ... }
public void setType (int p0) { ... }

However, this caused our unit tests in XA to fail that use Kotlin unsigned types:

KotlinUnsignedTypesTests.cs: 
error CS0200: Property or indexer 'UnsignedInstanceMethods.UnsignedInstanceProperty' cannot be assigned to -- it is read only

This is because properties that use Kotlin unsigned types append a -<type-hash> suffix to their getter/setter names:

// Kotlin
public var type: UInt = 0u

// Java
private int type = 0;

public int getType-pVg5ArA () { ... }
public void setType-WZ4Q5Ns (int p0) { ... }

Update our logic to handle this case.

@jpobst jpobst force-pushed the kotlin-public-setter-fix branch from 5422a81 to c34eed5 Compare October 30, 2023 18:38
@jpobst jpobst force-pushed the kotlin-public-setter-fix branch from c34eed5 to 24f398c Compare October 30, 2023 19:57
@jpobst jpobst changed the title [Xamarin.Android.Tools.Bytecode] Fix for finding public setters with old kotlinc versions. [Xamarin.Android.Tools.Bytecode] Fix for finding public setters with Kotlin unsigned types. Oct 30, 2023
@jpobst
Copy link
Contributor Author

jpobst commented Oct 31, 2023

XA test PR:
dotnet/android#8473
https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=8615135

All the test failures appear to be apkdiff thresholds. Presumably this is due to the (unrelated) invoker interface changes.

@jpobst jpobst marked this pull request as ready for review October 31, 2023 02:21
@jpobst jpobst requested a review from jonpryor October 31, 2023 18:02
@jonpryor jonpryor merged commit 38c8a82 into main Nov 3, 2023
@jonpryor jonpryor deleted the kotlin-public-setter-fix branch November 3, 2023 19:20
jonpryor added a commit to dotnet/android that referenced this pull request Nov 7, 2023
Fixes: dotnet/java-interop#910
Fixes: dotnet/java-interop#1139

Changes: dotnet/java-interop@3c83179...38c8a82

  * dotnet/java-interop@38c8a827: [Xamarin.Android.Tools.Bytecode] Kotlin unsigned internal props (dotnet/java-interop#1156)
  * dotnet/java-interop@1adb7964: [generator] `generator --lang-features=emit-legacy-interface-invokers` (dotnet/java-interop#1145)
  * dotnet/java-interop@6bd7ae48: [Xamarin.Android.Tools.Bytecode] Kotlin internal prop visibility (dotnet/java-interop#1151)

Updates `class-parse` to better support parsing the visibility of
Kotlin properties.

Updates `generator` to emit optimized interface Invokers.
The previous interface invoker codegen strategy can be enabled by
setting `$(_AndroidEmitLegacyInterfaceInvokers)`=True.
jonathanpeppers pushed a commit that referenced this pull request Nov 13, 2023
Context: 6bd7ae4

In commit 6bd7ae4, we updated the logic that matches a Kotlin public
property getter/setter to a generated Java getter/setter that follows
this pattern:

	// Kotlin
	public var type = 0

	// Java
	private int type = 0;

	public int getType () { ... }
	public void setType (int p0) { ... }

However, this caused unit tests in xamarin/xamarin-android to fail
that when using Kotlin unsigned types:

	KotlinUnsignedTypesTests.cs: 
	error CS0200: Property or indexer 'UnsignedInstanceMethods.UnsignedInstanceProperty' cannot be assigned to -- it is read only

This is because properties that use Kotlin unsigned types append a
`-<type-hash>` suffix to their getter/setter names:

	// Kotlin
	public var type: UInt = 0u

	// Java
	private int type = 0;

	public int getType-pVg5ArA () { ... }
	public void setType-WZ4Q5Ns (int p0) { ... }

Update our Kotlin logic to handle this case.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants