Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 1 | // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package classmerging; |
| 6 | |
Christoffer Quist Adamsen | f027763 | 2023-05-12 12:25:55 +0200 | [diff] [blame] | 7 | |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 8 | public class ConflictInGeneratedNameTest { |
| 9 | public static void main(String[] args) { |
| 10 | B obj = new B(); |
| 11 | obj.run(); |
| 12 | } |
| 13 | |
| 14 | public static class A { |
Christoffer Quist Adamsen | f027763 | 2023-05-12 12:25:55 +0200 | [diff] [blame] | 15 | @NeverPropagateValue @NoRedundantFieldLoadElimination private String name = "A"; |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 16 | |
| 17 | public A() { |
| 18 | print("In A.<init>()"); |
Christoffer Quist Adamsen | 4fcaa65 | 2020-11-27 09:49:11 +0100 | [diff] [blame] | 19 | $r8$constructor$classmerging$ConflictInGeneratedNameTest$A(); |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Christoffer Quist Adamsen | 4fcaa65 | 2020-11-27 09:49:11 +0100 | [diff] [blame] | 22 | private void $r8$constructor$classmerging$ConflictInGeneratedNameTest$A() { |
| 23 | print("In A.$r8$constructor$classmerging$ConflictInGeneratedNameTest$A()"); |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | public void printState() { |
| 27 | print("In A.printState()"); |
| 28 | print("A=" + name + "=" + getName()); |
| 29 | } |
| 30 | |
| 31 | // This method is not overridden. |
| 32 | public void foo() { |
| 33 | print("In A.foo()"); |
| 34 | } |
| 35 | |
| 36 | // This method is overridden. |
| 37 | public void bar() { |
| 38 | print("In A.bar()"); |
| 39 | } |
| 40 | |
| 41 | // This method is overridden and there is a PUBLIC method in B with the same name |
| 42 | // as the direct version of this method in B. |
| 43 | public void baz() { |
| 44 | print("In A.baz()"); |
| 45 | } |
| 46 | |
| 47 | // This method is overridden and there is a PRIVATE method in B with the same name |
| 48 | // as the direct version of this method in B. |
| 49 | public void boo() { |
| 50 | print("In A.boo()"); |
| 51 | } |
| 52 | |
| 53 | // There is a private method in B with the same name as this one. |
Christoffer Quist Adamsen | 801af25 | 2023-06-21 14:20:08 +0200 | [diff] [blame] | 54 | @NoAccessModification |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 55 | private String getName() { |
| 56 | return name; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public static class B extends A { |
Christoffer Quist Adamsen | f027763 | 2023-05-12 12:25:55 +0200 | [diff] [blame] | 61 | @NeverPropagateValue @NoRedundantFieldLoadElimination private String name = "B"; |
| 62 | |
| 63 | @NeverPropagateValue @NoRedundantFieldLoadElimination |
| 64 | private String name$classmerging$ConflictInGeneratedNameTest$A = "C"; |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 65 | |
| 66 | public B() { |
| 67 | print("In B.<init>()"); |
| 68 | print("A=" + super.name + "=" + super.getName()); |
| 69 | print("B=" + name + "=" + getName()); |
| 70 | print("C=" + name$classmerging$ConflictInGeneratedNameTest$A); |
| 71 | } |
| 72 | |
| 73 | public void run() { |
| 74 | printState(); |
| 75 | foo(); |
| 76 | bar(); |
| 77 | baz(); |
| 78 | baz$classmerging$ConflictInGeneratedNameTest$A(); |
| 79 | boo(); |
| 80 | boo$classmerging$ConflictInGeneratedNameTest$A(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void bar() { |
| 85 | print("In B.bar()"); |
| 86 | super.bar(); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void baz() { |
| 91 | print("In B.baz()"); |
| 92 | super.baz(); |
| 93 | } |
| 94 | |
| 95 | public void baz$classmerging$ConflictInGeneratedNameTest$A() { |
| 96 | print("In B.baz$classmerging$ConflictInGeneratedNameTest$A()"); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void boo() { |
| 101 | print("In B.boo()"); |
| 102 | super.boo(); |
| 103 | } |
| 104 | |
Christoffer Quist Adamsen | 801af25 | 2023-06-21 14:20:08 +0200 | [diff] [blame] | 105 | @NoAccessModification |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 106 | private void boo$classmerging$ConflictInGeneratedNameTest$A() { |
| 107 | print("In B.boo$classmerging$ConflictInGeneratedNameTest$A()"); |
| 108 | } |
| 109 | |
Christoffer Quist Adamsen | 801af25 | 2023-06-21 14:20:08 +0200 | [diff] [blame] | 110 | @NoAccessModification |
Christoffer Quist Adamsen | 1cbc764 | 2018-06-26 09:48:25 +0200 | [diff] [blame] | 111 | private String getName() { |
| 112 | return name; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | public static void print(String message) { |
| 117 | System.out.println(message); |
| 118 | } |
| 119 | } |