-
Notifications
You must be signed in to change notification settings - Fork 56
Fixing generator code to validate name collision between Methods and Fields #504
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
Conversation
Issue tracking this bug: |
tools/generator/Tests/expected/InterfaceMethodsConflict/InterfaceMethodsConflict.xml
Outdated
Show resolved
Hide resolved
tools/generator/Tests/expected/InterfaceMethodsConflict/InterfaceMethodsConflict.xml
Outdated
Show resolved
Hide resolved
tools/generator/Tests/expected/InterfaceMethodsConflict/InterfaceMethodsConflict.xml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check this when looking at setters too? ie:
void SetItem (int item);
int item;
I agree that this is the correct fix, but just a heads up that we might need to do additional metadata
work when we apply it to dotnet/android#3632.
If I'm reading this right, this will add GetIcon ()
for API < 23, but then that method will disappear for 23+. I suspect we will need to add it for 23+ as deprecated so it still works for people spanning versions.
A
That said, adding a |
This should be checked & verified, but the desired outcome by default is that we add partial class Action {
public int Icon {get; set;}
public virtual Icon GetIcon ();
} Which, yes, would be an API break. However, we already have that API break, between v5.1 and v6.0, and we're ignoring it! Meaning today, if you have code using v5.1 which uses that member, and run it in an app targeting API-29, you're boned. :-( (...yet another reason why we need better API compatibility checking; see also dotnet/android#1118). |
9ab8610
to
f9daa4a
Compare
…ame can be converted to a property only if there is no field already with that name, otherwise the field gets drop.
f9daa4a
to
08cbcc9
Compare
tools/generator/Tests/expected/InterfaceMethodsConflict/InterfaceMethodsConflict.xml
Show resolved
Hide resolved
This looks good. One last concern: versioning! Consider that you have v1 of the API: // Java v1
public class Example {
public int getValue();
public void setValue(int value);
} We'd binding this as a // C# v1
public partial class Example {
public int Value {get; set;}
} Now, in Java v2, a // Java v2
public class Example {
public string value;
public int getValue();
public void setValue(int value);
} What should C# do? For starters, is this scenario supportable? Yes, but really only for
Back to what // C# v2 -- bad?
public partial class Example {
public String Value {get; set;}
public int GetValue();
public void SetValue(int value);
} This results in an API & ABI break with previous versions. Thus, two questions:
|
My opinion is fixing the fallout from that scenario is on the user. We will need to review any changes this causes to |
The problem is little bigger than I/we thought look this example: Interface IHttpEntity has an abstract method called GetContent then on AbstractHttpEntity class, but then on StringEntity class and a method called GetContent We were ignoring the protected content field and generating an override property Content. Derrived classes could never access the original "protected field" Now, with the generator changes it sees there is a field and generates the method with the original name trying to override it However the base class does not have that method available Here is the build error: obj/Debug/android-29/mcw/Org.Apache.Http.Entity.StringEntity.cs(11,23): error CS0534: 'StringEntity' does not implement inherited abstract member 'AbstractHttpEntity.Content.get' [/Users/gugavaro/Work/microsoft/Xamarin/xamarin-android/src/Mono.Android/Mono.Android.csproj] I am not sure we should fix this issue. thoughts? |
We need to check that methods that starts with Get can be "promoted" to a property only if there is no field already with that name, otherwise that collision will cause the field to be drop.
For example:
int Item;
GetITem();
that would cause GetItem to be converted to Item property and the field Item to not be included on the Api.