author | mchung |
Sat, 24 Feb 2018 09:41:42 -0800 | |
changeset 48984 | b5d1fb0701d4 |
parent 48610 | a587f95313f1 |
child 52914 | 4fa75d8ad418 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
33362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
26 |
* @bug 8144903 8171981 8191802 8191842 |
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
27 |
* @summary Tests for determining the type from the expression |
33362 | 28 |
* @build KullaTesting TestingInputStream |
29 |
* @run testng TypeNameTest |
|
30 |
*/ |
|
31 |
||
32 |
import org.testng.annotations.Test; |
|
33 |
||
34 |
import static org.testng.Assert.assertEquals; |
|
35 |
||
36 |
@Test |
|
37 |
public class TypeNameTest extends KullaTesting { |
|
38 |
||
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
39 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
40 |
private void assertType(String expr, String type) { |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
41 |
assertType(expr, type, type); |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
42 |
} |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
43 |
|
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
44 |
private void assertType(String expr, String type, String inferType) { |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
45 |
assertEquals(varKey(assertEval(expr)).typeName(), type); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
46 |
assertInferredType(expr, inferType); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
47 |
} |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
48 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
49 |
public void testTypeInference() { |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
50 |
assertEval("import java.util.List;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
51 |
assertEval("import java.util.ArrayList;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
52 |
assertEval("import java.util.Arrays;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
53 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
54 |
assertType("new Object().getClass().getSuperclass() ", "Class<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
55 |
assertType("new ArrayList().getClass().getSuperclass()", "Class<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
56 |
assertType("new ArrayList().getClass()", "Class<? extends ArrayList>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
57 |
assertType("ArrayList.class", "Class<ArrayList>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
58 |
assertType("ArrayList.class.getSuperclass()", "Class<? super ArrayList>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
59 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
60 |
assertEval("class D<T extends CharSequence> { D<? super T> getS() { return null; } }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
61 |
assertEval("D<?> d = new D<String>();"); |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47216
diff
changeset
|
62 |
assertType("d.getS()", "D<?>"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
63 |
assertType("null", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
64 |
assertType("Class.forName( \"java.util.ArrayList\" )", "Class<?>"); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
65 |
assertType("new ArrayList<Boolean>() {}", "<anonymous class extending ArrayList<Boolean>>", "ArrayList<Boolean>"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
66 |
assertType("new ArrayList<String>().stream()", "java.util.stream.Stream<String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
67 |
assertType("Arrays.asList( 1, 2, 3)", "List<Integer>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
68 |
assertType("new ArrayList().getClass().getClass()", "Class<? extends Class>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
69 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
70 |
assertEval("interface A {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
71 |
assertEval("interface I {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
72 |
assertEval("interface J extends A, I {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
73 |
assertEval("interface K extends A, I {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
74 |
assertEval("class P<T extends A & I> {}"); |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47216
diff
changeset
|
75 |
assertType("(P<?>) null", "P<?>"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
76 |
} |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
77 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
78 |
public void testConditionals() { |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
79 |
assertEval("import java.util.List;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
80 |
assertEval("import java.util.ArrayList;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
81 |
assertEval("import java.util.Arrays;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
82 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
83 |
assertEval("CharSequence cs = \"hi\";"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
84 |
assertEval("String st = \"low\";"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
85 |
assertEval("boolean b;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
86 |
assertType("b? cs : st", "CharSequence"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
87 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
88 |
assertEval("List<String> l1 = Arrays.asList(\"hi\");"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
89 |
assertEval("List<? extends String> l2 = Arrays.asList(\"po\");"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
90 |
assertType("b? l1.get(0) : l2.get(0)", "String"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
91 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
92 |
assertEval("class X {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
93 |
assertEval("class B extends X {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
94 |
assertEval("class C extends X {}"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
95 |
assertType("b? new B() : new C()", "X"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
96 |
} |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
97 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
98 |
public void testJEP286NonDenotable() { |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
99 |
assertEval("import java.util.List;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
100 |
assertEval("import java.util.Arrays;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
101 |
assertEval("import java.util.Iterator;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
102 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
103 |
assertEval("List<? extends String> extString() { return Arrays.asList( \"hi\", \"low\" ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
104 |
assertEval("List<? super String> supString() { return Arrays.asList( \"hi\", \"low\" ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
105 |
assertEval("List<?> unbString() { return Arrays.asList( \"hi\", \"low\" ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
106 |
assertEval("List<? extends String>[] extStringArr() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
107 |
" @SuppressWarnings(\"unchecked\") " + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
108 |
"List<? extends String>[] a = new List[1]; a[0] = Arrays.asList(\"hi\"); return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
109 |
assertEval("List<? super String>[] supStringArr() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
110 |
" @SuppressWarnings(\"unchecked\") " + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
111 |
"List<? super String>[] a = new List[1]; a[0] = Arrays.asList(\"hi\"); return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
112 |
assertEval("List<?>[] unbStringArr() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
113 |
" @SuppressWarnings(\"unchecked\") " + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
114 |
"List<?>[] a = new List[1]; a[0] = Arrays.asList(\"hi\"); return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
115 |
assertEval("Iterable<? extends List<? extends String>> extStringIter() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
116 |
"return Arrays.asList( Arrays.asList( \"hi\" ) ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
117 |
assertEval("Iterable<? extends List<? super String>> supStringIter() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
118 |
"return Arrays.asList( Arrays.asList( \"hi\" ) ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
119 |
assertEval("Iterable<? extends List<?>> unbStringIter() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
120 |
"return Arrays.asList( Arrays.asList( \"hi\" ) ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
121 |
assertType("extString()", "List<? extends String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
122 |
assertType("extString().get(0)", "String"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
123 |
assertType("supString()", "List<? super String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
124 |
assertType("supString().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
125 |
assertType("unbString()", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
126 |
assertType("unbString().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
127 |
assertType("supStringArr()", "List<? super String>[]"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
128 |
assertType("supStringArr()[0]", "List<? super String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
129 |
assertType("supStringArr()[0].get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
130 |
assertType("unbStringArr()", "List<?>[]"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
131 |
assertType("unbStringArr()[0]", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
132 |
assertType("unbStringArr()[0].get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
133 |
assertType("extStringIter()", "Iterable<? extends List<? extends String>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
134 |
assertType("extStringIter().iterator()", "Iterator<? extends List<? extends String>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
135 |
assertType("extStringIter().iterator().next()", "List<? extends String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
136 |
assertType("extStringIter().iterator().next().get(0)", "String"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
137 |
assertType("supStringIter()", "Iterable<? extends List<? super String>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
138 |
assertType("supStringIter().iterator()", "Iterator<? extends List<? super String>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
139 |
assertType("supStringIter().iterator().next()", "List<? super String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
140 |
assertType("supStringIter().iterator().next().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
141 |
assertType("unbStringIter()", "Iterable<? extends List<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
142 |
assertType("unbStringIter().iterator()", "Iterator<? extends List<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
143 |
assertType("unbStringIter().iterator().next()", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
144 |
assertType("unbStringIter().iterator().next().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
145 |
} |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
146 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
147 |
public void testJEP286NonDenotable2() { |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
148 |
assertEval("import java.util.List;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
149 |
assertEval("import java.util.Arrays;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
150 |
assertEval("import java.lang.reflect.Array;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
151 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
152 |
assertEval("<Z extends Comparable<Z>> List<? extends Z> extFbound() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
153 |
"return Arrays.asList( (Z)null ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
154 |
assertEval("<Z extends Comparable<Z>> List<? super Z> supFbound() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
155 |
"return Arrays.asList( (Z)null ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
156 |
assertEval("<Z extends Comparable<Z>> List<? extends Z>[] extFboundArr() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
157 |
"@SuppressWarnings(\"unchecked\")" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
158 |
"List<? extends Z>[] a = new List[1]; a[0] = Arrays.asList( (Z)null ); return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
159 |
assertEval("<Z extends Comparable<Z>> List<? super Z>[] supFboundArr() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
160 |
"@SuppressWarnings(\"unchecked\")" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
161 |
"List<? super Z>[] a = new List[1]; a[0] = Arrays.asList( (Z)null ); return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
162 |
assertEval("<Z extends Comparable<Z>> Iterable<? extends List<? extends Z>> extFboundIter() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
163 |
"return Arrays.asList( Arrays.asList( (Z)null ) ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
164 |
assertEval("<Z extends Comparable<Z>> Iterable<? extends List<? super Z>> supFboundIter() {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
165 |
"return Arrays.asList( Arrays.asList( (Z)null ) ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
166 |
assertEval("<Z> List<Z> listOf(Z z) { return Arrays.asList( z ); }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
167 |
assertEval("<Z> Z[] arrayOf(Z z) {" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
168 |
"@SuppressWarnings(\"unchecked\")" + |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
169 |
"final Z[] a = (Z[]) Array.newInstance(z.getClass(), 1); a[0] = z; return a; }"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
170 |
assertType("extFbound()", "List<? extends Comparable<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
171 |
assertType("extFbound().get(0)", "Comparable<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
172 |
assertType("supFbound()", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
173 |
assertType("supFbound().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
174 |
assertType("extFboundArr()", "List<? extends Comparable<?>>[]"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
175 |
assertType("extFboundArr()[0]", "List<? extends Comparable<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
176 |
assertType("extFboundArr()[0].get(0)", "Comparable<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
177 |
assertType("supFboundArr()", "List<?>[]"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
178 |
assertType("supFboundArr()[0]", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
179 |
assertType("supFboundArr()[0].get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
180 |
assertType("extFboundIter()", "Iterable<? extends List<? extends Comparable<?>>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
181 |
assertType("extFboundIter().iterator()", "java.util.Iterator<? extends List<? extends Comparable<?>>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
182 |
assertType("extFboundIter().iterator().next()", "List<? extends Comparable<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
183 |
assertType("extFboundIter().iterator().next().get(0)", "Comparable<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
184 |
assertType("supFboundIter()", "Iterable<? extends List<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
185 |
assertType("supFboundIter().iterator()", "java.util.Iterator<? extends List<?>>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
186 |
assertType("supFboundIter().iterator().next()", "List<?>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
187 |
assertType("supFboundIter().iterator().next().get(0)", "Object"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
188 |
assertType("listOf(23)", "List<Integer>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
189 |
assertType("listOf(true)", "List<Boolean>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
190 |
assertType("listOf(true).get(0)", "Boolean"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
191 |
assertType("arrayOf(99)", "Integer[]"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
192 |
assertType("arrayOf(99)[0]", "Integer"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
193 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
194 |
assertEval("<Z> Z choose(Z z1, Z z2) { return z1; }"); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
195 |
assertType("choose(1, 1L);", "Number&Comparable<? extends Number&Comparable<?>>", "Object"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
196 |
} |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
197 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
198 |
public void testVariableTypeName() { |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
199 |
assertType("\"x\"", "String"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
200 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
201 |
assertType("java.util.regex.Pattern.compile(\"x\")", "java.util.regex.Pattern"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
202 |
assertEval("import java.util.regex.*;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
203 |
assertType("java.util.regex.Pattern.compile(\"x\")", "Pattern"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
204 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
205 |
assertType("new java.util.ArrayList()", "java.util.ArrayList"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
206 |
assertEval("import java.util.ArrayList;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
207 |
assertType("new java.util.ArrayList()", "ArrayList"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
208 |
|
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
209 |
assertType("java.util.Locale.Category.FORMAT", "java.util.Locale.Category"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
210 |
assertEval("import static java.util.Locale.Category;"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
211 |
assertType("java.util.Locale.Category.FORMAT", "Category"); |
33362 | 212 |
} |
213 |
||
214 |
public void testReplNestedClassName() { |
|
215 |
assertEval("class D { static class E {} }"); |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
216 |
assertType("new D.E();", "D.E"); |
33362 | 217 |
} |
218 |
||
219 |
public void testAnonymousClassName() { |
|
220 |
assertEval("class C {}"); |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
221 |
assertType("new C();", "C"); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
222 |
assertType("new C() { int x; };", "<anonymous class extending C>", "C"); |
33362 | 223 |
} |
224 |
||
225 |
public void testCapturedTypeName() { |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
226 |
assertType("\"\".getClass();", "Class<? extends String>"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
227 |
assertType("\"\".getClass().getEnumConstants();", "String[]"); |
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
228 |
} |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
229 |
|
33362 | 230 |
public void testJavaLang() { |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
231 |
assertType("\"\";", "String"); |
33362 | 232 |
} |
233 |
||
234 |
public void testNotOverEagerPackageEating() { |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
235 |
assertType("\"\".getClass().getDeclaredMethod(\"hashCode\");", "java.lang.reflect.Method"); |
33362 | 236 |
} |
237 |
||
238 |
public void testBounds() { |
|
239 |
assertEval("java.util.List<? extends String> list1 = java.util.Arrays.asList(\"\");"); |
|
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
240 |
assertType("list1.iterator().next()", "String"); |
33362 | 241 |
assertEval("java.util.List<? super String> list2 = java.util.Arrays.asList(\"\");"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
242 |
assertType("list2.iterator().next()", "Object"); |
33362 | 243 |
assertEval("java.util.List<?> list3 = java.util.Arrays.asList(\"\");"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
244 |
assertType("list3.iterator().next()", "Object"); |
33362 | 245 |
assertEval("class Test1<X extends CharSequence> { public X get() { return null; } }"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
246 |
assertEval("Test1<?> test1 = new Test1<>();"); |
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
247 |
assertType("test1.get()", "CharSequence"); |
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
248 |
assertEval("class Test2<X extends Number & CharSequence> { public X get() { return null; } }"); |
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
249 |
assertEval("Test2<?> test2 = new Test2<>();"); |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
47959
diff
changeset
|
250 |
assertType("test2.get()", "Number&CharSequence", "Object"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
251 |
assertEval("class Test3<T> { T[][] get() { return null; } }"); |
34750
36d62753f5da
8144903: JShell: determine incorrectly the type of the expression which is array type of captured type
rfield
parents:
33362
diff
changeset
|
252 |
assertEval("Test3<? extends String> test3 = new Test3<>();"); |
43134
006808ae5f6e
8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents:
34750
diff
changeset
|
253 |
assertType("test3.get()", "String[][]"); |
33362 | 254 |
} |
255 |
} |