author | coleenp |
Fri, 31 Aug 2018 07:03:46 -0400 | |
changeset 51608 | 625a5bdde0c5 |
parent 48610 | a587f95313f1 |
permissions | -rw-r--r-- |
47975
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
1 |
/* |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47975
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
47975
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
4 |
* |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
8 |
* |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
14 |
* |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
18 |
* |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
21 |
* questions. |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
22 |
*/ |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
23 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
24 |
/* |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47975
diff
changeset
|
25 |
* @test 8190939 8191842 |
47975
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
26 |
* @summary test expressions whose type is inaccessible |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
27 |
* @modules jdk.compiler/com.sun.tools.javac.api |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
28 |
* jdk.compiler/com.sun.tools.javac.main |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
29 |
* jdk.jdeps/com.sun.tools.javap |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
30 |
* @library /tools/lib |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
31 |
* @build KullaTesting Compiler |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
32 |
* @run testng InaccessibleExpressionTest |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
33 |
*/ |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
34 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
35 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
36 |
import java.nio.file.Path; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
37 |
import java.nio.file.Paths; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
38 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
39 |
import org.testng.annotations.BeforeMethod; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
40 |
import jdk.jshell.VarSnippet; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
41 |
import org.testng.annotations.Test; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
42 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
43 |
import static org.testng.Assert.assertEquals; |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
44 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
45 |
@Test |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
46 |
public class InaccessibleExpressionTest extends KullaTesting { |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
47 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
48 |
@BeforeMethod |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
49 |
@Override |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
50 |
public void setUp() { |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
51 |
Path path = Paths.get("eit"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
52 |
Compiler compiler = new Compiler(); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
53 |
compiler.compile(path, |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
54 |
"package priv;\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
55 |
"\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
56 |
"import java.util.function.Supplier;\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
57 |
"import java.util.ArrayList;\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
58 |
"\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
59 |
"public class GetPriv {\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
60 |
" private enum Count { One };\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
61 |
" public static Packp down() { return new Packp(); }\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
62 |
" public static MyList list() { return new MyList(); }\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
63 |
" public static Count priv() { return Count.One; }\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
64 |
"}\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
65 |
"\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
66 |
"class Packp extends Packp2 {\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
67 |
"public String toString() { return \"Packp\"; } }\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
68 |
"\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
69 |
"class Packp2 implements Supplier<Integer> {" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
70 |
"public Integer get() { return 5; }}\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
71 |
"\n" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
72 |
"class MyList extends ArrayList<Integer> {}"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
73 |
String tpath = compiler.getPath(path).toString(); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
74 |
setUp(b -> b |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
75 |
.remoteVMOptions("--class-path", tpath) |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
76 |
.compilerOptions("--class-path", tpath)); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
77 |
} |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
78 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
79 |
public void testExternal() { |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
80 |
assertEval("import static priv.GetPriv.*;"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
81 |
VarSnippet down = varKey(assertEval("down()", "Packp")); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
82 |
assertEquals(down.typeName(), "priv.Packp"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
83 |
assertEval(down.name() + ".get()", "5"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
84 |
VarSnippet list = varKey(assertEval("list()", "[]")); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
85 |
assertEquals(list.typeName(), "priv.MyList"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
86 |
assertEval(list.name() + ".size()", "0"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
87 |
VarSnippet one = varKey(assertEval("priv()", "One")); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
88 |
assertEquals(one.typeName(), "priv.GetPriv.Count"); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47975
diff
changeset
|
89 |
assertEval("var v = down();", "Packp"); |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47975
diff
changeset
|
90 |
assertDeclareFail("v.toString()", "compiler.err.not.def.access.class.intf.cant.access"); |
47975
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
91 |
} |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
92 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
93 |
public void testInternal() { |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
94 |
assertEval( |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
95 |
"class Top {" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
96 |
" private class Inner {" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
97 |
" public String toString() { return \"Inner\"; }" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
98 |
" }" + |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
99 |
" Inner n = new Inner(); }"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
100 |
VarSnippet n = varKey(assertEval("new Top().n", "Inner")); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
101 |
assertEquals(n.typeName(), "Top.Inner"); |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
102 |
} |
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
103 |
|
5e86806f57f9
8190939: JShell: gives a compiler error evaluating an expression of inaccessible type
rfield
parents:
diff
changeset
|
104 |
} |