Do not rebind field accesses if that would conflict with visibility.
This changes the assumption that field accesses are always dispatched to
an actual definition. Moving forward, your analysis has to make sure that
the field id is dispatched first.
This change also changes the semantics of some fields in AppInfoWithLiveness
to reflect this change.
Bug: 38187737
Change-Id: I221dac4ded6a6708d5bfc01bdd7a51a7b516294a
diff --git a/src/test/examples/memberrebinding/Memberrebinding.java b/src/test/examples/memberrebinding/Memberrebinding.java
new file mode 100644
index 0000000..74c99fd
--- /dev/null
+++ b/src/test/examples/memberrebinding/Memberrebinding.java
@@ -0,0 +1,38 @@
+// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package memberrebinding;
+
+import memberrebinding.subpackage.PublicClass;
+import memberrebindinglib.AnIndependentInterface;
+
+public class Memberrebinding {
+
+ public static void main(String[] args) {
+ ClassAtBottomOfChain bottomInstance = new ClassAtBottomOfChain();
+ bottomInstance.superCallsProperlyPropagate();
+ bottomInstance.methodThatCallsSuperCallsProperlyPropagateTwo();
+ bottomInstance.methodThatShadowsPrivate();
+ bottomInstance.ensureAllCalled();
+ System.out.println(bottomInstance.superField);
+ ClassExtendsLibraryClass classExtendsLibraryClass = new ClassExtendsLibraryClass();
+ classExtendsLibraryClass.methodThatAddsHelloWorld();
+ classExtendsLibraryClass.methodThatAddsHelloWorldUsingAddAll();
+ System.out.println(classExtendsLibraryClass.get(0));
+ System.out.println(classExtendsLibraryClass.get(1));
+ System.out.println(classExtendsLibraryClass.get(2));
+ PublicClass instance = new PublicClass();
+ instance.aMethod();
+ PublicClass.aStaticMethod();
+ ClassExtendsOtherLibraryClass classExtendsOther = new ClassExtendsOtherLibraryClass();
+ System.out.println(classExtendsOther.aMethodThatReturnsOne());
+ System.out.println(classExtendsOther.aMethodThatReturnsTwo());
+ System.out.println(classExtendsOther.aMethodThatReturnsThree());
+ System.out.println(classExtendsOther.aMethodThatReturnsFour());
+ AnIndependentInterface iface = classExtendsOther;
+ System.out.println(iface.aMethodThatReturnsTwo());
+ SuperClassOfClassExtendsOtherLibraryClass superClass = classExtendsOther;
+ System.out.println(superClass.aMethodThatReturnsTrue());
+ System.out.println(superClass.aMethodThatReturnsFalse());
+ }
+}