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

[XAT.Bytecode] Don't mark public Kotlin methods private if they shadow a private property/field #573

Merged
merged 1 commit into from
Feb 19, 2020

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Feb 18, 2020

Fixes #571.

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.

To fix:

  • Only consider getXXX methods as potential property getters instead of also allowing XXX. (This seems like it was incorrect anyways.)
  • When considering if a method is a potential property setter, also check that the method return type is void.

@jpobst jpobst requested a review from jonpryor February 18, 2020 19:24
@jonpryor jonpryor merged commit 566a461 into master Feb 19, 2020
@jonpryor jonpryor deleted the kotlin-shadowing branch February 19, 2020 03:42
jonpryor pushed a commit that referenced this pull request 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)
@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
Development

Successfully merging this pull request may close these issues.

Incorrectly removing Kotlin members
3 participants