Merge pull request #2840 from Rawi01/copy-vartype

Also copy vartype.type in TreeMirrorMaker
This commit is contained in:
Reinier Zwitserloot authored and GitHub committed 2021-09-16 02:03:29 +02:00
commit 602a68b8f8
4 files changed
+78

No files matched your search

@@ -32,8 +32,10 @@ import lombok.javac.JavacTreeMaker.TypeTag;
import com.sun.source.tree.LabeledStatementTree;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.TreeCopier;
import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
@@ -109,6 +111,21 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
if (wipeSymAndType) {
copy.sym = null;
copy.type = null;
} else {
if (original.vartype != null) {
copy.vartype.type = original.vartype.type;
original.vartype.accept(new TreeScanner() {
@Override public void scan(JCTree tree) {
super.scan(tree);
originalToCopy.get(tree).type = tree.type;
}
@Override public void visitSelect(JCFieldAccess tree) {
super.visitSelect(tree);
((JCFieldAccess) originalToCopy.get(tree)).sym = tree.sym;
}
});
}
}
}
@@ -0,0 +1,17 @@
import java.util.Map;
import java.util.HashMap;
public class ValAnonymousSubclassSelfReference {
public <T> void test(T arg) {
T d = arg;
Integer[] e = new Integer[1];
int[] f = new int[0];
java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
Integer h = 0;
int i = 0;
final int j = 1;
final int k = 2;
new ValAnonymousSubclassSelfReference() {
};
}
}
@@ -0,0 +1,23 @@
import java.util.Map;
import java.util.HashMap;
import lombok.val;
public class ValAnonymousSubclassSelfReference {
public ValAnonymousSubclassSelfReference() {
super();
}
public <T>void test(T arg) {
T d = arg;
Integer[] e = new Integer[1];
int[] f = new int[0];
java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
Integer h = 0;
int i = 0;
final @val int j = 1;
final @val int k = 2;
new ValAnonymousSubclassSelfReference() {
x() {
super();
}
};
}
}
@@ -0,0 +1,21 @@
// issue 2420: to trigger the problem 2 var/val, at least one normal variable and a anonymous self reference is required
import java.util.Map;
import java.util.HashMap;
import lombok.val;
public class ValAnonymousSubclassSelfReference {
public <T> void test(T arg) {
T d = arg;
Integer[] e = new Integer[1];
int[] f = new int[0];
java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
Integer h = 0;
int i = 0;
val j = 1;
val k = 2;
new ValAnonymousSubclassSelfReference() { };
}
}