-
Notifications
You must be signed in to change notification settings - Fork 227
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
Child class overrides lambda in parent class #109
Comments
For comparison: private /* synthetic */ void lambda$onCreate$0(View view) {
Toast.makeText((Context)this, (CharSequence)"Parent onClick", (int)1).show();
}
static /* synthetic */ void access$lambda$0(ParentActivity parentActivity, View view) {
parentActivity.lambda$onCreate$0(view);
} Child: private /* synthetic */ void lambda$onCreate$0(View view) {
Toast.makeText((Context)this, (CharSequence)"Child onClick", (int)1).show();
}
static /* synthetic */ void access$lambda$0(MainActivity mainActivity, View view) {
mainActivity.lambda$onCreate$0(view);
} After: /* synthetic */ void lambda$onCreate$0(View view) {
Toast.makeText((Context)this, (CharSequence)"Parent onClick", (int)1).show();
} Child: @Override
/* synthetic */ void lambda$onCreate$0(View view) {
Toast.makeText((Context)this, (CharSequence)"Child onClick", (int)1).show();
} |
Related issue: #81 |
Possibly related to (or even a duplicate of) #95 |
…de parent lambdas.
If a child and parent class both have a lambda method of the same name, make the child lambda private, with an accessor, so that it doesn't override the parent lambda.
…de parent lambdas.
Issue luontola#109: Add unit test to make sure child lambdas don't hide paren…
Issue luontola#109: Prevent child lambdas overriding parent lambdas.
Thanks for your work on fixing this, especially @caarmen, and sorry about taking so long to respond. The origin of the bug is the One solution is to convert the private instance method into a package-private static method, which won't be overridable by child classes. This can be done safely for lambda implementation methods which only the lambda class will call - for other methods it would fall back to generating a (static) bridge access method. |
Issue #109: Add unit test to make sure child lambdas don't hide parent lambdas
I've made a fix for this which converts the private instance methods into package-private static methods. Please try it out. I'll release a new version soon. |
The fix to this has been released in Retrolambda 2.5.0 |
This was initially reported in the gradle-retrolambda project, but the problem appears to come from this project.
Copying the report here:
Clicking on button_parent shows a Toast with "Child onClick"
test app: https://github.com/cpalasanu/RetrolambdaTest
Using the cfr decompiler, we see that the child activity class has a method that overrides the parent activity class:
Parent:
Child:
Both parent and child have the same method
lambda$onCreate$0(View view)
I did some tests building the retrolambda project locally. It appears the bug appears in this commit: bf93245 (between releases 2.2.0 and 2.3.0) The PR for that commit: #86
I have not done any investigation to understand what part of that commit introduces the bug.
The text was updated successfully, but these errors were encountered: