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

Mismatched virtual on property getter/setter #485

Open
jpobst opened this issue Aug 23, 2019 · 0 comments
Open

Mismatched virtual on property getter/setter #485

jpobst opened this issue Aug 23, 2019 · 0 comments
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jpobst
Copy link
Contributor

jpobst commented Aug 23, 2019

What should happen if the getter & setter differ in their "virtual-ness"?

This has actually happened in Android, via Activity's getTitle() and setTitle() methods:

<class abstract="false" deprecated="not deprecated" extends="android.view.ContextThemeWrapper" extends-generic-aware="android.view.ContextThemeWrapper" jni-extends="Landroid/view/ContextThemeWrapper;" final="false" name="Activity" static="false" visibility="public" jni-signature="Landroid/app/Activity;">
  <method abstract="false" deprecated="not deprecated" final="true" name="getTitle" jni-signature="()Ljava/lang/CharSequence;" bridge="false" native="false" return="java.lang.CharSequence" jni-return="Ljava/lang/CharSequence;" static="false" synchronized="false" synthetic="false" visibility="public" />
  <method abstract="false" deprecated="not deprecated" final="false" name="setTitle" jni-signature="(Ljava/lang/CharSequence;)V" bridge="false" native="false" return="void" jni-return="V" static="false" synchronized="false" synthetic="false" visibility="public">
    <parameter name="title" type="java.lang.CharSequence" jni-type="Ljava/lang/CharSequence;" />
  </method>
</class>

(Above XML fragments from xamarin-android/bin/BuildDebug/api/api-28.xml.in.)

Which is to say, consider:

public class Activity {
    public final CharSequence getTitle() {return null;}
    public void setTitle(CharSequence value) {}
}

Currently -- arguably a bug! -- we remove the "virtual-ness", and emit:

partial class Activity {
  public unsafe Java.Lang.ICharSequence TitleFormatted {
    get { /*performs non-virtual dispatch */}
    set { /* performs virtual dispatch! */ }
  }
}

Which is admittedly "wonky", but... that's what we've done.

Rephrased: maybe perhaps we should reconsider this code idiom?

That said, in "reconsidering" we also need to maintain ABI compatibility with existing Mono.Android.dll, but there are various ways to work around that...

@jpobst jpobst changed the title Mismatched "virtual" on property getter/setter Mismatched virtual on property getter/setter Aug 23, 2019
@jpobst jpobst added generator Issues binding a Java library (generator, class-parse, etc.) bug Component does not function as intended labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

No branches or pull requests

1 participant