Skip to content
Permalink
Browse files

8239536: Can't use `java.util.List` object after importing `java.awt.…

…List`

Using full qualified names for synthetic types; ensuring the user is warned when a variable becomes undefined due to a dependency change.

Reviewed-by: rfield
  • Loading branch information
Jan Lahoda
Jan Lahoda committed Feb 24, 2020
1 parent 4f20fa5 commit acd2d32913e9526f750075b99e2ccf11533f02fd
@@ -1208,6 +1208,7 @@ startup.feedback = \
/set mode normal -command verbose \n\
/set format normal display '' added,modified,replaced,overwrote,dropped-update \n\
/set format normal display '{pre}{action} variable {name}, reset to null{post}' replaced-vardecl,varinit-ok-update \n\
/set format normal display '{pre}{action} variable {name}{resolve}{post}' replaced-vardecl,varinit-notdefined \n\
/set format normal display '{result}' added,modified,replaced-expression,varvalue,assignment,varinit,vardecl-ok-primary \n\
/set mode concise -quiet normal \n\
\n\
@@ -59,6 +59,7 @@
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import java.util.function.BinaryOperator;
import jdk.jshell.ExpressionToTypeInfo.ExpressionInfo.AnonymousDescription;
import jdk.jshell.ExpressionToTypeInfo.ExpressionInfo.AnonymousDescription.VariableDesc;
import jdk.jshell.TaskFactory.AnalyzeTask;
@@ -406,9 +407,9 @@ private ExpressionInfo treeToInfo(TreePath tp) {
Type accessibleType = accessibleTypes.size() == 1 ? accessibleTypes.head
: types.makeIntersectionType(accessibleTypes);
ei.declareTypeName =
varTypeName(accessibleType, false, AnonymousTypeKind.DECLARE);
varTypeName(accessibleType, (full, pkg) -> full, false, AnonymousTypeKind.DECLARE);
ei.fullTypeName =
varTypeName(enhancedTypesAccessible ? accessibleType : type,
varTypeName(enhancedTypesAccessible ? accessibleType : type, (full, pkg) -> full,
true, AnonymousTypeKind.DECLARE);
ei.displayTypeName =
varTypeName(type, true, AnonymousTypeKind.DISPLAY);
@@ -510,11 +511,15 @@ public Void visitIdentifier(IdentifierTree node, Void p) {
ElementKind.PARAMETER, ElementKind.RESOURCE_VARIABLE);

private String varTypeName(Type type, boolean printIntersectionTypes, AnonymousTypeKind anonymousTypesKind) {
return varTypeName(type, state.maps::fullClassNameAndPackageToClass, printIntersectionTypes, anonymousTypesKind);
}

private String varTypeName(Type type, BinaryOperator<String> fullClassNameAndPackageToClass, boolean printIntersectionTypes, AnonymousTypeKind anonymousTypesKind) {
try {
Function<TypeSymbol, String> anonymousClass2DeclareName =
cs -> anon2Name.computeIfAbsent(cs, state.eval::computeDeclareName);
TypePrinter tp = new TypePrinter(at.messages(),
state.maps::fullClassNameAndPackageToClass, anonymousClass2DeclareName,
fullClassNameAndPackageToClass, anonymousClass2DeclareName,
printIntersectionTypes, anonymousTypesKind);
List<Type> captures = types.captures(type);
String res = tp.toString(types.upward(type, captures));
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099 8199623 8236715
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099 8199623 8236715 8239536
* @summary Simple jshell tool tests
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -912,4 +912,20 @@ public void testRecords() {
"| attempted to use record R which cannot be instantiated or its methods invoked until variable j is declared")
);
}

@Test
public void testImportChange() {
for (String feedback : new String[] {"verbose", "normal"}) {
test(
(a) -> assertCommandOutputContains(a, "/set feedback " + feedback, "| Feedback mode: " + feedback),
(a) -> assertCommand(a, "import java.util.*", ""),
(a) -> assertCommandOutputContains(a, "var v1 = List.of(1);", "v1 ==> [1]"),
(a) -> assertCommandOutputContains(a, "import java.awt.List;",
"| update replaced variable v1 which cannot be referenced until this error is corrected:"),
(a) -> assertCommandOutputContains(a, "var b = java.util.List.of(\"bb\")",
"b ==> [bb]"),
(a) -> assertCommandOutputContains(a, "b", "b ==> [bb]")
);
}
}
}
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8144903 8177466 8191842 8211694 8213725
* @bug 8144903 8177466 8191842 8211694 8213725 8239536
* @summary Tests for EvaluationState.variables
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -466,6 +466,15 @@ public void displayName() {
assertVarDisplayName("var v6 = new Runnable() { public void run() { } };", "<anonymous class implementing Runnable>");
}

public void varType() {
assertEval("import java.util.*;");
var firstVar = varKey(assertEval("var v1 = List.of(1);", added(VALID)));
assertEval("import list.List;", DiagCheck.DIAG_OK, DiagCheck.DIAG_ERROR, added(VALID),
ste(firstVar, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
assertEval("var v2 = java.util.List.of(1);", added(VALID));
assertEval("v2", "[1]");
}

public void varDeclNoInit() {
assertVarDeclNoInit("byte", "b", "0");
assertVarDeclNoInit("short", "h", "0");
@@ -579,6 +588,10 @@ public void setUp() {
"\n" +
"public interface J<T> {\n" +
" public List<T> get();\n" +
"}\n",
"package list;\n" +
"\n" +
"public class List {\n" +
"}\n");
String tpath = compiler.getPath(path).toString();
setUp(b -> b

0 comments on commit acd2d32

Please sign in to comment.