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

Incorrectly removing Kotlin members #571

Closed
mattleibow opened this issue Feb 14, 2020 · 4 comments · Fixed by #573
Closed

Incorrectly removing Kotlin members #571

mattleibow opened this issue Feb 14, 2020 · 4 comments · Fixed by #573
Milestone

Comments

@mattleibow
Copy link
Contributor

Not sure of exactly why, but a member is being removed. It might have to do with the fact that there is a property and a method with the same name...

Message:

Kotlin: Hiding internal getter method okhttp3/MultipartBody - contentType

Property:
https://github.com/square/okhttp/blob/parent-4.2.2/okhttp/src/main/java/okhttp3/MultipartBody.kt#L38

private val contentType: MediaType = "$type; boundary=$boundary".toMediaType()

Method:
https://github.com/square/okhttp/blob/parent-4.2.2/okhttp/src/main/java/okhttp3/MultipartBody.kt#L51

override fun contentType(): MediaType = contentType

Binlog:
msbuild.zip

Project:
Square.OkHttp3.zip

@mattleibow
Copy link
Contributor Author

It appears to be happening for var as well:

https://github.com/square/okhttp/blob/parent-4.2.2/okhttp/src/main/java/okhttp3/Cache.kt#L152

  private var hitCount = 0

https://github.com/square/okhttp/blob/parent-4.2.2/okhttp/src/main/java/okhttp3/Cache.kt#L380

  @Synchronized fun hitCount(): Int = hitCount

@mattleibow
Copy link
Contributor Author

mattleibow added a commit to mattleibow/square-bindings that referenced this issue Feb 14, 2020
jpobst added a commit that referenced this issue Feb 18, 2020
jonpryor pushed a commit that referenced this issue Feb 19, 2020
Fixes: #571

Don't mark `public` Kotlin methods as `private` if they "shadow" --
share the same name as -- a private property or field.

If a library uses Kotlin's `NAME_SHADOWING` we incorrectly match the
`private` property/field to the `public` method and mark the methods
as `private`.  Given Kotlin:

	@Suppress("NAME_SHADOWING")
	public class NameShadowing {
	    // Property and method
	    private val count: Int = 3
	    fun count(): Int = count
	    
	    // Field and method
	    private var hitCount = 0
	    fun hitCount(): Int = hitCount
	    
	    // Property and setter
	    private var type = 0
	    fun setType(type: Int) = { println (type); }
	}

Then the public methods `NameShadowing.count()`,
`NameShadowing.hitCount()`, and `NameShadowing.setType()` were not
present within the C# binding.

Support name shadowing by only considering `getFoo()` methods as
potential property getters, instead of allowing `foo`.  (Allowing
`foo` was likely incorrect anyways.)

Additionally, when considering if a method is a potential property
setter, also check that the method's return type is `void`.

[Xamarin.Android.Tools.Bytecode] Kotlin name shadowing support (#573)
jonpryor pushed a commit that referenced this issue Feb 21, 2020
Fixes: #571

Don't mark `public` Kotlin methods as `private` if they "shadow" --
share the same name as -- a private property or field.

If a library uses Kotlin's `NAME_SHADOWING` we incorrectly match the
`private` property/field to the `public` method and mark the methods
as `private`.  Given Kotlin:

	@Suppress("NAME_SHADOWING")
	public class NameShadowing {
	    // Property and method
	    private val count: Int = 3
	    fun count(): Int = count
	    
	    // Field and method
	    private var hitCount = 0
	    fun hitCount(): Int = hitCount
	    
	    // Property and setter
	    private var type = 0
	    fun setType(type: Int) = { println (type); }
	}

Then the public methods `NameShadowing.count()`,
`NameShadowing.hitCount()`, and `NameShadowing.setType()` were not
present within the C# binding.

Support name shadowing by only considering `getFoo()` methods as
potential property getters, instead of allowing `foo`.  (Allowing
`foo` was likely incorrect anyways.)

Additionally, when considering if a method is a potential property
setter, also check that the method's return type is `void`.

[Xamarin.Android.Tools.Bytecode] Kotlin name shadowing support (#573)
@brendanzagaeski
Copy link
Member

brendanzagaeski commented Mar 27, 2020

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 again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.2.100.7 and 10.3.0.33.

Fix included on Windows in Visual Studio 2019 version 16.6 Preview 1 and higher. 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.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Member

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 10.3.1.0.

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

Fix included on macOS in Visual Studio 2019 for Mac version 8.6. 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
None yet
Projects
None yet
2 participants