author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58521 | 55d2e10ea134 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
28 |
import java.lang.ref.SoftReference; |
14719
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
29 |
import java.util.HashSet; |
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
30 |
import java.util.HashMap; |
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
31 |
import java.util.Locale; |
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
32 |
import java.util.Map; |
41526
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
33 |
import java.util.Optional; |
14719
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
34 |
import java.util.Set; |
cd65a651beb3
8004068: Fix build problems caused by on-demand imports
jjg
parents:
14547
diff
changeset
|
35 |
import java.util.WeakHashMap; |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
36 |
import java.util.function.BiPredicate; |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
37 |
import java.util.function.Function; |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
38 |
import java.util.stream.Collector; |
10 | 39 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
40 |
import javax.tools.JavaFileObject; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
41 |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
42 |
import com.sun.tools.javac.code.Attribute.RetentionPolicy; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
43 |
import com.sun.tools.javac.code.Lint.LintCategory; |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47959
diff
changeset
|
44 |
import com.sun.tools.javac.code.Source.Feature; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
45 |
import com.sun.tools.javac.code.Type.UndetVar.InferenceBound; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
46 |
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
47 |
import com.sun.tools.javac.comp.AttrContext; |
10 | 48 |
import com.sun.tools.javac.comp.Check; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
49 |
import com.sun.tools.javac.comp.Enter; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
50 |
import com.sun.tools.javac.comp.Env; |
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
51 |
import com.sun.tools.javac.comp.LambdaToMethod; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
52 |
import com.sun.tools.javac.jvm.ClassFile; |
14258 | 53 |
import com.sun.tools.javac.util.*; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24397
diff
changeset
|
54 |
|
14258 | 55 |
import static com.sun.tools.javac.code.BoundKind.*; |
56 |
import static com.sun.tools.javac.code.Flags.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27125
diff
changeset
|
57 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
58 |
import static com.sun.tools.javac.code.Scope.*; |
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
59 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14258 | 60 |
import static com.sun.tools.javac.code.Symbol.*; |
10 | 61 |
import static com.sun.tools.javac.code.Type.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
62 |
import static com.sun.tools.javac.code.TypeTag.*; |
16300 | 63 |
import static com.sun.tools.javac.jvm.ClassFile.externalize; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
64 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
10 | 65 |
|
66 |
/** |
|
67 |
* Utility class containing various operations on types. |
|
68 |
* |
|
69 |
* <p>Unless other names are more illustrative, the following naming |
|
70 |
* conventions should be observed in this file: |
|
71 |
* |
|
72 |
* <dl> |
|
73 |
* <dt>t</dt> |
|
74 |
* <dd>If the first argument to an operation is a type, it should be named t.</dd> |
|
75 |
* <dt>s</dt> |
|
76 |
* <dd>Similarly, if the second argument to an operation is a type, it should be named s.</dd> |
|
77 |
* <dt>ts</dt> |
|
78 |
* <dd>If an operations takes a list of types, the first should be named ts.</dd> |
|
79 |
* <dt>ss</dt> |
|
80 |
* <dd>A second list of types should be named ss.</dd> |
|
81 |
* </dl> |
|
82 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5654
diff
changeset
|
83 |
* <p><b>This is NOT part of any supported API. |
10 | 84 |
* If you write code that depends on this, you do so at your own risk. |
85 |
* This code and its internal interfaces are subject to change or |
|
86 |
* deletion without notice.</b> |
|
87 |
*/ |
|
88 |
public class Types { |
|
22163 | 89 |
protected static final Context.Key<Types> typesKey = new Context.Key<>(); |
10 | 90 |
|
91 |
final Symtab syms; |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1469
diff
changeset
|
92 |
final JavacMessages messages; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
93 |
final Names names; |
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
94 |
final boolean allowDefaultMethods; |
42819
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
41862
diff
changeset
|
95 |
final boolean mapCapturesToBounds; |
10 | 96 |
final Check chk; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
97 |
final Enter enter; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
98 |
JCDiagnostic.Factory diags; |
10 | 99 |
List<Warner> warnStack = List.nil(); |
100 |
final Name capturedName; |
|
101 |
||
14547 | 102 |
public final Warner noWarnings; |
103 |
||
10 | 104 |
// <editor-fold defaultstate="collapsed" desc="Instantiating"> |
105 |
public static Types instance(Context context) { |
|
106 |
Types instance = context.get(typesKey); |
|
107 |
if (instance == null) |
|
108 |
instance = new Types(context); |
|
109 |
return instance; |
|
110 |
} |
|
111 |
||
112 |
protected Types(Context context) { |
|
113 |
context.put(typesKey, this); |
|
114 |
syms = Symtab.instance(context); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
115 |
names = Names.instance(context); |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
116 |
Source source = Source.instance(context); |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47959
diff
changeset
|
117 |
allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47959
diff
changeset
|
118 |
mapCapturesToBounds = Feature.MAP_CAPTURES_TO_BOUNDS.allowedInSource(source); |
10 | 119 |
chk = Check.instance(context); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
120 |
enter = Enter.instance(context); |
10 | 121 |
capturedName = names.fromString("<captured wildcard>"); |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1469
diff
changeset
|
122 |
messages = JavacMessages.instance(context); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
123 |
diags = JCDiagnostic.Factory.instance(context); |
14547 | 124 |
noWarnings = new Warner(null); |
10 | 125 |
} |
126 |
// </editor-fold> |
|
127 |
||
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
128 |
// <editor-fold defaultstate="collapsed" desc="bounds"> |
10 | 129 |
/** |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
130 |
* Get a wildcard's upper bound, returning non-wildcards unchanged. |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
131 |
* @param t a type argument, either a wildcard or a type |
10 | 132 |
*/ |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
133 |
public Type wildUpperBound(Type t) { |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
134 |
if (t.hasTag(WILDCARD)) { |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
135 |
WildcardType w = (WildcardType) t; |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
136 |
if (w.isSuperBound()) |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
137 |
return w.bound == null ? syms.objectType : w.bound.getUpperBound(); |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
138 |
else |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
139 |
return wildUpperBound(w.type); |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
140 |
} |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
141 |
else return t; |
10 | 142 |
} |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
143 |
|
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
144 |
/** |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
145 |
* Get a capture variable's upper bound, returning other types unchanged. |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
146 |
* @param t a type |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
147 |
*/ |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
148 |
public Type cvarUpperBound(Type t) { |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
149 |
if (t.hasTag(TYPEVAR)) { |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
150 |
TypeVar v = (TypeVar) t; |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
151 |
return v.isCaptured() ? cvarUpperBound(v.getUpperBound()) : v; |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
152 |
} |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
153 |
else return t; |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
154 |
} |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
155 |
|
10 | 156 |
/** |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
157 |
* Get a wildcard's lower bound, returning non-wildcards unchanged. |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
158 |
* @param t a type argument, either a wildcard or a type |
10 | 159 |
*/ |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
160 |
public Type wildLowerBound(Type t) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
161 |
if (t.hasTag(WILDCARD)) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
162 |
WildcardType w = (WildcardType) t; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
163 |
return w.isExtendsBound() ? syms.botType : wildLowerBound(w.type); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
164 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
165 |
else return t; |
10 | 166 |
} |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
167 |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
168 |
/** |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
169 |
* Get a capture variable's lower bound, returning other types unchanged. |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
170 |
* @param t a type |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
171 |
*/ |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
172 |
public Type cvarLowerBound(Type t) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
173 |
if (t.hasTag(TYPEVAR) && ((TypeVar) t).isCaptured()) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
174 |
return cvarLowerBound(t.getLowerBound()); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
175 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
176 |
else return t; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
177 |
} |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
178 |
|
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
179 |
/** |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
180 |
* Recursively skip type-variables until a class/array type is found; capture conversion is then |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
181 |
* (optionally) applied to the resulting type. This is useful for i.e. computing a site that is |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
182 |
* suitable for a method lookup. |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
183 |
*/ |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
184 |
public Type skipTypeVars(Type site, boolean capture) { |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
185 |
while (site.hasTag(TYPEVAR)) { |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
186 |
site = site.getUpperBound(); |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
187 |
} |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
188 |
return capture ? capture(site) : site; |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
189 |
} |
10 | 190 |
// </editor-fold> |
191 |
||
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
192 |
// <editor-fold defaultstate="collapsed" desc="projections"> |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
193 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
194 |
/** |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
195 |
* A projection kind. See {@link TypeProjection} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
196 |
*/ |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
197 |
enum ProjectionKind { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
198 |
UPWARDS() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
199 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
200 |
ProjectionKind complement() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
201 |
return DOWNWARDS; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
202 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
203 |
}, |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
204 |
DOWNWARDS() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
205 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
206 |
ProjectionKind complement() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
207 |
return UPWARDS; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
208 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
209 |
}; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
210 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
211 |
abstract ProjectionKind complement(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
212 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
213 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
214 |
/** |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
215 |
* This visitor performs upwards and downwards projections on types. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
216 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
217 |
* A projection is defined as a function that takes a type T, a set of type variables V and that |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
218 |
* produces another type S. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
219 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
220 |
* An upwards projection maps a type T into a type S such that (i) T has no variables in V, |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
221 |
* and (ii) S is an upper bound of T. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
222 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
223 |
* A downwards projection maps a type T into a type S such that (i) T has no variables in V, |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
224 |
* and (ii) S is a lower bound of T. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
225 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
226 |
* Note that projections are only allowed to touch variables in V. Theferore it is possible for |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
227 |
* a projection to leave its input type unchanged if it does not contain any variables in V. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
228 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
229 |
* Moreover, note that while an upwards projection is always defined (every type as an upper bound), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
230 |
* a downwards projection is not always defined. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
231 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
232 |
* Examples: |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
233 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
234 |
* {@code upwards(List<#CAP1>, [#CAP1]) = List<? extends String>, where #CAP1 <: String } |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
235 |
* {@code downwards(List<#CAP2>, [#CAP2]) = List<? super String>, where #CAP2 :> String } |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
236 |
* {@code upwards(List<#CAP1>, [#CAP2]) = List<#CAP1> } |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
237 |
* {@code downwards(List<#CAP1>, [#CAP1]) = not defined } |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
238 |
*/ |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
239 |
class TypeProjection extends TypeMapping<ProjectionKind> { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
240 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
241 |
List<Type> vars; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
242 |
Set<Type> seen = new HashSet<>(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
243 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
244 |
public TypeProjection(List<Type> vars) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
245 |
this.vars = vars; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
246 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
247 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
248 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
249 |
public Type visitClassType(ClassType t, ProjectionKind pkind) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
250 |
if (t.isCompound()) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
251 |
List<Type> components = directSupertypes(t); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
252 |
List<Type> components1 = components.map(c -> c.map(this, pkind)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
253 |
if (components == components1) return t; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
254 |
else return makeIntersectionType(components1); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
255 |
} else { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
256 |
Type outer = t.getEnclosingType(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
257 |
Type outer1 = visit(outer, pkind); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
258 |
List<Type> typarams = t.getTypeArguments(); |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
259 |
List<Type> formals = t.tsym.type.getTypeArguments(); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
260 |
ListBuffer<Type> typarams1 = new ListBuffer<>(); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
261 |
boolean changed = false; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
262 |
for (Type actual : typarams) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
263 |
Type t2 = mapTypeArgument(t, formals.head.getUpperBound(), actual, pkind); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
264 |
if (t2.hasTag(BOT)) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
265 |
//not defined |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
266 |
return syms.botType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
267 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
268 |
typarams1.add(t2); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
269 |
changed |= actual != t2; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
270 |
formals = formals.tail; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
271 |
} |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
272 |
if (outer1 == outer && !changed) return t; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
273 |
else return new ClassType(outer1, typarams1.toList(), t.tsym, t.getMetadata()) { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
274 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
275 |
protected boolean needsStripping() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
276 |
return true; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
277 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
278 |
}; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
279 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
280 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
281 |
|
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
282 |
@Override |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
283 |
public Type visitArrayType(ArrayType t, ProjectionKind s) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
284 |
Type elemtype = t.elemtype; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
285 |
Type elemtype1 = visit(elemtype, s); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
286 |
if (elemtype1 == elemtype) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
287 |
return t; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
288 |
} else if (elemtype1.hasTag(BOT)) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
289 |
//undefined |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
290 |
return syms.botType; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
291 |
} else { |
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
292 |
return new ArrayType(elemtype1, t.tsym, t.metadata) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
293 |
@Override |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
294 |
protected boolean needsStripping() { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
295 |
return true; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
296 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
297 |
}; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
298 |
} |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
299 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
300 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
301 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
302 |
public Type visitTypeVar(TypeVar t, ProjectionKind pkind) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
303 |
if (vars.contains(t)) { |
47458
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
304 |
if (seen.add(t)) { |
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
305 |
try { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
306 |
final Type bound; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
307 |
switch (pkind) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
308 |
case UPWARDS: |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
309 |
bound = t.getUpperBound(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
310 |
break; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
311 |
case DOWNWARDS: |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
312 |
bound = (t.getLowerBound() == null) ? |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
313 |
syms.botType : |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
314 |
t.getLowerBound(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
315 |
break; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
316 |
default: |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
317 |
Assert.error(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
318 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
319 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
320 |
return bound.map(this, pkind); |
47458
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
321 |
} finally { |
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
322 |
seen.remove(t); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
323 |
} |
47458
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
324 |
} else { |
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
325 |
//cycle |
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
326 |
return pkind == ProjectionKind.UPWARDS ? |
945935416d7c
8189838: Stack overflow when computing upward projection of an intersection type with fbounds
mcimadamore
parents:
47268
diff
changeset
|
327 |
syms.objectType : syms.botType; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
328 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
329 |
} else { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
330 |
return t; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
331 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
332 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
333 |
|
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
334 |
private Type mapTypeArgument(Type site, Type declaredBound, Type t, ProjectionKind pkind) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
335 |
return t.containsAny(vars) ? |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
336 |
t.map(new TypeArgumentProjection(site, declaredBound), pkind) : |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
337 |
t; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
338 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
339 |
|
47959
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
340 |
class TypeArgumentProjection extends TypeMapping<ProjectionKind> { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
341 |
|
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
342 |
Type site; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
343 |
Type declaredBound; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
344 |
|
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
345 |
TypeArgumentProjection(Type site, Type declaredBound) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
346 |
this.site = site; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
347 |
this.declaredBound = declaredBound; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
348 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
349 |
|
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
350 |
@Override |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
351 |
public Type visitType(Type t, ProjectionKind pkind) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
352 |
//type argument is some type containing restricted vars |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
353 |
if (pkind == ProjectionKind.DOWNWARDS) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
354 |
//not defined |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
355 |
return syms.botType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
356 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
357 |
Type upper = t.map(TypeProjection.this, ProjectionKind.UPWARDS); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
358 |
Type lower = t.map(TypeProjection.this, ProjectionKind.DOWNWARDS); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
359 |
List<Type> formals = site.tsym.type.getTypeArguments(); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
360 |
BoundKind bk; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
361 |
Type bound; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
362 |
if (!isSameType(upper, syms.objectType) && |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
363 |
(declaredBound.containsAny(formals) || |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
364 |
!isSubtype(declaredBound, upper))) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
365 |
bound = upper; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
366 |
bk = EXTENDS; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
367 |
} else if (!lower.hasTag(BOT)) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
368 |
bound = lower; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
369 |
bk = SUPER; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
370 |
} else { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
371 |
bound = syms.objectType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
372 |
bk = UNBOUND; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
373 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
374 |
return makeWildcard(bound, bk); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
375 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
376 |
|
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
377 |
@Override |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
378 |
public Type visitWildcardType(WildcardType wt, ProjectionKind pkind) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
379 |
//type argument is some wildcard whose bound contains restricted vars |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
380 |
Type bound = syms.botType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
381 |
BoundKind bk = wt.kind; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
382 |
switch (wt.kind) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
383 |
case EXTENDS: |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
384 |
bound = wt.type.map(TypeProjection.this, pkind); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
385 |
if (bound.hasTag(BOT)) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
386 |
return syms.botType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
387 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
388 |
break; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
389 |
case SUPER: |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
390 |
bound = wt.type.map(TypeProjection.this, pkind.complement()); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
391 |
if (bound.hasTag(BOT)) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
392 |
bound = syms.objectType; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
393 |
bk = UNBOUND; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
394 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
395 |
break; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
396 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
397 |
return makeWildcard(bound, bk); |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
398 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
399 |
|
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
400 |
private Type makeWildcard(Type bound, BoundKind bk) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
401 |
return new WildcardType(bound, bk, syms.boundClass) { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
402 |
@Override |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
403 |
protected boolean needsStripping() { |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
404 |
return true; |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
405 |
} |
5dd899009525
8191802: Upward projection result is A<? extends Number> instead of A<? super Integer>
mcimadamore
parents:
47458
diff
changeset
|
406 |
}; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
407 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
408 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
409 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
410 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
411 |
/** |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
412 |
* Computes an upward projection of given type, and vars. See {@link TypeProjection}. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
413 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
414 |
* @param t the type to be projected |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
415 |
* @param vars the set of type variables to be mapped |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
416 |
* @return the type obtained as result of the projection |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
417 |
*/ |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
418 |
public Type upward(Type t, List<Type> vars) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
419 |
return t.map(new TypeProjection(vars), ProjectionKind.UPWARDS); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
420 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
421 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
422 |
/** |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
423 |
* Computes the set of captured variables mentioned in a given type. See {@link CaptureScanner}. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
424 |
* This routine is typically used to computed the input set of variables to be used during |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
425 |
* an upwards projection (see {@link Types#upward(Type, List)}). |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
426 |
* |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
427 |
* @param t the type where occurrences of captured variables have to be found |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
428 |
* @return the set of captured variables found in t |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
429 |
*/ |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
430 |
public List<Type> captures(Type t) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
431 |
CaptureScanner cs = new CaptureScanner(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
432 |
Set<Type> captures = new HashSet<>(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
433 |
cs.visit(t, captures); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
434 |
return List.from(captures); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
435 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
436 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
437 |
/** |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
438 |
* This visitor scans a type recursively looking for occurrences of captured type variables. |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
439 |
*/ |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
440 |
class CaptureScanner extends SimpleVisitor<Void, Set<Type>> { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
441 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
442 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
443 |
public Void visitType(Type t, Set<Type> types) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
444 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
445 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
446 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
447 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
448 |
public Void visitClassType(ClassType t, Set<Type> seen) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
449 |
if (t.isCompound()) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
450 |
directSupertypes(t).forEach(s -> visit(s, seen)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
451 |
} else { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
452 |
t.allparams().forEach(ta -> visit(ta, seen)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
453 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
454 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
455 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
456 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
457 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
458 |
public Void visitArrayType(ArrayType t, Set<Type> seen) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
459 |
return visit(t.elemtype, seen); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
460 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
461 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
462 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
463 |
public Void visitWildcardType(WildcardType t, Set<Type> seen) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
464 |
visit(t.type, seen); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
465 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
466 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
467 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
468 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
469 |
public Void visitTypeVar(TypeVar t, Set<Type> seen) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
470 |
if ((t.tsym.flags() & Flags.SYNTHETIC) != 0 && seen.add(t)) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
471 |
visit(t.getUpperBound(), seen); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
472 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
473 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
474 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
475 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
476 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
477 |
public Void visitCapturedType(CapturedType t, Set<Type> seen) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
478 |
if (seen.add(t)) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
479 |
visit(t.getUpperBound(), seen); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
480 |
visit(t.getLowerBound(), seen); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
481 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
482 |
return null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
483 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
484 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
485 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
486 |
// </editor-fold> |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
487 |
|
10 | 488 |
// <editor-fold defaultstate="collapsed" desc="isUnbounded"> |
489 |
/** |
|
490 |
* Checks that all the arguments to a class are unbounded |
|
491 |
* wildcards or something else that doesn't make any restrictions |
|
492 |
* on the arguments. If a class isUnbounded, a raw super- or |
|
493 |
* subclass can be cast to it without a warning. |
|
494 |
* @param t a type |
|
495 |
* @return true iff the given type is unbounded or raw |
|
496 |
*/ |
|
497 |
public boolean isUnbounded(Type t) { |
|
498 |
return isUnbounded.visit(t); |
|
499 |
} |
|
500 |
// where |
|
501 |
private final UnaryVisitor<Boolean> isUnbounded = new UnaryVisitor<Boolean>() { |
|
502 |
||
503 |
public Boolean visitType(Type t, Void ignored) { |
|
504 |
return true; |
|
505 |
} |
|
506 |
||
507 |
@Override |
|
508 |
public Boolean visitClassType(ClassType t, Void ignored) { |
|
509 |
List<Type> parms = t.tsym.type.allparams(); |
|
510 |
List<Type> args = t.allparams(); |
|
511 |
while (parms.nonEmpty()) { |
|
512 |
WildcardType unb = new WildcardType(syms.objectType, |
|
513 |
BoundKind.UNBOUND, |
|
514 |
syms.boundClass, |
|
24396 | 515 |
(TypeVar)parms.head); |
10 | 516 |
if (!containsType(args.head, unb)) |
517 |
return false; |
|
518 |
parms = parms.tail; |
|
519 |
args = args.tail; |
|
520 |
} |
|
521 |
return true; |
|
522 |
} |
|
523 |
}; |
|
524 |
// </editor-fold> |
|
525 |
||
526 |
// <editor-fold defaultstate="collapsed" desc="asSub"> |
|
527 |
/** |
|
528 |
* Return the least specific subtype of t that starts with symbol |
|
529 |
* sym. If none exists, return null. The least specific subtype |
|
530 |
* is determined as follows: |
|
531 |
* |
|
532 |
* <p>If there is exactly one parameterized instance of sym that is a |
|
533 |
* subtype of t, that parameterized instance is returned.<br> |
|
534 |
* Otherwise, if the plain type or raw type `sym' is a subtype of |
|
535 |
* type t, the type `sym' itself is returned. Otherwise, null is |
|
536 |
* returned. |
|
537 |
*/ |
|
538 |
public Type asSub(Type t, Symbol sym) { |
|
539 |
return asSub.visit(t, sym); |
|
540 |
} |
|
541 |
// where |
|
542 |
private final SimpleVisitor<Type,Symbol> asSub = new SimpleVisitor<Type,Symbol>() { |
|
543 |
||
544 |
public Type visitType(Type t, Symbol sym) { |
|
545 |
return null; |
|
546 |
} |
|
547 |
||
548 |
@Override |
|
549 |
public Type visitClassType(ClassType t, Symbol sym) { |
|
550 |
if (t.tsym == sym) |
|
551 |
return t; |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
552 |
Type base = asSuper(sym.type, t.tsym); |
10 | 553 |
if (base == null) |
554 |
return null; |
|
22163 | 555 |
ListBuffer<Type> from = new ListBuffer<>(); |
556 |
ListBuffer<Type> to = new ListBuffer<>(); |
|
10 | 557 |
try { |
558 |
adapt(base, t, from, to); |
|
559 |
} catch (AdaptFailure ex) { |
|
560 |
return null; |
|
561 |
} |
|
562 |
Type res = subst(sym.type, from.toList(), to.toList()); |
|
563 |
if (!isSubtype(res, t)) |
|
564 |
return null; |
|
22163 | 565 |
ListBuffer<Type> openVars = new ListBuffer<>(); |
10 | 566 |
for (List<Type> l = sym.type.allparams(); |
567 |
l.nonEmpty(); l = l.tail) |
|
568 |
if (res.contains(l.head) && !t.contains(l.head)) |
|
569 |
openVars.append(l.head); |
|
570 |
if (openVars.nonEmpty()) { |
|
571 |
if (t.isRaw()) { |
|
572 |
// The subtype of a raw type is raw |
|
573 |
res = erasure(res); |
|
574 |
} else { |
|
575 |
// Unbound type arguments default to ? |
|
576 |
List<Type> opens = openVars.toList(); |
|
22163 | 577 |
ListBuffer<Type> qs = new ListBuffer<>(); |
10 | 578 |
for (List<Type> iter = opens; iter.nonEmpty(); iter = iter.tail) { |
24396 | 579 |
qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
580 |
syms.boundClass, (TypeVar) iter.head)); |
10 | 581 |
} |
582 |
res = subst(res, opens, qs.toList()); |
|
583 |
} |
|
584 |
} |
|
585 |
return res; |
|
586 |
} |
|
587 |
||
588 |
@Override |
|
589 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
|
590 |
return t; |
|
591 |
} |
|
592 |
}; |
|
593 |
// </editor-fold> |
|
594 |
||
595 |
// <editor-fold defaultstate="collapsed" desc="isConvertible"> |
|
596 |
/** |
|
10452
c8f32009b413
7085024: internal error; cannot instantiate Foo
mcimadamore
parents:
9812
diff
changeset
|
597 |
* Is t a subtype of or convertible via boxing/unboxing |
c8f32009b413
7085024: internal error; cannot instantiate Foo
mcimadamore
parents:
9812
diff
changeset
|
598 |
* conversion to s? |
10 | 599 |
*/ |
600 |
public boolean isConvertible(Type t, Type s, Warner warn) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
601 |
if (t.hasTag(ERROR)) { |
10452
c8f32009b413
7085024: internal error; cannot instantiate Foo
mcimadamore
parents:
9812
diff
changeset
|
602 |
return true; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
603 |
} |
10 | 604 |
boolean tPrimitive = t.isPrimitive(); |
605 |
boolean sPrimitive = s.isPrimitive(); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
606 |
if (tPrimitive == sPrimitive) { |
10 | 607 |
return isSubtypeUnchecked(t, s, warn); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
608 |
} |
45754
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
609 |
boolean tUndet = t.hasTag(UNDETVAR); |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
610 |
boolean sUndet = s.hasTag(UNDETVAR); |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
611 |
|
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
612 |
if (tUndet || sUndet) { |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
613 |
return tUndet ? |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
614 |
isSubtype(t, boxedTypeOrType(s)) : |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
615 |
isSubtype(boxedTypeOrType(t), s); |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
616 |
} |
740593904730
8182649: Unable to integrate due to compilation error
vromero
parents:
45504
diff
changeset
|
617 |
|
10 | 618 |
return tPrimitive |
619 |
? isSubtype(boxedClass(t).type, s) |
|
620 |
: isSubtype(unboxedType(t), s); |
|
621 |
} |
|
622 |
||
623 |
/** |
|
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
624 |
* Is t a subtype of or convertible via boxing/unboxing |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
625 |
* conversions to s? |
10 | 626 |
*/ |
627 |
public boolean isConvertible(Type t, Type s) { |
|
14547 | 628 |
return isConvertible(t, s, noWarnings); |
10 | 629 |
} |
630 |
// </editor-fold> |
|
631 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
632 |
// <editor-fold defaultstate="collapsed" desc="findSam"> |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
633 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
634 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
635 |
* Exception used to report a function descriptor lookup failure. The exception |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
636 |
* wraps a diagnostic that can be used to generate more details error |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
637 |
* messages. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
638 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
639 |
public static class FunctionDescriptorLookupError extends RuntimeException { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
640 |
private static final long serialVersionUID = 0; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
641 |
|
58350
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
54952
diff
changeset
|
642 |
transient JCDiagnostic diagnostic; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
643 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
644 |
FunctionDescriptorLookupError() { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
645 |
this.diagnostic = null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
646 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
647 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
648 |
FunctionDescriptorLookupError setMessage(JCDiagnostic diag) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
649 |
this.diagnostic = diag; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
650 |
return this; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
651 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
652 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
653 |
public JCDiagnostic getDiagnostic() { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
654 |
return diagnostic; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
655 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
656 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
657 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
658 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
659 |
* A cache that keeps track of function descriptors associated with given |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
660 |
* functional interfaces. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
661 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
662 |
class DescriptorCache { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
663 |
|
22163 | 664 |
private WeakHashMap<TypeSymbol, Entry> _map = new WeakHashMap<>(); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
665 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
666 |
class FunctionDescriptor { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
667 |
Symbol descSym; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
668 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
669 |
FunctionDescriptor(Symbol descSym) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
670 |
this.descSym = descSym; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
671 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
672 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
673 |
public Symbol getSymbol() { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
674 |
return descSym; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
675 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
676 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
677 |
public Type getType(Type site) { |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
678 |
site = removeWildcards(site); |
50636
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
679 |
if (site.isIntersection()) { |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
680 |
IntersectionClassType ict = (IntersectionClassType)site; |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
681 |
for (Type component : ict.getExplicitComponents()) { |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
682 |
if (!chk.checkValidGenericType(component)) { |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
683 |
//if the inferred functional interface type is not well-formed, |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
684 |
//or if it's not a subtype of the original target, issue an error |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
685 |
throw failure(diags.fragment(Fragments.NoSuitableFunctionalIntfInst(site))); |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
686 |
} |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
687 |
} |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
688 |
} else { |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
689 |
if (!chk.checkValidGenericType(site)) { |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
690 |
//if the inferred functional interface type is not well-formed, |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
691 |
//or if it's not a subtype of the original target, issue an error |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
692 |
throw failure(diags.fragment(Fragments.NoSuitableFunctionalIntfInst(site))); |
8a18bcdd75ed
8205052: No compilation error thrown when no valid parameterization exists for functional interface type
vromero
parents:
50213
diff
changeset
|
693 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
694 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
695 |
return memberType(site, descSym); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
696 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
697 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
698 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
699 |
class Entry { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
700 |
final FunctionDescriptor cachedDescRes; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
701 |
final int prevMark; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
702 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
703 |
public Entry(FunctionDescriptor cachedDescRes, |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
704 |
int prevMark) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
705 |
this.cachedDescRes = cachedDescRes; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
706 |
this.prevMark = prevMark; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
707 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
708 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
709 |
boolean matches(int mark) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
710 |
return this.prevMark == mark; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
711 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
712 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
713 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
714 |
FunctionDescriptor get(TypeSymbol origin) throws FunctionDescriptorLookupError { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
715 |
Entry e = _map.get(origin); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
716 |
CompoundScope members = membersClosure(origin.type, false); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
717 |
if (e == null || |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
718 |
!e.matches(members.getMark())) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
719 |
FunctionDescriptor descRes = findDescriptorInternal(origin, members); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
720 |
_map.put(origin, new Entry(descRes, members.getMark())); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
721 |
return descRes; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
722 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
723 |
else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
724 |
return e.cachedDescRes; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
725 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
726 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
727 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
728 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
729 |
* Compute the function descriptor associated with a given functional interface |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
730 |
*/ |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
731 |
public FunctionDescriptor findDescriptorInternal(TypeSymbol origin, |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
732 |
CompoundScope membersCache) throws FunctionDescriptorLookupError { |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
14949
diff
changeset
|
733 |
if (!origin.isInterface() || (origin.flags() & ANNOTATION) != 0) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
734 |
//t must be an interface |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
14949
diff
changeset
|
735 |
throw failure("not.a.functional.intf", origin); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
736 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
737 |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
738 |
final ListBuffer<Symbol> abstracts = new ListBuffer<>(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
739 |
for (Symbol sym : membersCache.getSymbols(new DescriptorFilter(origin))) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
740 |
Type mtype = memberType(origin.type, sym); |
40591
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
741 |
if (abstracts.isEmpty()) { |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
742 |
abstracts.append(sym); |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
743 |
} else if ((sym.name == abstracts.first().name && |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
744 |
overrideEquivalent(mtype, memberType(origin.type, abstracts.first())))) { |
40591
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
745 |
if (!abstracts.stream().filter(msym -> msym.owner.isSubClass(sym.enclClass(), Types.this)) |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
746 |
.map(msym -> memberType(origin.type, msym)) |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
747 |
.anyMatch(abstractMType -> isSubSignature(abstractMType, mtype))) { |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
748 |
abstracts.append(sym); |
8843f886a89f
8047338: javac is not correctly filtering non-members methods to obtain the function descriptor
vromero
parents:
39363
diff
changeset
|
749 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
750 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
751 |
//the target method(s) should be the only abstract members of t |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
14949
diff
changeset
|
752 |
throw failure("not.a.functional.intf.1", origin, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
753 |
diags.fragment(Fragments.IncompatibleAbstracts(Kinds.kindName(origin), origin))); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
754 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
755 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
756 |
if (abstracts.isEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
757 |
//t must define a suitable non-generic method |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
14949
diff
changeset
|
758 |
throw failure("not.a.functional.intf.1", origin, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
759 |
diags.fragment(Fragments.NoAbstracts(Kinds.kindName(origin), origin))); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
760 |
} else if (abstracts.size() == 1) { |
14723
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14719
diff
changeset
|
761 |
return new FunctionDescriptor(abstracts.first()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
762 |
} else { // size > 1 |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
763 |
FunctionDescriptor descRes = mergeDescriptors(origin, abstracts.toList()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
764 |
if (descRes == null) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
765 |
//we can get here if the functional interface is ill-formed |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
766 |
ListBuffer<JCDiagnostic> descriptors = new ListBuffer<>(); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
767 |
for (Symbol desc : abstracts) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
768 |
String key = desc.type.getThrownTypes().nonEmpty() ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
769 |
"descriptor.throws" : "descriptor"; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
770 |
descriptors.append(diags.fragment(key, desc.name, |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
771 |
desc.type.getParameterTypes(), |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
772 |
desc.type.getReturnType(), |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
773 |
desc.type.getThrownTypes())); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
774 |
} |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
775 |
JCDiagnostic msg = |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
776 |
diags.fragment(Fragments.IncompatibleDescsInFunctionalIntf(Kinds.kindName(origin), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
777 |
origin)); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
778 |
JCDiagnostic.MultilineDiagnostic incompatibleDescriptors = |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44186
diff
changeset
|
779 |
new JCDiagnostic.MultilineDiagnostic(msg, descriptors.toList()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
780 |
throw failure(incompatibleDescriptors); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
781 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
782 |
return descRes; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
783 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
784 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
785 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
786 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
787 |
* Compute a synthetic type for the target descriptor given a list |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
788 |
* of override-equivalent methods in the functional interface type. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
789 |
* The resulting method type is a method type that is override-equivalent |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
790 |
* and return-type substitutable with each method in the original list. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
791 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
792 |
private FunctionDescriptor mergeDescriptors(TypeSymbol origin, List<Symbol> methodSyms) { |
41526
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
793 |
return mergeAbstracts(methodSyms, origin.type, false) |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
794 |
.map(bestSoFar -> new FunctionDescriptor(bestSoFar.baseSymbol()) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
795 |
@Override |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
796 |
public Type getType(Type origin) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
797 |
Type mt = memberType(origin, getSymbol()); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
798 |
return createMethodTypeWithThrown(mt, bestSoFar.type.getThrownTypes()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
799 |
} |
41526
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
800 |
}).orElse(null); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
801 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
802 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
803 |
FunctionDescriptorLookupError failure(String msg, Object... args) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
804 |
return failure(diags.fragment(msg, args)); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
805 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
806 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
807 |
FunctionDescriptorLookupError failure(JCDiagnostic diag) { |
50181
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
808 |
return new FunctionDescriptorLookupError().setMessage(diag); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
809 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
810 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
811 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
812 |
private DescriptorCache descCache = new DescriptorCache(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
813 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
814 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
815 |
* Find the method descriptor associated to this class symbol - if the |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
816 |
* symbol 'origin' is not a functional interface, an exception is thrown. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
817 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
818 |
public Symbol findDescriptorSymbol(TypeSymbol origin) throws FunctionDescriptorLookupError { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
819 |
return descCache.get(origin).getSymbol(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
820 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
821 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
822 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
823 |
* Find the type of the method descriptor associated to this class symbol - |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
824 |
* if the symbol 'origin' is not a functional interface, an exception is thrown. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
825 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
826 |
public Type findDescriptorType(Type origin) throws FunctionDescriptorLookupError { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
827 |
return descCache.get(origin.tsym).getType(origin); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
828 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
829 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
830 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
831 |
* Is given type a functional interface? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
832 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
833 |
public boolean isFunctionalInterface(TypeSymbol tsym) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
834 |
try { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
835 |
findDescriptorSymbol(tsym); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
836 |
return true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
837 |
} catch (FunctionDescriptorLookupError ex) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
838 |
return false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
839 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
840 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
841 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
842 |
public boolean isFunctionalInterface(Type site) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
843 |
try { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
844 |
findDescriptorType(site); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
845 |
return true; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
846 |
} catch (FunctionDescriptorLookupError ex) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
847 |
return false; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
848 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15361
diff
changeset
|
849 |
} |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
850 |
|
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
851 |
public Type removeWildcards(Type site) { |
34757
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
852 |
if (site.getTypeArguments().stream().anyMatch(t -> t.hasTag(WILDCARD))) { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
853 |
//compute non-wildcard parameterization - JLS 9.9 |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
854 |
List<Type> actuals = site.getTypeArguments(); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
855 |
List<Type> formals = site.tsym.type.getTypeArguments(); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
856 |
ListBuffer<Type> targs = new ListBuffer<>(); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
857 |
for (Type formal : formals) { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
858 |
Type actual = actuals.head; |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
859 |
Type bound = formal.getUpperBound(); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
860 |
if (actuals.head.hasTag(WILDCARD)) { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
861 |
WildcardType wt = (WildcardType)actual; |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
862 |
//check that bound does not contain other formals |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
863 |
if (bound.containsAny(formals)) { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
864 |
targs.add(wt.type); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
865 |
} else { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
866 |
//compute new type-argument based on declared bound and wildcard bound |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
867 |
switch (wt.kind) { |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
868 |
case UNBOUND: |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
869 |
targs.add(bound); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
870 |
break; |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
871 |
case EXTENDS: |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
872 |
targs.add(glb(bound, wt.type)); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
873 |
break; |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
874 |
case SUPER: |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
875 |
targs.add(wt.type); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
876 |
break; |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
877 |
default: |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
878 |
Assert.error("Cannot get here!"); |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
879 |
} |
16311
1090c7ac6ae2
8008293: Declared bounds not considered when functional interface containing unbound wildcards is instantiated
mcimadamore
parents:
16300
diff
changeset
|
880 |
} |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
881 |
} else { |
34757
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
882 |
//not a wildcard - the new type argument remains unchanged |
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
883 |
targs.add(actual); |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
884 |
} |
34757
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
885 |
actuals = actuals.tail; |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
886 |
} |
34757
85ceb9850b1d
8142876: Javac does not correctly implement wildcards removal from functional interfaces
mcimadamore
parents:
34756
diff
changeset
|
887 |
return subst(site.tsym.type, formals, targs.toList()); |
16292
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
888 |
} else { |
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
889 |
return site; |
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
890 |
} |
3be2cdacb3b3
8006749: compiler does not allow Object protected methods to be used in lambda
mcimadamore
parents:
15718
diff
changeset
|
891 |
} |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
892 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
893 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
894 |
* Create a symbol for a class that implements a given functional interface |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
895 |
* and overrides its functional descriptor. This routine is used for two |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
896 |
* main purposes: (i) checking well-formedness of a functional interface; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
897 |
* (ii) perform functional interface bridge calculation. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
898 |
*/ |
50181
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
899 |
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, Type target, long cflags) { |
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
900 |
if (target == null || target == syms.unknownType) { |
19127
8a0cbd5cb055
8020804: javac crashes when speculative attribution infers intersection type with array component
mcimadamore
parents:
19124
diff
changeset
|
901 |
return null; |
8a0cbd5cb055
8020804: javac crashes when speculative attribution infers intersection type with array component
mcimadamore
parents:
19124
diff
changeset
|
902 |
} |
50181
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
903 |
Symbol descSym = findDescriptorSymbol(target.tsym); |
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
904 |
Type descType = findDescriptorType(target); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
905 |
ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass()); |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29842
diff
changeset
|
906 |
csym.completer = Completer.NULL_COMPLETER; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
907 |
csym.members_field = WriteableScope.create(csym); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
908 |
MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
909 |
csym.members_field.enter(instDescSym); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42819
diff
changeset
|
910 |
Type.ClassType ctype = new Type.ClassType(Type.noType, List.nil(), csym); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
911 |
ctype.supertype_field = syms.objectType; |
50181
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
912 |
ctype.interfaces_field = target.isIntersection() ? |
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
913 |
directSupertypes(target) : |
f854b76b6a0c
8148354: Errors targeting functional interface intersection types
vromero
parents:
48661
diff
changeset
|
914 |
List.of(target); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
915 |
csym.type = ctype; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
916 |
csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
917 |
return csym; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
918 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
919 |
|
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
920 |
/** |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
921 |
* Find the minimal set of methods that are overridden by the functional |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
922 |
* descriptor in 'origin'. All returned methods are assumed to have different |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
923 |
* erased signatures. |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
924 |
*/ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
925 |
public List<Symbol> functionalInterfaceBridges(TypeSymbol origin) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
926 |
Assert.check(isFunctionalInterface(origin)); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
927 |
Symbol descSym = findDescriptorSymbol(origin); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
928 |
CompoundScope members = membersClosure(origin.type, false); |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
929 |
ListBuffer<Symbol> overridden = new ListBuffer<>(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
930 |
outer: for (Symbol m2 : members.getSymbolsByName(descSym.name, bridgeFilter)) { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
931 |
if (m2 == descSym) continue; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
932 |
else if (descSym.overrides(m2, origin, Types.this, false)) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
933 |
for (Symbol m3 : overridden) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
934 |
if (isSameType(m3.erasure(Types.this), m2.erasure(Types.this)) || |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
935 |
(m3.overrides(m2, origin, Types.this, false) && |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
936 |
(pendingBridges((ClassSymbol)origin, m3.enclClass()) || |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
937 |
(((MethodSymbol)m2).binaryImplementation((ClassSymbol)m3.owner, Types.this) != null)))) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
938 |
continue outer; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
939 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
940 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
941 |
overridden.add(m2); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
942 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
943 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
944 |
return overridden.toList(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
945 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
946 |
//where |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
947 |
private Filter<Symbol> bridgeFilter = new Filter<Symbol>() { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
948 |
public boolean accepts(Symbol t) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27125
diff
changeset
|
949 |
return t.kind == MTH && |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
950 |
t.name != names.init && |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
951 |
t.name != names.clinit && |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
952 |
(t.flags() & SYNTHETIC) == 0; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
953 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
954 |
}; |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
955 |
private boolean pendingBridges(ClassSymbol origin, TypeSymbol s) { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
956 |
//a symbol will be completed from a classfile if (a) symbol has |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
957 |
//an associated file object with CLASS kind and (b) the symbol has |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
958 |
//not been entered |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
959 |
if (origin.classfile != null && |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
960 |
origin.classfile.getKind() == JavaFileObject.Kind.CLASS && |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
961 |
enter.getEnv(origin) == null) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
962 |
return false; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
963 |
} |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
964 |
if (origin == s) { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
965 |
return true; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
966 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
967 |
for (Type t : interfaces(origin.type)) { |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
968 |
if (pendingBridges((ClassSymbol)t.tsym, s)) { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
969 |
return true; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
970 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
971 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
972 |
return false; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
973 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
974 |
// </editor-fold> |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
975 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
976 |
/** |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
977 |
* Scope filter used to skip methods that should be ignored (such as methods |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16567
diff
changeset
|
978 |
* overridden by j.l.Object) during function interface conversion interface check |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
979 |
*/ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
980 |
class DescriptorFilter implements Filter<Symbol> { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
981 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
982 |
TypeSymbol origin; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
983 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
984 |
DescriptorFilter(TypeSymbol origin) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
985 |
this.origin = origin; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
986 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
987 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
988 |
@Override |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
989 |
public boolean accepts(Symbol sym) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27125
diff
changeset
|
990 |
return sym.kind == MTH && |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
991 |
(sym.flags() & (ABSTRACT | DEFAULT)) == ABSTRACT && |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
992 |
!overridesObjectMethod(origin, sym) && |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
993 |
(interfaceCandidates(origin.type, (MethodSymbol)sym).head.flags() & DEFAULT) == 0; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
994 |
} |
22163 | 995 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
996 |
|
10 | 997 |
// <editor-fold defaultstate="collapsed" desc="isSubtype"> |
998 |
/** |
|
999 |
* Is t an unchecked subtype of s? |
|
1000 |
*/ |
|
1001 |
public boolean isSubtypeUnchecked(Type t, Type s) { |
|
14547 | 1002 |
return isSubtypeUnchecked(t, s, noWarnings); |
10 | 1003 |
} |
1004 |
/** |
|
1005 |
* Is t an unchecked subtype of s? |
|
1006 |
*/ |
|
1007 |
public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) { |
|
39100
5dc24593e3ae
8159680: Inference failure with unchecked subtyping and arrays
mcimadamore
parents:
38834
diff
changeset
|
1008 |
boolean result = isSubtypeUncheckedInternal(t, s, true, warn); |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1009 |
if (result) { |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1010 |
checkUnsafeVarargsConversion(t, s, warn); |
660
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
1011 |
} |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1012 |
return result; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1013 |
} |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1014 |
//where |
39100
5dc24593e3ae
8159680: Inference failure with unchecked subtyping and arrays
mcimadamore
parents:
38834
diff
changeset
|
1015 |
private boolean isSubtypeUncheckedInternal(Type t, Type s, boolean capture, Warner warn) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1016 |
if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1017 |
if (((ArrayType)t).elemtype.isPrimitive()) { |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1018 |
return isSameType(elemtype(t), elemtype(s)); |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1019 |
} else { |
39100
5dc24593e3ae
8159680: Inference failure with unchecked subtyping and arrays
mcimadamore
parents:
38834
diff
changeset
|
1020 |
return isSubtypeUncheckedInternal(elemtype(t), elemtype(s), false, warn); |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1021 |
} |
39100
5dc24593e3ae
8159680: Inference failure with unchecked subtyping and arrays
mcimadamore
parents:
38834
diff
changeset
|
1022 |
} else if (isSubtype(t, s, capture)) { |
10 | 1023 |
return true; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1024 |
} else if (t.hasTag(TYPEVAR)) { |
39100
5dc24593e3ae
8159680: Inference failure with unchecked subtyping and arrays
mcimadamore
parents:
38834
diff
changeset
|
1025 |
return isSubtypeUncheckedInternal(t.getUpperBound(), s, false, warn); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1026 |
} else if (!s.isRaw()) { |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
1027 |
Type t2 = asSuper(t, s.tsym); |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1028 |
if (t2 != null && t2.isRaw()) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1029 |
if (isReifiable(s)) { |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1030 |
warn.silentWarn(LintCategory.UNCHECKED); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1031 |
} else { |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1032 |
warn.warn(LintCategory.UNCHECKED); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1033 |
} |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1034 |
return true; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1035 |
} |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1036 |
} |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1037 |
return false; |
10 | 1038 |
} |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1039 |
|
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1040 |
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1041 |
if (!t.hasTag(ARRAY) || isReifiable(t)) { |
15385 | 1042 |
return; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1043 |
} |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1044 |
ArrayType from = (ArrayType)t; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1045 |
boolean shouldWarn = false; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1046 |
switch (s.getTag()) { |
10810
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1047 |
case ARRAY: |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1048 |
ArrayType to = (ArrayType)s; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1049 |
shouldWarn = from.isVarargs() && |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1050 |
!to.isVarargs() && |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1051 |
!isReifiable(from); |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1052 |
break; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1053 |
case CLASS: |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1054 |
shouldWarn = from.isVarargs(); |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1055 |
break; |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1056 |
} |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1057 |
if (shouldWarn) { |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1058 |
warn.warn(LintCategory.VARARGS); |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1059 |
} |
9444a714fdaf
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
mcimadamore
parents:
10634
diff
changeset
|
1060 |
} |
10 | 1061 |
|
1062 |
/** |
|
1063 |
* Is t a subtype of s?<br> |
|
1064 |
* (not defined for Method and ForAll types) |
|
1065 |
*/ |
|
1066 |
final public boolean isSubtype(Type t, Type s) { |
|
1067 |
return isSubtype(t, s, true); |
|
1068 |
} |
|
1069 |
final public boolean isSubtypeNoCapture(Type t, Type s) { |
|
1070 |
return isSubtype(t, s, false); |
|
1071 |
} |
|
1072 |
public boolean isSubtype(Type t, Type s, boolean capture) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
1073 |
if (t.equalsIgnoreMetadata(s)) |
10 | 1074 |
return true; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1075 |
if (s.isPartial()) |
10 | 1076 |
return isSuperType(s, t); |
1077 |
||
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1078 |
if (s.isCompound()) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1079 |
for (Type s2 : interfaces(s).prepend(supertype(s))) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1080 |
if (!isSubtype(t, s2, capture)) |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1081 |
return false; |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1082 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1083 |
return true; |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1084 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
1085 |
|
28451
d4fdab318a53
8062358: ClassCastException in TransTypes.visitApply
jlahoda
parents:
27390
diff
changeset
|
1086 |
// Generally, if 's' is a lower-bounded type variable, recur on lower bound; but |
24397
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1087 |
// for inference variables and intersections, we need to keep 's' |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1088 |
// (see JLS 4.10.2 for intersections and 18.2.3 for inference vars) |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1089 |
if (!t.hasTag(UNDETVAR) && !t.isCompound()) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1090 |
// TODO: JDK-8039198, bounds checking sometimes passes in a wildcard as s |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1091 |
Type lower = cvarLowerBound(wildLowerBound(s)); |
28451
d4fdab318a53
8062358: ClassCastException in TransTypes.visitApply
jlahoda
parents:
27390
diff
changeset
|
1092 |
if (s != lower && !lower.hasTag(BOT)) |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1093 |
return isSubtype(capture ? capture(t) : t, lower, false); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1094 |
} |
10 | 1095 |
|
1096 |
return isSubtype.visit(capture ? capture(t) : t, s); |
|
1097 |
} |
|
1098 |
// where |
|
1099 |
private TypeRelation isSubtype = new TypeRelation() |
|
1100 |
{ |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1101 |
@Override |
10 | 1102 |
public Boolean visitType(Type t, Type s) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1103 |
switch (t.getTag()) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1104 |
case BYTE: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1105 |
return (!s.hasTag(CHAR) && t.getTag().isSubRangeOf(s.getTag())); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1106 |
case CHAR: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1107 |
return (!s.hasTag(SHORT) && t.getTag().isSubRangeOf(s.getTag())); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1108 |
case SHORT: case INT: case LONG: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1109 |
case FLOAT: case DOUBLE: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1110 |
return t.getTag().isSubRangeOf(s.getTag()); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1111 |
case BOOLEAN: case VOID: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1112 |
return t.hasTag(s.getTag()); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1113 |
case TYPEVAR: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1114 |
return isSubtypeNoCapture(t.getUpperBound(), s); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1115 |
case BOT: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1116 |
return |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1117 |
s.hasTag(BOT) || s.hasTag(CLASS) || |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1118 |
s.hasTag(ARRAY) || s.hasTag(TYPEVAR); |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1119 |
case WILDCARD: //we shouldn't be here - avoids crash (see 7034495) |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1120 |
case NONE: |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1121 |
return false; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1122 |
default: |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1123 |
throw new AssertionError("isSubtype " + t.getTag()); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1124 |
} |
10 | 1125 |
} |
1126 |
||
22163 | 1127 |
private Set<TypePair> cache = new HashSet<>(); |
10 | 1128 |
|
1129 |
private boolean containsTypeRecursive(Type t, Type s) { |
|
1130 |
TypePair pair = new TypePair(t, s); |
|
1131 |
if (cache.add(pair)) { |
|
1132 |
try { |
|
1133 |
return containsType(t.getTypeArguments(), |
|
1134 |
s.getTypeArguments()); |
|
1135 |
} finally { |
|
1136 |
cache.remove(pair); |
|
1137 |
} |
|
1138 |
} else { |
|
1139 |
return containsType(t.getTypeArguments(), |
|
1140 |
rewriteSupers(s).getTypeArguments()); |
|
1141 |
} |
|
1142 |
} |
|
1143 |
||
1144 |
private Type rewriteSupers(Type t) { |
|
1145 |
if (!t.isParameterized()) |
|
1146 |
return t; |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
1147 |
ListBuffer<Type> from = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
1148 |
ListBuffer<Type> to = new ListBuffer<>(); |
10 | 1149 |
adaptSelf(t, from, to); |
1150 |
if (from.isEmpty()) |
|
1151 |
return t; |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
1152 |
ListBuffer<Type> rewrite = new ListBuffer<>(); |
10 | 1153 |
boolean changed = false; |
1154 |
for (Type orig : to.toList()) { |
|
1155 |
Type s = rewriteSupers(orig); |
|
1156 |
if (s.isSuperBound() && !s.isExtendsBound()) { |
|
1157 |
s = new WildcardType(syms.objectType, |
|
1158 |
BoundKind.UNBOUND, |
|
24396 | 1159 |
syms.boundClass, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
1160 |
s.getMetadata()); |
10 | 1161 |
changed = true; |
1162 |
} else if (s != orig) { |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1163 |
s = new WildcardType(wildUpperBound(s), |
10 | 1164 |
BoundKind.EXTENDS, |
24396 | 1165 |
syms.boundClass, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
1166 |
s.getMetadata()); |
10 | 1167 |
changed = true; |
1168 |
} |
|
1169 |
rewrite.append(s); |
|
1170 |
} |
|
1171 |
if (changed) |
|
1172 |
return subst(t.tsym.type, from.toList(), rewrite.toList()); |
|
1173 |
else |
|
1174 |
return t; |
|
1175 |
} |
|
1176 |
||
1177 |
@Override |
|
1178 |
public Boolean visitClassType(ClassType t, Type s) { |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
1179 |
Type sup = asSuper(t, s.tsym); |
24397
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1180 |
if (sup == null) return false; |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1181 |
// If t is an intersection, sup might not be a class type |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1182 |
if (!sup.hasTag(CLASS)) return isSubtypeNoCapture(sup, s); |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1183 |
return sup.tsym == s.tsym |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
1184 |
// Check type variable containment |
10 | 1185 |
&& (!s.isParameterized() || containsTypeRecursive(s, sup)) |
1186 |
&& isSubtypeNoCapture(sup.getEnclosingType(), |
|
1187 |
s.getEnclosingType()); |
|
1188 |
} |
|
1189 |
||
1190 |
@Override |
|
1191 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1192 |
if (s.hasTag(ARRAY)) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1193 |
if (t.elemtype.isPrimitive()) |
10 | 1194 |
return isSameType(t.elemtype, elemtype(s)); |
1195 |
else |
|
1196 |
return isSubtypeNoCapture(t.elemtype, elemtype(s)); |
|
1197 |
} |
|
1198 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1199 |
if (s.hasTag(CLASS)) { |
10 | 1200 |
Name sname = s.tsym.getQualifiedName(); |
1201 |
return sname == names.java_lang_Object |
|
1202 |
|| sname == names.java_lang_Cloneable |
|
1203 |
|| sname == names.java_io_Serializable; |
|
1204 |
} |
|
1205 |
||
1206 |
return false; |
|
1207 |
} |
|
1208 |
||
1209 |
@Override |
|
1210 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
1211 |
//todo: test against origin needed? or replace with substitution? |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1212 |
if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) { |
10 | 1213 |
return true; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1214 |
} else if (s.hasTag(BOT)) { |
10634
7f15f5a11ae9
7086586: Inference producing null type argument
mcimadamore
parents:
10453
diff
changeset
|
1215 |
//if 's' is 'null' there's no instantiated type U for which |
7f15f5a11ae9
7086586: Inference producing null type argument
mcimadamore
parents:
10453
diff
changeset
|
1216 |
//U <: s (but 'null' itself, which is not a valid type) |
7f15f5a11ae9
7086586: Inference producing null type argument
mcimadamore
parents:
10453
diff
changeset
|
1217 |
return false; |
7f15f5a11ae9
7086586: Inference producing null type argument
mcimadamore
parents:
10453
diff
changeset
|
1218 |
} |
10 | 1219 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
1220 |
t.addBound(InferenceBound.UPPER, s, Types.this); |
10 | 1221 |
return true; |
1222 |
} |
|
1223 |
||
1224 |
@Override |
|
1225 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
1226 |
return true; |
|
1227 |
} |
|
1228 |
}; |
|
1229 |
||
1230 |
/** |
|
1231 |
* Is t a subtype of every type in given list `ts'?<br> |
|
1232 |
* (not defined for Method and ForAll types)<br> |
|
1233 |
* Allows unchecked conversions. |
|
1234 |
*/ |
|
1235 |
public boolean isSubtypeUnchecked(Type t, List<Type> ts, Warner warn) { |
|
1236 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
1237 |
if (!isSubtypeUnchecked(t, l.head, warn)) |
|
1238 |
return false; |
|
1239 |
return true; |
|
1240 |
} |
|
1241 |
||
1242 |
/** |
|
1243 |
* Are corresponding elements of ts subtypes of ss? If lists are |
|
1244 |
* of different length, return false. |
|
1245 |
*/ |
|
1246 |
public boolean isSubtypes(List<Type> ts, List<Type> ss) { |
|
1247 |
while (ts.tail != null && ss.tail != null |
|
1248 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
1249 |
isSubtype(ts.head, ss.head)) { |
|
1250 |
ts = ts.tail; |
|
1251 |
ss = ss.tail; |
|
1252 |
} |
|
1253 |
return ts.tail == null && ss.tail == null; |
|
1254 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
1255 |
} |
|
1256 |
||
1257 |
/** |
|
1258 |
* Are corresponding elements of ts subtypes of ss, allowing |
|
1259 |
* unchecked conversions? If lists are of different length, |
|
1260 |
* return false. |
|
1261 |
**/ |
|
1262 |
public boolean isSubtypesUnchecked(List<Type> ts, List<Type> ss, Warner warn) { |
|
1263 |
while (ts.tail != null && ss.tail != null |
|
1264 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
1265 |
isSubtypeUnchecked(ts.head, ss.head, warn)) { |
|
1266 |
ts = ts.tail; |
|
1267 |
ss = ss.tail; |
|
1268 |
} |
|
1269 |
return ts.tail == null && ss.tail == null; |
|
1270 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
1271 |
} |
|
1272 |
// </editor-fold> |
|
1273 |
||
1274 |
// <editor-fold defaultstate="collapsed" desc="isSuperType"> |
|
1275 |
/** |
|
1276 |
* Is t a supertype of s? |
|
1277 |
*/ |
|
1278 |
public boolean isSuperType(Type t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1279 |
switch (t.getTag()) { |
10 | 1280 |
case ERROR: |
1281 |
return true; |
|
1282 |
case UNDETVAR: { |
|
1283 |
UndetVar undet = (UndetVar)t; |
|
1284 |
if (t == s || |
|
1285 |
undet.qtype == s || |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1286 |
s.hasTag(ERROR) || |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1287 |
s.hasTag(BOT)) { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1288 |
return true; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1289 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
1290 |
undet.addBound(InferenceBound.LOWER, s, this); |
10 | 1291 |
return true; |
1292 |
} |
|
1293 |
default: |
|
1294 |
return isSubtype(s, t); |
|
1295 |
} |
|
1296 |
} |
|
1297 |
// </editor-fold> |
|
1298 |
||
1299 |
// <editor-fold defaultstate="collapsed" desc="isSameType"> |
|
1300 |
/** |
|
1301 |
* Are corresponding elements of the lists the same type? If |
|
1302 |
* lists are of different length, return false. |
|
1303 |
*/ |
|
1304 |
public boolean isSameTypes(List<Type> ts, List<Type> ss) { |
|
1305 |
while (ts.tail != null && ss.tail != null |
|
1306 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1307 |
isSameType(ts.head, ss.head)) { |
10 | 1308 |
ts = ts.tail; |
1309 |
ss = ss.tail; |
|
1310 |
} |
|
1311 |
return ts.tail == null && ss.tail == null; |
|
1312 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
1313 |
} |
|
1314 |
||
1315 |
/** |
|
36995 | 1316 |
* A polymorphic signature method (JLS 15.12.3) is a method that |
1317 |
* (i) is declared in the java.lang.invoke.MethodHandle/VarHandle classes; |
|
1318 |
* (ii) takes a single variable arity parameter; |
|
1319 |
* (iii) whose declared type is Object[]; |
|
1320 |
* (iv) has any return type, Object signifying a polymorphic return type; and |
|
1321 |
* (v) is native. |
|
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1322 |
*/ |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1323 |
public boolean isSignaturePolymorphic(MethodSymbol msym) { |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1324 |
List<Type> argtypes = msym.type.getParameterTypes(); |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1325 |
return (msym.flags_field & NATIVE) != 0 && |
36995 | 1326 |
(msym.owner == syms.methodHandleType.tsym || msym.owner == syms.varHandleType.tsym) && |
41856
13a056e8f16e
8168774: Polymorhic signature method check crashes javac
mcimadamore
parents:
41526
diff
changeset
|
1327 |
argtypes.length() == 1 && |
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1328 |
argtypes.head.hasTag(TypeTag.ARRAY) && |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1329 |
((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym; |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1330 |
} |
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1331 |
|
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
17578
diff
changeset
|
1332 |
/** |
10 | 1333 |
* Is t the same type as s? |
1334 |
*/ |
|
1335 |
public boolean isSameType(Type t, Type s) { |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1336 |
return isSameTypeVisitor.visit(t, s); |
10 | 1337 |
} |
1338 |
// where |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1339 |
|
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1340 |
/** |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1341 |
* Type-equality relation - type variables are considered |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1342 |
* equals if they share the same object identity. |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1343 |
*/ |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1344 |
TypeRelation isSameTypeVisitor = new TypeRelation() { |
10 | 1345 |
|
1346 |
public Boolean visitType(Type t, Type s) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
1347 |
if (t.equalsIgnoreMetadata(s)) |
10 | 1348 |
return true; |
1349 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1350 |
if (s.isPartial()) |
10 | 1351 |
return visit(s, t); |
1352 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1353 |
switch (t.getTag()) { |
10 | 1354 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
1355 |
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1356 |
return t.hasTag(s.getTag()); |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1357 |
case TYPEVAR: { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1358 |
if (s.hasTag(TYPEVAR)) { |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1359 |
//type-substitution does not preserve type-var types |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1360 |
//check that type var symbols and bounds are indeed the same |
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1361 |
return t == s; |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1362 |
} |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1363 |
else { |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1364 |
//special case for s == ? super X, where upper(s) = u |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1365 |
//check that u == t, where u has been set by Type.withTypeVar |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1366 |
return s.isSuperBound() && |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1367 |
!s.isExtendsBound() && |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1368 |
visit(t, wildUpperBound(s)); |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1369 |
} |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
1370 |
} |
10 | 1371 |
default: |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1372 |
throw new AssertionError("isSameType " + t.getTag()); |
10 | 1373 |
} |
1374 |
} |
|
1375 |
||
1376 |
@Override |
|
1377 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
39363
ebaee646b121
8159970: javac, JLS8 18.2.4 is not completely implemented by the compiler
vromero
parents:
39100
diff
changeset
|
1378 |
if (!s.hasTag(WILDCARD)) { |
10 | 1379 |
return false; |
39363
ebaee646b121
8159970: javac, JLS8 18.2.4 is not completely implemented by the compiler
vromero
parents:
39100
diff
changeset
|
1380 |
} else { |
ebaee646b121
8159970: javac, JLS8 18.2.4 is not completely implemented by the compiler
vromero
parents:
39100
diff
changeset
|
1381 |
WildcardType t2 = (WildcardType)s; |
ebaee646b121
8159970: javac, JLS8 18.2.4 is not completely implemented by the compiler
vromero
parents:
39100
diff
changeset
|
1382 |
return (t.kind == t2.kind || (t.isExtendsBound() && s.isExtendsBound())) && |
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1383 |
isSameType(t.type, t2.type); |
39363
ebaee646b121
8159970: javac, JLS8 18.2.4 is not completely implemented by the compiler
vromero
parents:
39100
diff
changeset
|
1384 |
} |
10 | 1385 |
} |
1386 |
||
1387 |
@Override |
|
1388 |
public Boolean visitClassType(ClassType t, Type s) { |
|
1389 |
if (t == s) |
|
1390 |
return true; |
|
1391 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1392 |
if (s.isPartial()) |
10 | 1393 |
return visit(s, t); |
1394 |
||
1395 |
if (s.isSuperBound() && !s.isExtendsBound()) |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1396 |
return visit(t, wildUpperBound(s)) && visit(t, wildLowerBound(s)); |
10 | 1397 |
|
1398 |
if (t.isCompound() && s.isCompound()) { |
|
1399 |
if (!visit(supertype(t), supertype(s))) |
|
1400 |
return false; |
|
1401 |
||
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1402 |
Map<Symbol,Type> tMap = new HashMap<>(); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1403 |
for (Type ti : interfaces(t)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1404 |
if (tMap.containsKey(ti)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1405 |
throw new AssertionError("Malformed intersection"); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1406 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1407 |
tMap.put(ti.tsym, ti); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1408 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1409 |
for (Type si : interfaces(s)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1410 |
if (!tMap.containsKey(si.tsym)) |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1411 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1412 |
Type ti = tMap.remove(si.tsym); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1413 |
if (!visit(ti, si)) |
10 | 1414 |
return false; |
1415 |
} |
|
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34757
diff
changeset
|
1416 |
return tMap.isEmpty(); |
10 | 1417 |
} |
1418 |
return t.tsym == s.tsym |
|
1419 |
&& visit(t.getEnclosingType(), s.getEnclosingType()) |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1420 |
&& containsTypeEquivalent(t.getTypeArguments(), s.getTypeArguments()); |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
1421 |
} |
15705 | 1422 |
|
10 | 1423 |
@Override |
1424 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
1425 |
if (t == s) |
|
1426 |
return true; |
|
1427 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1428 |
if (s.isPartial()) |
10 | 1429 |
return visit(s, t); |
1430 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1431 |
return s.hasTag(ARRAY) |
10 | 1432 |
&& containsTypeEquivalent(t.elemtype, elemtype(s)); |
1433 |
} |
|
1434 |
||
1435 |
@Override |
|
1436 |
public Boolean visitMethodType(MethodType t, Type s) { |
|
1437 |
// isSameType for methods does not take thrown |
|
1438 |
// exceptions into account! |
|
1439 |
return hasSameArgs(t, s) && visit(t.getReturnType(), s.getReturnType()); |
|
1440 |
} |
|
1441 |
||
1442 |
@Override |
|
1443 |
public Boolean visitPackageType(PackageType t, Type s) { |
|
1444 |
return t == s; |
|
1445 |
} |
|
1446 |
||
1447 |
@Override |
|
1448 |
public Boolean visitForAll(ForAll t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1449 |
if (!s.hasTag(FORALL)) { |
10 | 1450 |
return false; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1451 |
} |
10 | 1452 |
|
1453 |
ForAll forAll = (ForAll)s; |
|
1454 |
return hasSameBounds(t, forAll) |
|
1455 |
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars)); |
|
1456 |
} |
|
1457 |
||
1458 |
@Override |
|
1459 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1460 |
if (s.hasTag(WILDCARD)) { |
10 | 1461 |
// FIXME, this might be leftovers from before capture conversion |
1462 |
return false; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1463 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1464 |
|
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1465 |
if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) { |
10 | 1466 |
return true; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1467 |
} |
10 | 1468 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
1469 |
t.addBound(InferenceBound.EQ, s, Types.this); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
11549
diff
changeset
|
1470 |
|
10 | 1471 |
return true; |
1472 |
} |
|
1473 |
||
1474 |
@Override |
|
1475 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
1476 |
return true; |
|
1477 |
} |
|
1478 |
}; |
|
17578 | 1479 |
|
24396 | 1480 |
// </editor-fold> |
1481 |
||
10 | 1482 |
// <editor-fold defaultstate="collapsed" desc="Contains Type"> |
1483 |
public boolean containedBy(Type t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1484 |
switch (t.getTag()) { |
10 | 1485 |
case UNDETVAR: |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1486 |
if (s.hasTag(WILDCARD)) { |
10 | 1487 |
UndetVar undetvar = (UndetVar)t; |
24396 | 1488 |
WildcardType wt = (WildcardType)s; |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1489 |
switch(wt.kind) { |
25441
92dcee5a4741
8043926: javac, code valid in 7 is not compiling for 8
mcimadamore
parents:
25279
diff
changeset
|
1490 |
case UNBOUND: |
92dcee5a4741
8043926: javac, code valid in 7 is not compiling for 8
mcimadamore
parents:
25279
diff
changeset
|
1491 |
break; |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1492 |
case EXTENDS: { |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1493 |
Type bound = wildUpperBound(s); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
1494 |
undetvar.addBound(InferenceBound.UPPER, bound, this); |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1495 |
break; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1496 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1497 |
case SUPER: { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1498 |
Type bound = wildLowerBound(s); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
13689
diff
changeset
|
1499 |
undetvar.addBound(InferenceBound.LOWER, bound, this); |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1500 |
break; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
1501 |
} |
1535
a64c289fe413
6762569: Javac crashes with AssertionError in Types.containedBy
mcimadamore
parents:
1530
diff
changeset
|
1502 |
} |
10 | 1503 |
return true; |
1504 |
} else { |
|
1505 |
return isSameType(t, s); |
|
1506 |
} |
|
1507 |
case ERROR: |
|
1508 |
return true; |
|
1509 |
default: |
|
1510 |
return containsType(s, t); |
|
1511 |
} |
|
1512 |
} |
|
1513 |
||
1514 |
boolean containsType(List<Type> ts, List<Type> ss) { |
|
1515 |
while (ts.nonEmpty() && ss.nonEmpty() |
|
1516 |
&& containsType(ts.head, ss.head)) { |
|
1517 |
ts = ts.tail; |
|
1518 |
ss = ss.tail; |
|
1519 |
} |
|
1520 |
return ts.isEmpty() && ss.isEmpty(); |
|
1521 |
} |
|
1522 |
||
1523 |
/** |
|
1524 |
* Check if t contains s. |
|
1525 |
* |
|
1526 |
* <p>T contains S if: |
|
1527 |
* |
|
1528 |
* <p>{@code L(T) <: L(S) && U(S) <: U(T)} |
|
1529 |
* |
|
1530 |
* <p>This relation is only used by ClassType.isSubtype(), that |
|
1531 |
* is, |
|
1532 |
* |
|
1533 |
* <p>{@code C<S> <: C<T> if T contains S.} |
|
1534 |
* |
|
1535 |
* <p>Because of F-bounds, this relation can lead to infinite |
|
1536 |
* recursion. Thus we must somehow break that recursion. Notice |
|
1537 |
* that containsType() is only called from ClassType.isSubtype(). |
|
1538 |
* Since the arguments have already been checked against their |
|
1539 |
* bounds, we know: |
|
1540 |
* |
|
1541 |
* <p>{@code U(S) <: U(T) if T is "super" bound (U(T) *is* the bound)} |
|
1542 |
* |
|
1543 |
* <p>{@code L(T) <: L(S) if T is "extends" bound (L(T) is bottom)} |
|
1544 |
* |
|
1545 |
* @param t a type |
|
1546 |
* @param s a type |
|
1547 |
*/ |
|
1548 |
public boolean containsType(Type t, Type s) { |
|
1549 |
return containsType.visit(t, s); |
|
1550 |
} |
|
1551 |
// where |
|
1552 |
private TypeRelation containsType = new TypeRelation() { |
|
1553 |
||
1554 |
public Boolean visitType(Type t, Type s) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1555 |
if (s.isPartial()) |
10 | 1556 |
return containedBy(s, t); |
1557 |
else |
|
1558 |
return isSameType(t, s); |
|
1559 |
} |
|
1560 |
||
7637 | 1561 |
// void debugContainsType(WildcardType t, Type s) { |
1562 |
// System.err.println(); |
|
1563 |
// System.err.format(" does %s contain %s?%n", t, s); |
|
1564 |
// System.err.format(" %s U(%s) <: U(%s) %s = %s%n", |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1565 |
// wildUpperBound(s), s, t, wildUpperBound(t), |
7637 | 1566 |
// t.isSuperBound() |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1567 |
// || isSubtypeNoCapture(wildUpperBound(s), wildUpperBound(t))); |
7637 | 1568 |
// System.err.format(" %s L(%s) <: L(%s) %s = %s%n", |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1569 |
// wildLowerBound(t), t, s, wildLowerBound(s), |
7637 | 1570 |
// t.isExtendsBound() |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1571 |
// || isSubtypeNoCapture(wildLowerBound(t), wildLowerBound(s))); |
7637 | 1572 |
// System.err.println(); |
1573 |
// } |
|
10 | 1574 |
|
1575 |
@Override |
|
1576 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1577 |
if (s.isPartial()) |
10 | 1578 |
return containedBy(s, t); |
1579 |
else { |
|
7637 | 1580 |
// debugContainsType(t, s); |
10 | 1581 |
return isSameWildcard(t, s) |
1582 |
|| isCaptureOf(s, t) |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1583 |
|| ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), wildLowerBound(s))) && |
29146
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1584 |
(t.isSuperBound() || isSubtypeNoCapture(wildUpperBound(s), wildUpperBound(t)))); |
10 | 1585 |
} |
1586 |
} |
|
1587 |
||
1588 |
@Override |
|
1589 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1590 |
if (!s.hasTag(WILDCARD)) { |
10 | 1591 |
return isSameType(t, s); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1592 |
} else { |
10 | 1593 |
return false; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1594 |
} |
10 | 1595 |
} |
1596 |
||
1597 |
@Override |
|
1598 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
1599 |
return true; |
|
1600 |
} |
|
1601 |
}; |
|
1602 |
||
1603 |
public boolean isCaptureOf(Type s, WildcardType t) { |
|
24396 | 1604 |
if (!s.hasTag(TYPEVAR) || !((TypeVar)s).isCaptured()) |
10 | 1605 |
return false; |
24396 | 1606 |
return isSameWildcard(t, ((CapturedType)s).wildcard); |
10 | 1607 |
} |
1608 |
||
1609 |
public boolean isSameWildcard(WildcardType t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1610 |
if (!s.hasTag(WILDCARD)) |
10 | 1611 |
return false; |
24396 | 1612 |
WildcardType w = (WildcardType)s; |
10 | 1613 |
return w.kind == t.kind && w.type == t.type; |
1614 |
} |
|
1615 |
||
1616 |
public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { |
|
1617 |
while (ts.nonEmpty() && ss.nonEmpty() |
|
1618 |
&& containsTypeEquivalent(ts.head, ss.head)) { |
|
1619 |
ts = ts.tail; |
|
1620 |
ss = ss.tail; |
|
1621 |
} |
|
1622 |
return ts.isEmpty() && ss.isEmpty(); |
|
1623 |
} |
|
1624 |
// </editor-fold> |
|
1625 |
||
1626 |
// <editor-fold defaultstate="collapsed" desc="isCastable"> |
|
1627 |
public boolean isCastable(Type t, Type s) { |
|
14547 | 1628 |
return isCastable(t, s, noWarnings); |
10 | 1629 |
} |
1630 |
||
1631 |
/** |
|
1632 |
* Is t is castable to s?<br> |
|
1633 |
* s is assumed to be an erased type.<br> |
|
1634 |
* (not defined for Method and ForAll types). |
|
1635 |
*/ |
|
1636 |
public boolean isCastable(Type t, Type s, Warner warn) { |
|
1637 |
if (t == s) |
|
1638 |
return true; |
|
34756
d31f11c4cc75
8144832: cast conversion fails when converting a type-variable to primitive type
vromero
parents:
34563
diff
changeset
|
1639 |
if (t.isPrimitive() != s.isPrimitive()) { |
d31f11c4cc75
8144832: cast conversion fails when converting a type-variable to primitive type
vromero
parents:
34563
diff
changeset
|
1640 |
t = skipTypeVars(t, false); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1641 |
return (isConvertible(t, s, warn) |
51047
860a3648c494
8028563: Remove javac support for 6/1.6 source and target values
darcy
parents:
50898
diff
changeset
|
1642 |
|| (s.isPrimitive() && |
9721
da048be191c2
7041730: Regression: compiler accepts invalid cast from int to Byte
mcimadamore
parents:
9607
diff
changeset
|
1643 |
isSubtype(boxedClass(s).type, t))); |
34756
d31f11c4cc75
8144832: cast conversion fails when converting a type-variable to primitive type
vromero
parents:
34563
diff
changeset
|
1644 |
} |
10 | 1645 |
if (warn != warnStack.head) { |
1646 |
try { |
|
1647 |
warnStack = warnStack.prepend(warn); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1648 |
checkUnsafeVarargsConversion(t, s, warn); |
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1649 |
return isCastable.visit(t,s); |
10 | 1650 |
} finally { |
1651 |
warnStack = warnStack.tail; |
|
1652 |
} |
|
1653 |
} else { |
|
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1654 |
return isCastable.visit(t,s); |
10 | 1655 |
} |
1656 |
} |
|
1657 |
// where |
|
1658 |
private TypeRelation isCastable = new TypeRelation() { |
|
1659 |
||
1660 |
public Boolean visitType(Type t, Type s) { |
|
50898
12133a6e2613
8205418: Assorted improvements to source code model
jlahoda
parents:
50636
diff
changeset
|
1661 |
if (s.hasTag(ERROR) || t.hasTag(NONE)) |
10 | 1662 |
return true; |
1663 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1664 |
switch (t.getTag()) { |
10 | 1665 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
1666 |
case DOUBLE: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1667 |
return s.isNumeric(); |
10 | 1668 |
case BOOLEAN: |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1669 |
return s.hasTag(BOOLEAN); |
10 | 1670 |
case VOID: |
1671 |
return false; |
|
1672 |
case BOT: |
|
1673 |
return isSubtype(t, s); |
|
1674 |
default: |
|
1675 |
throw new AssertionError(); |
|
1676 |
} |
|
1677 |
} |
|
1678 |
||
1679 |
@Override |
|
1680 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1681 |
return isCastable(wildUpperBound(t), s, warnStack.head); |
10 | 1682 |
} |
1683 |
||
1684 |
@Override |
|
1685 |
public Boolean visitClassType(ClassType t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1686 |
if (s.hasTag(ERROR) || s.hasTag(BOT)) |
10 | 1687 |
return true; |
1688 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1689 |
if (s.hasTag(TYPEVAR)) { |
14547 | 1690 |
if (isCastable(t, s.getUpperBound(), noWarnings)) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1691 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1692 |
return true; |
1693 |
} else { |
|
1694 |
return false; |
|
1695 |
} |
|
1696 |
} |
|
1697 |
||
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1698 |
if (t.isCompound() || s.isCompound()) { |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1699 |
return !t.isCompound() ? |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1700 |
visitCompoundType((ClassType)s, t, true) : |
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1701 |
visitCompoundType(t, s, false); |
10 | 1702 |
} |
1703 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1704 |
if (s.hasTag(CLASS) || s.hasTag(ARRAY)) { |
10 | 1705 |
boolean upcast; |
1706 |
if ((upcast = isSubtype(erasure(t), erasure(s))) |
|
1707 |
|| isSubtype(erasure(s), erasure(t))) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1708 |
if (!upcast && s.hasTag(ARRAY)) { |
10 | 1709 |
if (!isReifiable(s)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1710 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1711 |
return true; |
1712 |
} else if (s.isRaw()) { |
|
1713 |
return true; |
|
1714 |
} else if (t.isRaw()) { |
|
1715 |
if (!isUnbounded(s)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1716 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1717 |
return true; |
1718 |
} |
|
1719 |
// Assume |a| <: |b| |
|
1720 |
final Type a = upcast ? t : s; |
|
1721 |
final Type b = upcast ? s : t; |
|
1722 |
final boolean HIGH = true; |
|
1723 |
final boolean LOW = false; |
|
1724 |
final boolean DONT_REWRITE_TYPEVARS = false; |
|
1725 |
Type aHigh = rewriteQuantifiers(a, HIGH, DONT_REWRITE_TYPEVARS); |
|
1726 |
Type aLow = rewriteQuantifiers(a, LOW, DONT_REWRITE_TYPEVARS); |
|
1727 |
Type bHigh = rewriteQuantifiers(b, HIGH, DONT_REWRITE_TYPEVARS); |
|
1728 |
Type bLow = rewriteQuantifiers(b, LOW, DONT_REWRITE_TYPEVARS); |
|
1729 |
Type lowSub = asSub(bLow, aLow.tsym); |
|
1730 |
Type highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym); |
|
1731 |
if (highSub == null) { |
|
1732 |
final boolean REWRITE_TYPEVARS = true; |
|
1733 |
aHigh = rewriteQuantifiers(a, HIGH, REWRITE_TYPEVARS); |
|
1734 |
aLow = rewriteQuantifiers(a, LOW, REWRITE_TYPEVARS); |
|
1735 |
bHigh = rewriteQuantifiers(b, HIGH, REWRITE_TYPEVARS); |
|
1736 |
bLow = rewriteQuantifiers(b, LOW, REWRITE_TYPEVARS); |
|
1737 |
lowSub = asSub(bLow, aLow.tsym); |
|
1738 |
highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym); |
|
1739 |
} |
|
1740 |
if (highSub != null) { |
|
8032 | 1741 |
if (!(a.tsym == highSub.tsym && a.tsym == lowSub.tsym)) { |
1742 |
Assert.error(a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym); |
|
1743 |
} |
|
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1744 |
if (!disjointTypes(aHigh.allparams(), highSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1745 |
&& !disjointTypes(aHigh.allparams(), lowSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1746 |
&& !disjointTypes(aLow.allparams(), highSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1747 |
&& !disjointTypes(aLow.allparams(), lowSub.allparams())) { |
7627
de2a86da165e
7005095: Cast: compile reject sensible cast from final class to interface
mcimadamore
parents:
7331
diff
changeset
|
1748 |
if (upcast ? giveWarning(a, b) : |
2218
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
1749 |
giveWarning(b, a)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1750 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1751 |
return true; |
1752 |
} |
|
1753 |
} |
|
1754 |
if (isReifiable(s)) |
|
1755 |
return isSubtypeUnchecked(a, b); |
|
1756 |
else |
|
1757 |
return isSubtypeUnchecked(a, b, warnStack.head); |
|
1758 |
} |
|
1759 |
||
1760 |
// Sidecast |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1761 |
if (s.hasTag(CLASS)) { |
10 | 1762 |
if ((s.tsym.flags() & INTERFACE) != 0) { |
1763 |
return ((t.tsym.flags() & FINAL) == 0) |
|
1764 |
? sideCast(t, s, warnStack.head) |
|
1765 |
: sideCastFinal(t, s, warnStack.head); |
|
1766 |
} else if ((t.tsym.flags() & INTERFACE) != 0) { |
|
1767 |
return ((s.tsym.flags() & FINAL) == 0) |
|
1768 |
? sideCast(t, s, warnStack.head) |
|
1769 |
: sideCastFinal(t, s, warnStack.head); |
|
1770 |
} else { |
|
1771 |
// unrelated class types |
|
1772 |
return false; |
|
1773 |
} |
|
1774 |
} |
|
1775 |
} |
|
1776 |
return false; |
|
1777 |
} |
|
1778 |
||
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1779 |
boolean visitCompoundType(ClassType ct, Type s, boolean reverse) { |
16565
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1780 |
Warner warn = noWarnings; |
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
1781 |
for (Type c : directSupertypes(ct)) { |
16565
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1782 |
warn.clear(); |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1783 |
if (reverse ? !isCastable(s, c, warn) : !isCastable(c, s, warn)) |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1784 |
return false; |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1785 |
} |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1786 |
if (warn.hasLint(LintCategory.UNCHECKED)) |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1787 |
warnStack.head.warn(LintCategory.UNCHECKED); |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1788 |
return true; |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1789 |
} |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
1790 |
|
10 | 1791 |
@Override |
1792 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1793 |
switch (s.getTag()) { |
10 | 1794 |
case ERROR: |
1795 |
case BOT: |
|
1796 |
return true; |
|
1797 |
case TYPEVAR: |
|
14547 | 1798 |
if (isCastable(s, t, noWarnings)) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1799 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1800 |
return true; |
1801 |
} else { |
|
1802 |
return false; |
|
1803 |
} |
|
1804 |
case CLASS: |
|
1805 |
return isSubtype(t, s); |
|
1806 |
case ARRAY: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
1807 |
if (elemtype(t).isPrimitive() || elemtype(s).isPrimitive()) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1808 |
return elemtype(t).hasTag(elemtype(s).getTag()); |
10 | 1809 |
} else { |
1810 |
return visit(elemtype(t), elemtype(s)); |
|
1811 |
} |
|
1812 |
default: |
|
1813 |
return false; |
|
1814 |
} |
|
1815 |
} |
|
1816 |
||
1817 |
@Override |
|
1818 |
public Boolean visitTypeVar(TypeVar t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1819 |
switch (s.getTag()) { |
10 | 1820 |
case ERROR: |
1821 |
case BOT: |
|
1822 |
return true; |
|
1823 |
case TYPEVAR: |
|
1824 |
if (isSubtype(t, s)) { |
|
1825 |
return true; |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
1826 |
} else if (isCastable(t.getUpperBound(), s, noWarnings)) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1827 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1828 |
return true; |
1829 |
} else { |
|
1830 |
return false; |
|
1831 |
} |
|
1832 |
default: |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
1833 |
return isCastable(t.getUpperBound(), s, warnStack.head); |
10 | 1834 |
} |
1835 |
} |
|
1836 |
||
1837 |
@Override |
|
1838 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
1839 |
return true; |
|
1840 |
} |
|
1841 |
}; |
|
1842 |
// </editor-fold> |
|
1843 |
||
1844 |
// <editor-fold defaultstate="collapsed" desc="disjointTypes"> |
|
1845 |
public boolean disjointTypes(List<Type> ts, List<Type> ss) { |
|
1846 |
while (ts.tail != null && ss.tail != null) { |
|
1847 |
if (disjointType(ts.head, ss.head)) return true; |
|
1848 |
ts = ts.tail; |
|
1849 |
ss = ss.tail; |
|
1850 |
} |
|
1851 |
return false; |
|
1852 |
} |
|
1853 |
||
1854 |
/** |
|
1855 |
* Two types or wildcards are considered disjoint if it can be |
|
1856 |
* proven that no type can be contained in both. It is |
|
1857 |
* conservative in that it is allowed to say that two types are |
|
1858 |
* not disjoint, even though they actually are. |
|
1859 |
* |
|
14259 | 1860 |
* The type {@code C<X>} is castable to {@code C<Y>} exactly if |
1861 |
* {@code X} and {@code Y} are not disjoint. |
|
10 | 1862 |
*/ |
1863 |
public boolean disjointType(Type t, Type s) { |
|
1864 |
return disjointType.visit(t, s); |
|
1865 |
} |
|
1866 |
// where |
|
1867 |
private TypeRelation disjointType = new TypeRelation() { |
|
1868 |
||
22163 | 1869 |
private Set<TypePair> cache = new HashSet<>(); |
10 | 1870 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1871 |
@Override |
10 | 1872 |
public Boolean visitType(Type t, Type s) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1873 |
if (s.hasTag(WILDCARD)) |
10 | 1874 |
return visit(s, t); |
1875 |
else |
|
1876 |
return notSoftSubtypeRecursive(t, s) || notSoftSubtypeRecursive(s, t); |
|
1877 |
} |
|
1878 |
||
1879 |
private boolean isCastableRecursive(Type t, Type s) { |
|
1880 |
TypePair pair = new TypePair(t, s); |
|
1881 |
if (cache.add(pair)) { |
|
1882 |
try { |
|
1883 |
return Types.this.isCastable(t, s); |
|
1884 |
} finally { |
|
1885 |
cache.remove(pair); |
|
1886 |
} |
|
1887 |
} else { |
|
1888 |
return true; |
|
1889 |
} |
|
1890 |
} |
|
1891 |
||
1892 |
private boolean notSoftSubtypeRecursive(Type t, Type s) { |
|
1893 |
TypePair pair = new TypePair(t, s); |
|
1894 |
if (cache.add(pair)) { |
|
1895 |
try { |
|
1896 |
return Types.this.notSoftSubtype(t, s); |
|
1897 |
} finally { |
|
1898 |
cache.remove(pair); |
|
1899 |
} |
|
1900 |
} else { |
|
1901 |
return false; |
|
1902 |
} |
|
1903 |
} |
|
1904 |
||
1905 |
@Override |
|
1906 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
1907 |
if (t.isUnbound()) |
|
1908 |
return false; |
|
1909 |
||
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1910 |
if (!s.hasTag(WILDCARD)) { |
10 | 1911 |
if (t.isExtendsBound()) |
1912 |
return notSoftSubtypeRecursive(s, t.type); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1913 |
else |
10 | 1914 |
return notSoftSubtypeRecursive(t.type, s); |
1915 |
} |
|
1916 |
||
1917 |
if (s.isUnbound()) |
|
1918 |
return false; |
|
1919 |
||
1920 |
if (t.isExtendsBound()) { |
|
1921 |
if (s.isExtendsBound()) |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1922 |
return !isCastableRecursive(t.type, wildUpperBound(s)); |
10 | 1923 |
else if (s.isSuperBound()) |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1924 |
return notSoftSubtypeRecursive(wildLowerBound(s), t.type); |
10 | 1925 |
} else if (t.isSuperBound()) { |
1926 |
if (s.isExtendsBound()) |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1927 |
return notSoftSubtypeRecursive(t.type, wildUpperBound(s)); |
10 | 1928 |
} |
1929 |
return false; |
|
1930 |
} |
|
1931 |
}; |
|
1932 |
// </editor-fold> |
|
1933 |
||
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1934 |
// <editor-fold defaultstate="collapsed" desc="cvarLowerBounds"> |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1935 |
public List<Type> cvarLowerBounds(List<Type> ts) { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
1936 |
return ts.map(cvarLowerBoundMapping); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1937 |
} |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
1938 |
private final TypeMapping<Void> cvarLowerBoundMapping = new TypeMapping<Void>() { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
1939 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
1940 |
public Type visitCapturedType(CapturedType t, Void _unused) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
1941 |
return cvarLowerBound(t); |
10 | 1942 |
} |
1943 |
}; |
|
1944 |
// </editor-fold> |
|
1945 |
||
1946 |
// <editor-fold defaultstate="collapsed" desc="notSoftSubtype"> |
|
1947 |
/** |
|
1948 |
* This relation answers the question: is impossible that |
|
1949 |
* something of type `t' can be a subtype of `s'? This is |
|
1950 |
* different from the question "is `t' not a subtype of `s'?" |
|
1951 |
* when type variables are involved: Integer is not a subtype of T |
|
14259 | 1952 |
* where {@code <T extends Number>} but it is not true that Integer cannot |
10 | 1953 |
* possibly be a subtype of T. |
1954 |
*/ |
|
1955 |
public boolean notSoftSubtype(Type t, Type s) { |
|
1956 |
if (t == s) return false; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1957 |
if (t.hasTag(TYPEVAR)) { |
10 | 1958 |
TypeVar tv = (TypeVar) t; |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
1959 |
return !isCastable(tv.getUpperBound(), |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1960 |
relaxBound(s), |
14547 | 1961 |
noWarnings); |
10 | 1962 |
} |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
1963 |
if (!s.hasTag(WILDCARD)) |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1964 |
s = cvarUpperBound(s); |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1965 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1966 |
return !isSubtype(t, relaxBound(s)); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1967 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1968 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1969 |
private Type relaxBound(Type t) { |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
1970 |
return (t.hasTag(TYPEVAR)) ? |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
1971 |
rewriteQuantifiers(skipTypeVars(t, false), true, true) : |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
1972 |
t; |
10 | 1973 |
} |
1974 |
// </editor-fold> |
|
1975 |
||
1976 |
// <editor-fold defaultstate="collapsed" desc="isReifiable"> |
|
1977 |
public boolean isReifiable(Type t) { |
|
1978 |
return isReifiable.visit(t); |
|
1979 |
} |
|
1980 |
// where |
|
1981 |
private UnaryVisitor<Boolean> isReifiable = new UnaryVisitor<Boolean>() { |
|
1982 |
||
1983 |
public Boolean visitType(Type t, Void ignored) { |
|
1984 |
return true; |
|
1985 |
} |
|
1986 |
||
1987 |
@Override |
|
1988 |
public Boolean visitClassType(ClassType t, Void ignored) { |
|
3554
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1989 |
if (t.isCompound()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1990 |
return false; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1991 |
else { |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1992 |
if (!t.isParameterized()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1993 |
return true; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1994 |
|
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1995 |
for (Type param : t.allparams()) { |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1996 |
if (!param.isUnbound()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1997 |
return false; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1998 |
} |
10 | 1999 |
return true; |
2000 |
} |
|
2001 |
} |
|
2002 |
||
2003 |
@Override |
|
2004 |
public Boolean visitArrayType(ArrayType t, Void ignored) { |
|
2005 |
return visit(t.elemtype); |
|
2006 |
} |
|
2007 |
||
2008 |
@Override |
|
2009 |
public Boolean visitTypeVar(TypeVar t, Void ignored) { |
|
2010 |
return false; |
|
2011 |
} |
|
2012 |
}; |
|
2013 |
// </editor-fold> |
|
2014 |
||
2015 |
// <editor-fold defaultstate="collapsed" desc="Array Utils"> |
|
2016 |
public boolean isArray(Type t) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2017 |
while (t.hasTag(WILDCARD)) |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
2018 |
t = wildUpperBound(t); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2019 |
return t.hasTag(ARRAY); |
10 | 2020 |
} |
2021 |
||
2022 |
/** |
|
2023 |
* The element type of an array. |
|
2024 |
*/ |
|
2025 |
public Type elemtype(Type t) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2026 |
switch (t.getTag()) { |
10 | 2027 |
case WILDCARD: |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
2028 |
return elemtype(wildUpperBound(t)); |
10 | 2029 |
case ARRAY: |
2030 |
return ((ArrayType)t).elemtype; |
|
2031 |
case FORALL: |
|
2032 |
return elemtype(((ForAll)t).qtype); |
|
2033 |
case ERROR: |
|
2034 |
return t; |
|
2035 |
default: |
|
2036 |
return null; |
|
2037 |
} |
|
2038 |
} |
|
2039 |
||
7635
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2040 |
public Type elemtypeOrType(Type t) { |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2041 |
Type elemtype = elemtype(t); |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2042 |
return elemtype != null ? |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2043 |
elemtype : |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2044 |
t; |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2045 |
} |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
2046 |
|
10 | 2047 |
/** |
2048 |
* Mapping to take element type of an arraytype |
|
2049 |
*/ |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2050 |
private TypeMapping<Void> elemTypeFun = new TypeMapping<Void>() { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2051 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2052 |
public Type visitArrayType(ArrayType t, Void _unused) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2053 |
return t.elemtype; |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2054 |
} |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2055 |
|
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2056 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2057 |
public Type visitTypeVar(TypeVar t, Void _unused) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2058 |
return visit(skipTypeVars(t, false)); |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
2059 |
} |
10 | 2060 |
}; |
2061 |
||
2062 |
/** |
|
2063 |
* The number of dimensions of an array type. |
|
2064 |
*/ |
|
2065 |
public int dimensions(Type t) { |
|
2066 |
int result = 0; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2067 |
while (t.hasTag(ARRAY)) { |
10 | 2068 |
result++; |
2069 |
t = elemtype(t); |
|
2070 |
} |
|
2071 |
return result; |
|
2072 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2073 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2074 |
/** |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2075 |
* Returns an ArrayType with the component type t |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2076 |
* |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2077 |
* @param t The component type of the ArrayType |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2078 |
* @return the ArrayType for the given component |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2079 |
*/ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2080 |
public ArrayType makeArrayType(Type t) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2081 |
if (t.hasTag(VOID) || t.hasTag(PACKAGE)) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2082 |
Assert.error("Type t must not be a VOID or PACKAGE type, " + t.toString()); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2083 |
} |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2084 |
return new ArrayType(t, syms.arrayClass); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
2085 |
} |
10 | 2086 |
// </editor-fold> |
2087 |
||
2088 |
// <editor-fold defaultstate="collapsed" desc="asSuper"> |
|
2089 |
/** |
|
2090 |
* Return the (most specific) base type of t that starts with the |
|
2091 |
* given symbol. If none exists, return null. |
|
2092 |
* |
|
28800
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28459
diff
changeset
|
2093 |
* Caveat Emptor: Since javac represents the class of all arrays with a singleton |
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28459
diff
changeset
|
2094 |
* symbol Symtab.arrayClass, which by being a singleton cannot hold any discriminant, |
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28459
diff
changeset
|
2095 |
* this method could yield surprising answers when invoked on arrays. For example when |
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28459
diff
changeset
|
2096 |
* invoked with t being byte [] and sym being t.sym itself, asSuper would answer null. |
35f9042d53b3
8069265: ClassCastException when compiled with JDK 9b08+, JDK8 compiles OK.
jlahoda
parents:
28459
diff
changeset
|
2097 |
* |
10 | 2098 |
* @param t a type |
2099 |
* @param sym a symbol |
|
2100 |
*/ |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2101 |
public Type asSuper(Type t, Symbol sym) { |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2102 |
/* Some examples: |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2103 |
* |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2104 |
* (Enum<E>, Comparable) => Comparable<E> |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2105 |
* (c.s.s.d.AttributeTree.ValueKind, Enum) => Enum<c.s.s.d.AttributeTree.ValueKind> |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2106 |
* (c.s.s.t.ExpressionTree, c.s.s.t.Tree) => c.s.s.t.Tree |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2107 |
* (j.u.List<capture#160 of ? extends c.s.s.d.DocTree>, Iterable) => |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2108 |
* Iterable<capture#160 of ? extends c.s.s.d.DocTree> |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2109 |
*/ |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2110 |
if (sym.type == syms.objectType) { //optimization |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2111 |
return syms.objectType; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
2112 |
} |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2113 |
return asSuper.visit(t, sym); |
10 | 2114 |
} |
2115 |
// where |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2116 |
private SimpleVisitor<Type,Symbol> asSuper = new SimpleVisitor<Type,Symbol>() { |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2117 |
|
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2118 |
public Type visitType(Type t, Symbol sym) { |
10 | 2119 |
return null; |
2120 |
} |
|
2121 |
||
2122 |
@Override |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2123 |
public Type visitClassType(ClassType t, Symbol sym) { |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2124 |
if (t.tsym == sym) |
10 | 2125 |
return t; |
2126 |
||
2127 |
Type st = supertype(t); |
|
24397
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2128 |
if (st.hasTag(CLASS) || st.hasTag(TYPEVAR)) { |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2129 |
Type x = asSuper(st, sym); |
10 | 2130 |
if (x != null) |
2131 |
return x; |
|
2132 |
} |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2133 |
if ((sym.flags() & INTERFACE) != 0) { |
10 | 2134 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |
24397
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2135 |
if (!l.head.hasTag(ERROR)) { |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2136 |
Type x = asSuper(l.head, sym); |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2137 |
if (x != null) |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2138 |
return x; |
32aef69ee177
8042656: Inference produces spurious error for intersection type bounds check
dlsmith
parents:
24396
diff
changeset
|
2139 |
} |
10 | 2140 |
} |
2141 |
} |
|
2142 |
return null; |
|
2143 |
} |
|
2144 |
||
2145 |
@Override |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2146 |
public Type visitArrayType(ArrayType t, Symbol sym) { |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2147 |
return isSubtype(t, sym.type) ? sym.type : null; |
10 | 2148 |
} |
2149 |
||
2150 |
@Override |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2151 |
public Type visitTypeVar(TypeVar t, Symbol sym) { |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2152 |
if (t.tsym == sym) |
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
2153 |
return t; |
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
2154 |
else |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2155 |
return asSuper(t.getUpperBound(), sym); |
10 | 2156 |
} |
2157 |
||
2158 |
@Override |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2159 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2160 |
return t; |
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
2161 |
} |
10 | 2162 |
}; |
2163 |
||
2164 |
/** |
|
2165 |
* Return the base type of t or any of its outer types that starts |
|
2166 |
* with the given symbol. If none exists, return null. |
|
2167 |
* |
|
2168 |
* @param t a type |
|
2169 |
* @param sym a symbol |
|
2170 |
*/ |
|
2171 |
public Type asOuterSuper(Type t, Symbol sym) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2172 |
switch (t.getTag()) { |
10 | 2173 |
case CLASS: |
2174 |
do { |
|
2175 |
Type s = asSuper(t, sym); |
|
2176 |
if (s != null) return s; |
|
2177 |
t = t.getEnclosingType(); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2178 |
} while (t.hasTag(CLASS)); |
10 | 2179 |
return null; |
2180 |
case ARRAY: |
|
2181 |
return isSubtype(t, sym.type) ? sym.type : null; |
|
2182 |
case TYPEVAR: |
|
2183 |
return asSuper(t, sym); |
|
2184 |
case ERROR: |
|
2185 |
return t; |
|
2186 |
default: |
|
2187 |
return null; |
|
2188 |
} |
|
2189 |
} |
|
2190 |
||
2191 |
/** |
|
2192 |
* Return the base type of t or any of its enclosing types that |
|
2193 |
* starts with the given symbol. If none exists, return null. |
|
2194 |
* |
|
2195 |
* @param t a type |
|
2196 |
* @param sym a symbol |
|
2197 |
*/ |
|
2198 |
public Type asEnclosingSuper(Type t, Symbol sym) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2199 |
switch (t.getTag()) { |
10 | 2200 |
case CLASS: |
2201 |
do { |
|
2202 |
Type s = asSuper(t, sym); |
|
2203 |
if (s != null) return s; |
|
2204 |
Type outer = t.getEnclosingType(); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2205 |
t = (outer.hasTag(CLASS)) ? outer : |
10 | 2206 |
(t.tsym.owner.enclClass() != null) ? t.tsym.owner.enclClass().type : |
2207 |
Type.noType; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2208 |
} while (t.hasTag(CLASS)); |
10 | 2209 |
return null; |
2210 |
case ARRAY: |
|
2211 |
return isSubtype(t, sym.type) ? sym.type : null; |
|
2212 |
case TYPEVAR: |
|
2213 |
return asSuper(t, sym); |
|
2214 |
case ERROR: |
|
2215 |
return t; |
|
2216 |
default: |
|
2217 |
return null; |
|
2218 |
} |
|
2219 |
} |
|
2220 |
// </editor-fold> |
|
2221 |
||
2222 |
// <editor-fold defaultstate="collapsed" desc="memberType"> |
|
2223 |
/** |
|
2224 |
* The type of given symbol, seen as a member of t. |
|
2225 |
* |
|
2226 |
* @param t a type |
|
2227 |
* @param sym a symbol |
|
2228 |
*/ |
|
2229 |
public Type memberType(Type t, Symbol sym) { |
|
2230 |
return (sym.flags() & STATIC) != 0 |
|
2231 |
? sym.type |
|
2232 |
: memberType.visit(t, sym); |
|
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2233 |
} |
10 | 2234 |
// where |
2235 |
private SimpleVisitor<Type,Symbol> memberType = new SimpleVisitor<Type,Symbol>() { |
|
2236 |
||
2237 |
public Type visitType(Type t, Symbol sym) { |
|
2238 |
return sym.type; |
|
2239 |
} |
|
2240 |
||
2241 |
@Override |
|
2242 |
public Type visitWildcardType(WildcardType t, Symbol sym) { |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
2243 |
return memberType(wildUpperBound(t), sym); |
10 | 2244 |
} |
2245 |
||
2246 |
@Override |
|
2247 |
public Type visitClassType(ClassType t, Symbol sym) { |
|
2248 |
Symbol owner = sym.owner; |
|
2249 |
long flags = sym.flags(); |
|
2250 |
if (((flags & STATIC) == 0) && owner.type.isParameterized()) { |
|
2251 |
Type base = asOuterSuper(t, owner); |
|
1469
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
2252 |
//if t is an intersection type T = CT & I1 & I2 ... & In |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
2253 |
//its supertypes CT, I1, ... In might contain wildcards |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
2254 |
//so we need to go through capture conversion |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
2255 |
base = t.isCompound() ? capture(base) : base; |
10 | 2256 |
if (base != null) { |
2257 |
List<Type> ownerParams = owner.type.allparams(); |
|
2258 |
List<Type> baseParams = base.allparams(); |
|
2259 |
if (ownerParams.nonEmpty()) { |
|
2260 |
if (baseParams.isEmpty()) { |
|
2261 |
// then base is a raw type |
|
2262 |
return erasure(sym.type); |
|
2263 |
} else { |
|
2264 |
return subst(sym.type, ownerParams, baseParams); |
|
2265 |
} |
|
2266 |
} |
|
2267 |
} |
|
2268 |
} |
|
2269 |
return sym.type; |
|
2270 |
} |
|
2271 |
||
2272 |
@Override |
|
2273 |
public Type visitTypeVar(TypeVar t, Symbol sym) { |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2274 |
return memberType(t.getUpperBound(), sym); |
10 | 2275 |
} |
2276 |
||
2277 |
@Override |
|
2278 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
|
2279 |
return t; |
|
2280 |
} |
|
2281 |
}; |
|
2282 |
// </editor-fold> |
|
2283 |
||
2284 |
// <editor-fold defaultstate="collapsed" desc="isAssignable"> |
|
2285 |
public boolean isAssignable(Type t, Type s) { |
|
14547 | 2286 |
return isAssignable(t, s, noWarnings); |
10 | 2287 |
} |
2288 |
||
2289 |
/** |
|
2290 |
* Is t assignable to s?<br> |
|
2291 |
* Equivalent to subtype except for constant values and raw |
|
2292 |
* types.<br> |
|
2293 |
* (not defined for Method and ForAll types) |
|
2294 |
*/ |
|
2295 |
public boolean isAssignable(Type t, Type s, Warner warn) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2296 |
if (t.hasTag(ERROR)) |
10 | 2297 |
return true; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2298 |
if (t.getTag().isSubRangeOf(INT) && t.constValue() != null) { |
10 | 2299 |
int value = ((Number)t.constValue()).intValue(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2300 |
switch (s.getTag()) { |
10 | 2301 |
case BYTE: |
2302 |
case CHAR: |
|
42973
3795332b55c7
8171132: Improve class reading of invalid or out-of-range ConstantValue attributes
cushon
parents:
42828
diff
changeset
|
2303 |
case SHORT: |
3795332b55c7
8171132: Improve class reading of invalid or out-of-range ConstantValue attributes
cushon
parents:
42828
diff
changeset
|
2304 |
case INT: |
3795332b55c7
8171132: Improve class reading of invalid or out-of-range ConstantValue attributes
cushon
parents:
42828
diff
changeset
|
2305 |
if (s.getTag().checkRange(value)) |
10 | 2306 |
return true; |
2307 |
break; |
|
2308 |
case CLASS: |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2309 |
switch (unboxedType(s).getTag()) { |
10 | 2310 |
case BYTE: |
2311 |
case CHAR: |
|
2312 |
case SHORT: |
|
2313 |
return isAssignable(t, unboxedType(s), warn); |
|
2314 |
} |
|
2315 |
break; |
|
2316 |
} |
|
2317 |
} |
|
2318 |
return isConvertible(t, s, warn); |
|
2319 |
} |
|
2320 |
// </editor-fold> |
|
2321 |
||
2322 |
// <editor-fold defaultstate="collapsed" desc="erasure"> |
|
2323 |
/** |
|
2324 |
* The erasure of t {@code |t|} -- the type that results when all |
|
2325 |
* type parameters in t are deleted. |
|
2326 |
*/ |
|
2327 |
public Type erasure(Type t) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2328 |
return eraseNotNeeded(t) ? t : erasure(t, false); |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2329 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2330 |
//where |
13633
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2331 |
private boolean eraseNotNeeded(Type t) { |
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2332 |
// We don't want to erase primitive types and String type as that |
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2333 |
// operation is idempotent. Also, erasing these could result in loss |
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2334 |
// of information such as constant values attached to such types. |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2335 |
return (t.isPrimitive()) || (syms.stringType.tsym == t.tsym); |
13633
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2336 |
} |
0ea4283af723
7181320: javac NullPointerException for switch labels with cast to String expressions
sundar
parents:
12468
diff
changeset
|
2337 |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2338 |
private Type erasure(Type t, boolean recurse) { |
24396 | 2339 |
if (t.isPrimitive()) { |
10 | 2340 |
return t; /* fast special case */ |
24396 | 2341 |
} else { |
2342 |
Type out = erasure.visit(t, recurse); |
|
2343 |
return out; |
|
2344 |
} |
|
45756
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45754
diff
changeset
|
2345 |
} |
10 | 2346 |
// where |
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
2347 |
private TypeMapping<Boolean> erasure = new StructuralTypeMapping<Boolean>() { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2348 |
private Type combineMetadata(final Type s, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2349 |
final Type t) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2350 |
if (t.getMetadata() != TypeMetadata.EMPTY) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2351 |
switch (s.getKind()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2352 |
case OTHER: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2353 |
case UNION: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2354 |
case INTERSECTION: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2355 |
case PACKAGE: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2356 |
case EXECUTABLE: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2357 |
case NONE: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2358 |
case VOID: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2359 |
case ERROR: |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2360 |
return s; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2361 |
default: return s.cloneWithMetadata(s.getMetadata().without(Kind.ANNOTATIONS)); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2362 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2363 |
} else { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2364 |
return s; |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2365 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2366 |
} |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2367 |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2368 |
public Type visitType(Type t, Boolean recurse) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
2369 |
if (t.isPrimitive()) |
10 | 2370 |
return t; /*fast special case*/ |
24396 | 2371 |
else { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2372 |
//other cases already handled |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2373 |
return combineMetadata(t, t); |
24396 | 2374 |
} |
10 | 2375 |
} |
2376 |
||
2377 |
@Override |
|
33915
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2378 |
public Type visitWildcardType(WildcardType t, Boolean recurse) { |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2379 |
Type erased = erasure(wildUpperBound(t), recurse); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2380 |
return combineMetadata(erased, t); |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2381 |
} |
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2382 |
|
66f0ce11ae22
8142931: java compiler: type erasure doesn't work since 9-b28
sadayapalam
parents:
33709
diff
changeset
|
2383 |
@Override |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2384 |
public Type visitClassType(ClassType t, Boolean recurse) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2385 |
Type erased = t.tsym.erasure(Types.this); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2386 |
if (recurse) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2387 |
erased = new ErasedClassType(erased.getEnclosingType(),erased.tsym, |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2388 |
t.getMetadata().without(Kind.ANNOTATIONS)); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2389 |
return erased; |
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2390 |
} else { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2391 |
return combineMetadata(erased, t); |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2392 |
} |
10 | 2393 |
} |
2394 |
||
2395 |
@Override |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2396 |
public Type visitTypeVar(TypeVar t, Boolean recurse) { |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2397 |
Type erased = erasure(t.getUpperBound(), recurse); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
2398 |
return combineMetadata(erased, t); |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2399 |
} |
10 | 2400 |
}; |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2401 |
|
10 | 2402 |
public List<Type> erasure(List<Type> ts) { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2403 |
return erasure.visit(ts, false); |
10 | 2404 |
} |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2405 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2406 |
public Type erasureRecursive(Type t) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2407 |
return erasure(t, true); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2408 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2409 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2410 |
public List<Type> erasureRecursive(List<Type> ts) { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2411 |
return erasure.visit(ts, true); |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2412 |
} |
10 | 2413 |
// </editor-fold> |
2414 |
||
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2415 |
// <editor-fold defaultstate="collapsed" desc="makeIntersectionType"> |
10 | 2416 |
/** |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2417 |
* Make an intersection type from non-empty list of types. The list should be ordered according to |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2418 |
* {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2419 |
* Hence, this version of makeIntersectionType may not be called during a classfile read. |
10 | 2420 |
* |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2421 |
* @param bounds the types from which the intersection type is formed |
10 | 2422 |
*/ |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2423 |
public IntersectionClassType makeIntersectionType(List<Type> bounds) { |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2424 |
return makeIntersectionType(bounds, bounds.head.tsym.isInterface()); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2425 |
} |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2426 |
|
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2427 |
/** |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2428 |
* Make an intersection type from non-empty list of types. The list should be ordered according to |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2429 |
* {@link TypeSymbol#precedes(TypeSymbol, Types)}. This does not cause symbol completion as |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2430 |
* an extra parameter indicates as to whether all bounds are interfaces - in which case the |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2431 |
* supertype is implicitly assumed to be 'Object'. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2432 |
* |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2433 |
* @param bounds the types from which the intersection type is formed |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2434 |
* @param allInterfaces are all bounds interface types? |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2435 |
*/ |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2436 |
public IntersectionClassType makeIntersectionType(List<Type> bounds, boolean allInterfaces) { |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2437 |
Assert.check(bounds.nonEmpty()); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2438 |
Type firstExplicitBound = bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2439 |
if (allInterfaces) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2440 |
bounds = bounds.prepend(syms.objectType); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2441 |
} |
10 | 2442 |
ClassSymbol bc = |
2443 |
new ClassSymbol(ABSTRACT|PUBLIC|SYNTHETIC|COMPOUND|ACYCLIC, |
|
2444 |
Type.moreInfo |
|
2445 |
? names.fromString(bounds.toString()) |
|
2446 |
: names.empty, |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2447 |
null, |
10 | 2448 |
syms.noSymbol); |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2449 |
IntersectionClassType intersectionType = new IntersectionClassType(bounds, bc, allInterfaces); |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2450 |
bc.type = intersectionType; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2451 |
bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ? |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2452 |
syms.objectType : // error condition, recover |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2453 |
erasure(firstExplicitBound); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
2454 |
bc.members_field = WriteableScope.create(bc); |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2455 |
return intersectionType; |
10 | 2456 |
} |
2457 |
// </editor-fold> |
|
2458 |
||
2459 |
// <editor-fold defaultstate="collapsed" desc="supertype"> |
|
2460 |
public Type supertype(Type t) { |
|
2461 |
return supertype.visit(t); |
|
2462 |
} |
|
2463 |
// where |
|
2464 |
private UnaryVisitor<Type> supertype = new UnaryVisitor<Type>() { |
|
2465 |
||
2466 |
public Type visitType(Type t, Void ignored) { |
|
2467 |
// A note on wildcards: there is no good way to |
|
2468 |
// determine a supertype for a super bounded wildcard. |
|
25276
59c17f73fee3
8034147: javac crashes with a NullPointerException during bounds checking
dlsmith
parents:
25273
diff
changeset
|
2469 |
return Type.noType; |
10 | 2470 |
} |
2471 |
||
2472 |
@Override |
|
2473 |
public Type visitClassType(ClassType t, Void ignored) { |
|
2474 |
if (t.supertype_field == null) { |
|
2475 |
Type supertype = ((ClassSymbol)t.tsym).getSuperclass(); |
|
2476 |
// An interface has no superclass; its supertype is Object. |
|
2477 |
if (t.isInterface()) |
|
2478 |
supertype = ((ClassType)t.tsym.type).supertype_field; |
|
2479 |
if (t.supertype_field == null) { |
|
2480 |
List<Type> actuals = classBound(t).allparams(); |
|
2481 |
List<Type> formals = t.tsym.type.allparams(); |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2482 |
if (t.hasErasedSupertypes()) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2483 |
t.supertype_field = erasureRecursive(supertype); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2484 |
} else if (formals.nonEmpty()) { |
10 | 2485 |
t.supertype_field = subst(supertype, formals, actuals); |
2486 |
} |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2487 |
else { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2488 |
t.supertype_field = supertype; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2489 |
} |
10 | 2490 |
} |
2491 |
} |
|
2492 |
return t.supertype_field; |
|
2493 |
} |
|
2494 |
||
2495 |
/** |
|
2496 |
* The supertype is always a class type. If the type |
|
2497 |
* variable's bounds start with a class type, this is also |
|
2498 |
* the supertype. Otherwise, the supertype is |
|
2499 |
* java.lang.Object. |
|
2500 |
*/ |
|
2501 |
@Override |
|
2502 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2503 |
if (t.getUpperBound().hasTag(TYPEVAR) || |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2504 |
(!t.getUpperBound().isCompound() && !t.getUpperBound().isInterface())) { |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2505 |
return t.getUpperBound(); |
10 | 2506 |
} else { |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2507 |
return supertype(t.getUpperBound()); |
10 | 2508 |
} |
2509 |
} |
|
2510 |
||
2511 |
@Override |
|
2512 |
public Type visitArrayType(ArrayType t, Void ignored) { |
|
2513 |
if (t.elemtype.isPrimitive() || isSameType(t.elemtype, syms.objectType)) |
|
2514 |
return arraySuperType(); |
|
2515 |
else |
|
2516 |
return new ArrayType(supertype(t.elemtype), t.tsym); |
|
2517 |
} |
|
2518 |
||
2519 |
@Override |
|
2520 |
public Type visitErrorType(ErrorType t, Void ignored) { |
|
18915
dcc9c8265f65
8016640: compiler hangs if the generics arity of a base class is wrong
mcimadamore
parents:
18914
diff
changeset
|
2521 |
return Type.noType; |
10 | 2522 |
} |
2523 |
}; |
|
2524 |
// </editor-fold> |
|
2525 |
||
2526 |
// <editor-fold defaultstate="collapsed" desc="interfaces"> |
|
2527 |
/** |
|
2528 |
* Return the interfaces implemented by this class. |
|
2529 |
*/ |
|
2530 |
public List<Type> interfaces(Type t) { |
|
2531 |
return interfaces.visit(t); |
|
2532 |
} |
|
2533 |
// where |
|
2534 |
private UnaryVisitor<List<Type>> interfaces = new UnaryVisitor<List<Type>>() { |
|
2535 |
||
2536 |
public List<Type> visitType(Type t, Void ignored) { |
|
2537 |
return List.nil(); |
|
2538 |
} |
|
2539 |
||
2540 |
@Override |
|
2541 |
public List<Type> visitClassType(ClassType t, Void ignored) { |
|
2542 |
if (t.interfaces_field == null) { |
|
2543 |
List<Type> interfaces = ((ClassSymbol)t.tsym).getInterfaces(); |
|
2544 |
if (t.interfaces_field == null) { |
|
2545 |
// If t.interfaces_field is null, then t must |
|
2546 |
// be a parameterized type (not to be confused |
|
2547 |
// with a generic type declaration). |
|
2548 |
// Terminology: |
|
2549 |
// Parameterized type: List<String> |
|
2550 |
// Generic type declaration: class List<E> { ... } |
|
2551 |
// So t corresponds to List<String> and |
|
2552 |
// t.tsym.type corresponds to List<E>. |
|
2553 |
// The reason t must be parameterized type is |
|
2554 |
// that completion will happen as a side |
|
2555 |
// effect of calling |
|
2556 |
// ClassSymbol.getInterfaces. Since |
|
2557 |
// t.interfaces_field is null after |
|
2558 |
// completion, we can assume that t is not the |
|
2559 |
// type of a class/interface declaration. |
|
8032 | 2560 |
Assert.check(t != t.tsym.type, t); |
10 | 2561 |
List<Type> actuals = t.allparams(); |
2562 |
List<Type> formals = t.tsym.type.allparams(); |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2563 |
if (t.hasErasedSupertypes()) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2564 |
t.interfaces_field = erasureRecursive(interfaces); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2565 |
} else if (formals.nonEmpty()) { |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
2566 |
t.interfaces_field = subst(interfaces, formals, actuals); |
10 | 2567 |
} |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2568 |
else { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2569 |
t.interfaces_field = interfaces; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
2570 |
} |
10 | 2571 |
} |
2572 |
} |
|
2573 |
return t.interfaces_field; |
|
2574 |
} |
|
2575 |
||
2576 |
@Override |
|
2577 |
public List<Type> visitTypeVar(TypeVar t, Void ignored) { |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2578 |
if (t.getUpperBound().isCompound()) |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2579 |
return interfaces(t.getUpperBound()); |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2580 |
|
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2581 |
if (t.getUpperBound().isInterface()) |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2582 |
return List.of(t.getUpperBound()); |
10 | 2583 |
|
2584 |
return List.nil(); |
|
2585 |
} |
|
2586 |
}; |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
2587 |
|
20252
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2588 |
public List<Type> directSupertypes(Type t) { |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2589 |
return directSupertypes.visit(t); |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2590 |
} |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2591 |
// where |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2592 |
private final UnaryVisitor<List<Type>> directSupertypes = new UnaryVisitor<List<Type>>() { |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2593 |
|
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2594 |
public List<Type> visitType(final Type type, final Void ignored) { |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2595 |
if (!type.isIntersection()) { |
20252
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2596 |
final Type sup = supertype(type); |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2597 |
return (sup == Type.noType || sup == type || sup == null) |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2598 |
? interfaces(type) |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2599 |
: interfaces(type).prepend(sup); |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2600 |
} else { |
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
2601 |
return ((IntersectionClassType)type).getExplicitComponents(); |
20252
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2602 |
} |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2603 |
} |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2604 |
}; |
fae5c47ba7a4
6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents:
20249
diff
changeset
|
2605 |
|
14547 | 2606 |
public boolean isDirectSuperInterface(TypeSymbol isym, TypeSymbol origin) { |
2607 |
for (Type i2 : interfaces(origin.type)) { |
|
2608 |
if (isym == i2.tsym) return true; |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
2609 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
2610 |
return false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
2611 |
} |
10 | 2612 |
// </editor-fold> |
2613 |
||
2614 |
// <editor-fold defaultstate="collapsed" desc="isDerivedRaw"> |
|
22163 | 2615 |
Map<Type,Boolean> isDerivedRawCache = new HashMap<>(); |
10 | 2616 |
|
2617 |
public boolean isDerivedRaw(Type t) { |
|
2618 |
Boolean result = isDerivedRawCache.get(t); |
|
2619 |
if (result == null) { |
|
2620 |
result = isDerivedRawInternal(t); |
|
2621 |
isDerivedRawCache.put(t, result); |
|
2622 |
} |
|
2623 |
return result; |
|
2624 |
} |
|
2625 |
||
2626 |
public boolean isDerivedRawInternal(Type t) { |
|
2627 |
if (t.isErroneous()) |
|
2628 |
return false; |
|
2629 |
return |
|
2630 |
t.isRaw() || |
|
25276
59c17f73fee3
8034147: javac crashes with a NullPointerException during bounds checking
dlsmith
parents:
25273
diff
changeset
|
2631 |
supertype(t) != Type.noType && isDerivedRaw(supertype(t)) || |
10 | 2632 |
isDerivedRaw(interfaces(t)); |
2633 |
} |
|
2634 |
||
2635 |
public boolean isDerivedRaw(List<Type> ts) { |
|
2636 |
List<Type> l = ts; |
|
2637 |
while (l.nonEmpty() && !isDerivedRaw(l.head)) l = l.tail; |
|
2638 |
return l.nonEmpty(); |
|
2639 |
} |
|
2640 |
// </editor-fold> |
|
2641 |
||
2642 |
// <editor-fold defaultstate="collapsed" desc="setBounds"> |
|
2643 |
/** |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2644 |
* Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly, |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2645 |
* as follows: if all all bounds are interface types, the computed supertype is Object,otherwise |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2646 |
* the supertype is simply left null (in this case, the supertype is assumed to be the head of |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2647 |
* the bound list passed as second argument). Note that this check might cause a symbol completion. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2648 |
* Hence, this version of setBounds may not be called during a classfile read. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2649 |
* |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2650 |
* @param t a type variable |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2651 |
* @param bounds the bounds, must be nonempty |
10 | 2652 |
*/ |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2653 |
public void setBounds(TypeVar t, List<Type> bounds) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2654 |
setBounds(t, bounds, bounds.head.tsym.isInterface()); |
10 | 2655 |
} |
2656 |
||
2657 |
/** |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2658 |
* Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2659 |
* This does not cause symbol completion as an extra parameter indicates as to whether all bounds |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2660 |
* are interfaces - in which case the supertype is implicitly assumed to be 'Object'. |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2661 |
* |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2662 |
* @param t a type variable |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2663 |
* @param bounds the bounds, must be nonempty |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
2664 |
* @param allInterfaces are all bounds interface types? |
10 | 2665 |
*/ |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2666 |
public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) { |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2667 |
t.setUpperBound( bounds.tail.isEmpty() ? |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14723
diff
changeset
|
2668 |
bounds.head : |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2669 |
makeIntersectionType(bounds, allInterfaces) ); |
10 | 2670 |
t.rank_field = -1; |
2671 |
} |
|
2672 |
// </editor-fold> |
|
2673 |
||
2674 |
// <editor-fold defaultstate="collapsed" desc="getBounds"> |
|
2675 |
/** |
|
2676 |
* Return list of bounds of the given type variable. |
|
2677 |
*/ |
|
2678 |
public List<Type> getBounds(TypeVar t) { |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2679 |
if (t.getUpperBound().hasTag(NONE)) |
14547 | 2680 |
return List.nil(); |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2681 |
else if (t.getUpperBound().isErroneous() || !t.getUpperBound().isCompound()) |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
2682 |
return List.of(t.getUpperBound()); |
10 | 2683 |
else if ((erasure(t).tsym.flags() & INTERFACE) == 0) |
2684 |
return interfaces(t).prepend(supertype(t)); |
|
2685 |
else |
|
2686 |
// No superclass was given in bounds. |
|
2687 |
// In this case, supertype is Object, erasure is first interface. |
|
2688 |
return interfaces(t); |
|
2689 |
} |
|
2690 |
// </editor-fold> |
|
2691 |
||
2692 |
// <editor-fold defaultstate="collapsed" desc="classBound"> |
|
2693 |
/** |
|
2694 |
* If the given type is a (possibly selected) type variable, |
|
2695 |
* return the bounding class of this type, otherwise return the |
|
2696 |
* type itself. |
|
2697 |
*/ |
|
2698 |
public Type classBound(Type t) { |
|
2699 |
return classBound.visit(t); |
|
2700 |
} |
|
2701 |
// where |
|
2702 |
private UnaryVisitor<Type> classBound = new UnaryVisitor<Type>() { |
|
2703 |
||
2704 |
public Type visitType(Type t, Void ignored) { |
|
2705 |
return t; |
|
2706 |
} |
|
2707 |
||
2708 |
@Override |
|
2709 |
public Type visitClassType(ClassType t, Void ignored) { |
|
2710 |
Type outer1 = classBound(t.getEnclosingType()); |
|
2711 |
if (outer1 != t.getEnclosingType()) |
|
24396 | 2712 |
return new ClassType(outer1, t.getTypeArguments(), t.tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
2713 |
t.getMetadata()); |
10 | 2714 |
else |
2715 |
return t; |
|
2716 |
} |
|
2717 |
||
2718 |
@Override |
|
2719 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
2720 |
return classBound(supertype(t)); |
|
2721 |
} |
|
2722 |
||
2723 |
@Override |
|
2724 |
public Type visitErrorType(ErrorType t, Void ignored) { |
|
2725 |
return t; |
|
2726 |
} |
|
2727 |
}; |
|
2728 |
// </editor-fold> |
|
2729 |
||
2730 |
// <editor-fold defaultstate="collapsed" desc="sub signature / override equivalence"> |
|
2731 |
/** |
|
2732 |
* Returns true iff the first signature is a <em>sub |
|
2733 |
* signature</em> of the other. This is <b>not</b> an equivalence |
|
2734 |
* relation. |
|
2735 |
* |
|
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
54762
diff
changeset
|
2736 |
* @jls 8.4.2 Method Signature |
10 | 2737 |
* @see #overrideEquivalent(Type t, Type s) |
2738 |
* @param t first signature (possibly raw). |
|
2739 |
* @param s second signature (could be subjected to erasure). |
|
2740 |
* @return true if t is a sub signature of s. |
|
2741 |
*/ |
|
2742 |
public boolean isSubSignature(Type t, Type s) { |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2743 |
return isSubSignature(t, s, true); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2744 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2745 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2746 |
public boolean isSubSignature(Type t, Type s, boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2747 |
return hasSameArgs(t, s, strict) || hasSameArgs(t, erasure(s), strict); |
10 | 2748 |
} |
2749 |
||
2750 |
/** |
|
2751 |
* Returns true iff these signatures are related by <em>override |
|
2752 |
* equivalence</em>. This is the natural extension of |
|
2753 |
* isSubSignature to an equivalence relation. |
|
2754 |
* |
|
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
54762
diff
changeset
|
2755 |
* @jls 8.4.2 Method Signature |
10 | 2756 |
* @see #isSubSignature(Type t, Type s) |
2757 |
* @param t a signature (possible raw, could be subjected to |
|
2758 |
* erasure). |
|
2759 |
* @param s a signature (possible raw, could be subjected to |
|
2760 |
* erasure). |
|
2761 |
* @return true if either argument is a sub signature of the other. |
|
2762 |
*/ |
|
2763 |
public boolean overrideEquivalent(Type t, Type s) { |
|
2764 |
return hasSameArgs(t, s) || |
|
2765 |
hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s); |
|
2766 |
} |
|
2767 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2768 |
public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
2769 |
for (Symbol sym : syms.objectType.tsym.members().getSymbolsByName(msym.name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
2770 |
if (msym.overrides(sym, origin, Types.this, true)) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2771 |
return true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2772 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2773 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2774 |
return false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2775 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2776 |
|
41526
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2777 |
/** |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2778 |
* This enum defines the strategy for implementing most specific return type check |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2779 |
* during the most specific and functional interface checks. |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2780 |
*/ |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2781 |
public enum MostSpecificReturnCheck { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2782 |
/** |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2783 |
* Return r1 is more specific than r2 if {@code r1 <: r2}. Extra care required for (i) handling |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2784 |
* method type variables (if either method is generic) and (ii) subtyping should be replaced |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2785 |
* by type-equivalence for primitives. This is essentially an inlined version of |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2786 |
* {@link Types#resultSubtype(Type, Type, Warner)}, where the assignability check has been |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2787 |
* replaced with a strict subtyping check. |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2788 |
*/ |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2789 |
BASIC() { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2790 |
@Override |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2791 |
public boolean test(Type mt1, Type mt2, Types types) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2792 |
List<Type> tvars = mt1.getTypeArguments(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2793 |
List<Type> svars = mt2.getTypeArguments(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2794 |
Type t = mt1.getReturnType(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2795 |
Type s = types.subst(mt2.getReturnType(), svars, tvars); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2796 |
return types.isSameType(t, s) || |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2797 |
!t.isPrimitive() && |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2798 |
!s.isPrimitive() && |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2799 |
types.isSubtype(t, s); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2800 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2801 |
}, |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2802 |
/** |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2803 |
* Return r1 is more specific than r2 if r1 is return-type-substitutable for r2. |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2804 |
*/ |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2805 |
RTS() { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2806 |
@Override |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2807 |
public boolean test(Type mt1, Type mt2, Types types) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2808 |
return types.returnTypeSubstitutable(mt1, mt2); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2809 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2810 |
}; |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2811 |
|
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2812 |
public abstract boolean test(Type mt1, Type mt2, Types types); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2813 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2814 |
|
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2815 |
/** |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2816 |
* Merge multiple abstract methods. The preferred method is a method that is a subsignature |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2817 |
* of all the other signatures and whose return type is more specific {@see MostSpecificReturnCheck}. |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2818 |
* The resulting preferred method has a thrown clause that is the intersection of the merged |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2819 |
* methods' clauses. |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2820 |
*/ |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2821 |
public Optional<Symbol> mergeAbstracts(List<Symbol> ambiguousInOrder, Type site, boolean sigCheck) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2822 |
//first check for preconditions |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2823 |
boolean shouldErase = false; |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2824 |
List<Type> erasedParams = ambiguousInOrder.head.erasure(this).getParameterTypes(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2825 |
for (Symbol s : ambiguousInOrder) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2826 |
if ((s.flags() & ABSTRACT) == 0 || |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2827 |
(sigCheck && !isSameTypes(erasedParams, s.erasure(this).getParameterTypes()))) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2828 |
return Optional.empty(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2829 |
} else if (s.type.hasTag(FORALL)) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2830 |
shouldErase = true; |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2831 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2832 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2833 |
//then merge abstracts |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2834 |
for (MostSpecificReturnCheck mostSpecificReturnCheck : MostSpecificReturnCheck.values()) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2835 |
outer: for (Symbol s : ambiguousInOrder) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2836 |
Type mt = memberType(site, s); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2837 |
List<Type> allThrown = mt.getThrownTypes(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2838 |
for (Symbol s2 : ambiguousInOrder) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2839 |
if (s != s2) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2840 |
Type mt2 = memberType(site, s2); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2841 |
if (!isSubSignature(mt, mt2) || |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2842 |
!mostSpecificReturnCheck.test(mt, mt2, this)) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2843 |
//ambiguity cannot be resolved |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2844 |
continue outer; |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2845 |
} else { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2846 |
List<Type> thrownTypes2 = mt2.getThrownTypes(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2847 |
if (!mt.hasTag(FORALL) && shouldErase) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2848 |
thrownTypes2 = erasure(thrownTypes2); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2849 |
} else if (mt.hasTag(FORALL)) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2850 |
//subsignature implies that if most specific is generic, then all other |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2851 |
//methods are too |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2852 |
Assert.check(mt2.hasTag(FORALL)); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2853 |
// if both are generic methods, adjust thrown types ahead of intersection computation |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2854 |
thrownTypes2 = subst(thrownTypes2, mt2.getTypeArguments(), mt.getTypeArguments()); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2855 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2856 |
allThrown = chk.intersect(allThrown, thrownTypes2); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2857 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2858 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2859 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2860 |
return (allThrown == mt.getThrownTypes()) ? |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2861 |
Optional.of(s) : |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2862 |
Optional.of(new MethodSymbol( |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2863 |
s.flags(), |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2864 |
s.name, |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2865 |
createMethodTypeWithThrown(s.type, allThrown), |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2866 |
s.owner) { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2867 |
@Override |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2868 |
public Symbol baseSymbol() { |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2869 |
return s; |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2870 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2871 |
}); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2872 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2873 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2874 |
return Optional.empty(); |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2875 |
} |
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
40591
diff
changeset
|
2876 |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2877 |
// <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site"> |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2878 |
class ImplementationCache { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2879 |
|
22163 | 2880 |
private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>> _map = new WeakHashMap<>(); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2881 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2882 |
class Entry { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2883 |
final MethodSymbol cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2884 |
final Filter<Symbol> implFilter; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2885 |
final boolean checkResult; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2886 |
final int prevMark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2887 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2888 |
public Entry(MethodSymbol cachedImpl, |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2889 |
Filter<Symbol> scopeFilter, |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2890 |
boolean checkResult, |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2891 |
int prevMark) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2892 |
this.cachedImpl = cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2893 |
this.implFilter = scopeFilter; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2894 |
this.checkResult = checkResult; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2895 |
this.prevMark = prevMark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2896 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2897 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2898 |
boolean matches(Filter<Symbol> scopeFilter, boolean checkResult, int mark) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2899 |
return this.implFilter == scopeFilter && |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2900 |
this.checkResult == checkResult && |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2901 |
this.prevMark == mark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2902 |
} |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2903 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2904 |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2905 |
MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2906 |
SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2907 |
Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2908 |
if (cache == null) { |
22163 | 2909 |
cache = new HashMap<>(); |
2910 |
_map.put(ms, new SoftReference<>(cache)); |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2911 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2912 |
Entry e = cache.get(origin); |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2913 |
CompoundScope members = membersClosure(origin.type, true); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2914 |
if (e == null || |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2915 |
!e.matches(implFilter, checkResult, members.getMark())) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2916 |
MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2917 |
cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark())); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2918 |
return impl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2919 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2920 |
else { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2921 |
return e.cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2922 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2923 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2924 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2925 |
private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
2926 |
for (Type t = origin.type; t.hasTag(CLASS) || t.hasTag(TYPEVAR); t = supertype(t)) { |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
2927 |
t = skipTypeVars(t, false); |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2928 |
TypeSymbol c = t.tsym; |
27390
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2929 |
Symbol bestSoFar = null; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
2930 |
for (Symbol sym : c.members().getSymbolsByName(ms.name, implFilter)) { |
27390
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2931 |
if (sym != null && sym.overrides(ms, origin, Types.this, checkResult)) { |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2932 |
bestSoFar = sym; |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2933 |
if ((sym.flags() & ABSTRACT) == 0) { |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2934 |
//if concrete impl is found, exit immediately |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2935 |
break; |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2936 |
} |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2937 |
} |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2938 |
} |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2939 |
if (bestSoFar != null) { |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2940 |
//return either the (only) concrete implementation or the first abstract one |
02221d4ed524
6987475: Order of declarations affects whether abstract method considered overridden
mcimadamore
parents:
27228
diff
changeset
|
2941 |
return (MethodSymbol)bestSoFar; |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2942 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2943 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2944 |
return null; |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2945 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2946 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2947 |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2948 |
private ImplementationCache implCache = new ImplementationCache(); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2949 |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2950 |
public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2951 |
return implCache.get(ms, origin, checkResult, implFilter); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2952 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2953 |
// </editor-fold> |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2954 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2955 |
// <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2956 |
class MembersClosureCache extends SimpleVisitor<Scope.CompoundScope, Void> { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2957 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2958 |
private Map<TypeSymbol, CompoundScope> _map = new HashMap<>(); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2959 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2960 |
Set<TypeSymbol> seenTypes = new HashSet<>(); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2961 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2962 |
class MembersScope extends CompoundScope { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2963 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2964 |
CompoundScope scope; |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2965 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2966 |
public MembersScope(CompoundScope scope) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2967 |
super(scope.owner); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2968 |
this.scope = scope; |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2969 |
} |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2970 |
|
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2971 |
Filter<Symbol> combine(Filter<Symbol> sf) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2972 |
return s -> !s.owner.isInterface() && (sf == null || sf.accepts(s)); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2973 |
} |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2974 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2975 |
@Override |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2976 |
public Iterable<Symbol> getSymbols(Filter<Symbol> sf, LookupKind lookupKind) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2977 |
return scope.getSymbols(combine(sf), lookupKind); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2978 |
} |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2979 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2980 |
@Override |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2981 |
public Iterable<Symbol> getSymbolsByName(Name name, Filter<Symbol> sf, LookupKind lookupKind) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2982 |
return scope.getSymbolsByName(name, combine(sf), lookupKind); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2983 |
} |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2984 |
|
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2985 |
@Override |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2986 |
public int getMark() { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2987 |
return scope.getMark(); |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2988 |
} |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2989 |
} |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2990 |
|
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2991 |
CompoundScope nilScope; |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
2992 |
|
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2993 |
/** members closure visitor methods **/ |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
2994 |
|
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2995 |
public CompoundScope visitType(Type t, Void _unused) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2996 |
if (nilScope == null) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2997 |
nilScope = new CompoundScope(syms.noSymbol); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2998 |
} |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
2999 |
return nilScope; |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3000 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3001 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3002 |
@Override |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3003 |
public CompoundScope visitClassType(ClassType t, Void _unused) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3004 |
if (!seenTypes.add(t.tsym)) { |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3005 |
//this is possible when an interface is implemented in multiple |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3006 |
//superclasses, or when a class hierarchy is circular - in such |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3007 |
//cases we don't need to recurse (empty scope is returned) |
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3008 |
return new CompoundScope(t.tsym); |
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3009 |
} |
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3010 |
try { |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3011 |
seenTypes.add(t.tsym); |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3012 |
ClassSymbol csym = (ClassSymbol)t.tsym; |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3013 |
CompoundScope membersClosure = _map.get(csym); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3014 |
if (membersClosure == null) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3015 |
membersClosure = new CompoundScope(csym); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3016 |
for (Type i : interfaces(t)) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3017 |
membersClosure.prependSubScope(visit(i, null)); |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3018 |
} |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3019 |
membersClosure.prependSubScope(visit(supertype(t), null)); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
3020 |
membersClosure.prependSubScope(csym.members()); |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3021 |
_map.put(csym, membersClosure); |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3022 |
} |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3023 |
return membersClosure; |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3024 |
} |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3025 |
finally { |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3026 |
seenTypes.remove(t.tsym); |
10453
41fe3e16698a
7079713: javac hangs when compiling a class that references a cyclically inherited class
mcimadamore
parents:
10452
diff
changeset
|
3027 |
} |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3028 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3029 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3030 |
@Override |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3031 |
public CompoundScope visitTypeVar(TypeVar t, Void _unused) { |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3032 |
return visit(t.getUpperBound(), null); |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
3033 |
} |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3034 |
} |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3035 |
|
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3036 |
private MembersClosureCache membersCache = new MembersClosureCache(); |
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3037 |
|
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3038 |
public CompoundScope membersClosure(Type site, boolean skipInterface) { |
31005
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3039 |
CompoundScope cs = membersCache.visit(site, null); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3040 |
Assert.checkNonNull(cs, () -> "type " + site); |
673532e90337
8039262: Java compiler performance degradation jdk1.7 vs. jdk1.6 should be amended
jlahoda
parents:
30845
diff
changeset
|
3041 |
return skipInterface ? membersCache.new MembersScope(cs) : cs; |
9812
f716e42cb230
7046348: Regression: javac complains of missing classfile for a seemingly unrelated interface
mcimadamore
parents:
9721
diff
changeset
|
3042 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
3043 |
// </editor-fold> |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
3044 |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3045 |
|
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3046 |
/** Return first abstract member of class `sym'. |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3047 |
*/ |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3048 |
public MethodSymbol firstUnimplementedAbstract(ClassSymbol sym) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3049 |
try { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3050 |
return firstUnimplementedAbstractImpl(sym, sym); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3051 |
} catch (CompletionFailure ex) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3052 |
chk.completionError(enter.getEnv(sym).tree.pos(), ex); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3053 |
return null; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3054 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3055 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3056 |
//where: |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3057 |
private MethodSymbol firstUnimplementedAbstractImpl(ClassSymbol impl, ClassSymbol c) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3058 |
MethodSymbol undef = null; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3059 |
// Do not bother to search in classes that are not abstract, |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3060 |
// since they cannot have abstract members. |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3061 |
if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3062 |
Scope s = c.members(); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3063 |
for (Symbol sym : s.getSymbols(NON_RECURSIVE)) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3064 |
if (sym.kind == MTH && |
33709 | 3065 |
(sym.flags() & (ABSTRACT|DEFAULT|PRIVATE)) == ABSTRACT) { |
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3066 |
MethodSymbol absmeth = (MethodSymbol)sym; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3067 |
MethodSymbol implmeth = absmeth.implementation(impl, this, true); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3068 |
if (implmeth == null || implmeth == absmeth) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3069 |
//look for default implementations |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3070 |
if (allowDefaultMethods) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3071 |
MethodSymbol prov = interfaceCandidates(impl.type, absmeth).head; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3072 |
if (prov != null && prov.overrides(absmeth, impl, this, true)) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3073 |
implmeth = prov; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3074 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3075 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3076 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3077 |
if (implmeth == null || implmeth == absmeth) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3078 |
undef = absmeth; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3079 |
break; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3080 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3081 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3082 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3083 |
if (undef == null) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3084 |
Type st = supertype(c.type); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3085 |
if (st.hasTag(CLASS)) |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3086 |
undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol)st.tsym); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3087 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3088 |
for (List<Type> l = interfaces(c.type); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3089 |
undef == null && l.nonEmpty(); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3090 |
l = l.tail) { |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3091 |
undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol)l.head.tsym); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3092 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3093 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3094 |
return undef; |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3095 |
} |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3096 |
|
41862
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3097 |
public class CandidatesCache { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3098 |
public Map<Entry, List<MethodSymbol>> cache = new WeakHashMap<>(); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3099 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3100 |
class Entry { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3101 |
Type site; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3102 |
MethodSymbol msym; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3103 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3104 |
Entry(Type site, MethodSymbol msym) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3105 |
this.site = site; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3106 |
this.msym = msym; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3107 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3108 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3109 |
@Override |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3110 |
public boolean equals(Object obj) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3111 |
if (obj instanceof Entry) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3112 |
Entry e = (Entry)obj; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3113 |
return e.msym == msym && isSameType(site, e.site); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3114 |
} else { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3115 |
return false; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3116 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3117 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3118 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3119 |
@Override |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3120 |
public int hashCode() { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3121 |
return Types.this.hashCode(site) & ~msym.hashCode(); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3122 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3123 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3124 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3125 |
public List<MethodSymbol> get(Entry e) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3126 |
return cache.get(e); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3127 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3128 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3129 |
public void put(Entry e, List<MethodSymbol> msymbols) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3130 |
cache.put(e, msymbols); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3131 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3132 |
} |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3133 |
|
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3134 |
public CandidatesCache candidatesCache = new CandidatesCache(); |
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28451
diff
changeset
|
3135 |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3136 |
//where |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3137 |
public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { |
41862
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3138 |
CandidatesCache.Entry e = candidatesCache.new Entry(site, ms); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3139 |
List<MethodSymbol> candidates = candidatesCache.get(e); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3140 |
if (candidates == null) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3141 |
Filter<Symbol> filter = new MethodFilter(ms, site); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3142 |
List<MethodSymbol> candidates2 = List.nil(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25441
diff
changeset
|
3143 |
for (Symbol s : membersClosure(site, false).getSymbols(filter)) { |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16567
diff
changeset
|
3144 |
if (!site.tsym.isInterface() && !s.owner.isInterface()) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16567
diff
changeset
|
3145 |
return List.of((MethodSymbol)s); |
41862
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3146 |
} else if (!candidates2.contains(s)) { |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3147 |
candidates2 = candidates2.prepend((MethodSymbol)s); |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16567
diff
changeset
|
3148 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3149 |
} |
41862
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3150 |
candidates = prune(candidates2); |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3151 |
candidatesCache.put(e, candidates); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3152 |
} |
41862
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3153 |
return candidates; |
471a0cb1b986
8167431: javac takes too long time to resolve interface dependency
vromero
parents:
41856
diff
changeset
|
3154 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3155 |
|
16295
8b76e466f3cb
8007535: Compiler crashes on @FunctionalInterface used on interface with two inherited methods with same signatures
mcimadamore
parents:
16292
diff
changeset
|
3156 |
public List<MethodSymbol> prune(List<MethodSymbol> methods) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
3157 |
ListBuffer<MethodSymbol> methodsMin = new ListBuffer<>(); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3158 |
for (MethodSymbol m1 : methods) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3159 |
boolean isMin_m1 = true; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3160 |
for (MethodSymbol m2 : methods) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3161 |
if (m1 == m2) continue; |
16295
8b76e466f3cb
8007535: Compiler crashes on @FunctionalInterface used on interface with two inherited methods with same signatures
mcimadamore
parents:
16292
diff
changeset
|
3162 |
if (m2.owner != m1.owner && |
8b76e466f3cb
8007535: Compiler crashes on @FunctionalInterface used on interface with two inherited methods with same signatures
mcimadamore
parents:
16292
diff
changeset
|
3163 |
asSuper(m2.owner.type, m1.owner) != null) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3164 |
isMin_m1 = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3165 |
break; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3166 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3167 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3168 |
if (isMin_m1) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3169 |
methodsMin.append(m1); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3170 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3171 |
return methodsMin.toList(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3172 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3173 |
// where |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3174 |
private class MethodFilter implements Filter<Symbol> { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3175 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3176 |
Symbol msym; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3177 |
Type site; |
14547 | 3178 |
|
3179 |
MethodFilter(Symbol msym, Type site) { |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3180 |
this.msym = msym; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3181 |
this.site = site; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3182 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3183 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3184 |
public boolean accepts(Symbol s) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27125
diff
changeset
|
3185 |
return s.kind == MTH && |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3186 |
s.name == msym.name && |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
3187 |
(s.flags() & SYNTHETIC) == 0 && |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3188 |
s.isInheritedIn(site.tsym, Types.this) && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3189 |
overrideEquivalent(memberType(site, s), memberType(site, msym)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3190 |
} |
22163 | 3191 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3192 |
// </editor-fold> |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3193 |
|
10 | 3194 |
/** |
3195 |
* Does t have the same arguments as s? It is assumed that both |
|
3196 |
* types are (possibly polymorphic) method types. Monomorphic |
|
3197 |
* method types "have the same arguments", if their argument lists |
|
3198 |
* are equal. Polymorphic method types "have the same arguments", |
|
3199 |
* if they have the same arguments after renaming all type |
|
3200 |
* variables of one to corresponding type variables in the other, |
|
3201 |
* where correspondence is by position in the type parameter list. |
|
3202 |
*/ |
|
3203 |
public boolean hasSameArgs(Type t, Type s) { |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3204 |
return hasSameArgs(t, s, true); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3205 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3206 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3207 |
public boolean hasSameArgs(Type t, Type s, boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3208 |
return hasSameArgs(t, s, strict ? hasSameArgs_strict : hasSameArgs_nonstrict); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3209 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3210 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3211 |
private boolean hasSameArgs(Type t, Type s, TypeRelation hasSameArgs) { |
10 | 3212 |
return hasSameArgs.visit(t, s); |
3213 |
} |
|
3214 |
// where |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3215 |
private class HasSameArgs extends TypeRelation { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3216 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3217 |
boolean strict; |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3218 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3219 |
public HasSameArgs(boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3220 |
this.strict = strict; |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3221 |
} |
10 | 3222 |
|
3223 |
public Boolean visitType(Type t, Type s) { |
|
3224 |
throw new AssertionError(); |
|
3225 |
} |
|
3226 |
||
3227 |
@Override |
|
3228 |
public Boolean visitMethodType(MethodType t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3229 |
return s.hasTag(METHOD) |
10 | 3230 |
&& containsTypeEquivalent(t.argtypes, s.getParameterTypes()); |
3231 |
} |
|
3232 |
||
3233 |
@Override |
|
3234 |
public Boolean visitForAll(ForAll t, Type s) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3235 |
if (!s.hasTag(FORALL)) |
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3236 |
return strict ? false : visitMethodType(t.asMethodType(), s); |
10 | 3237 |
|
3238 |
ForAll forAll = (ForAll)s; |
|
3239 |
return hasSameBounds(t, forAll) |
|
3240 |
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars)); |
|
3241 |
} |
|
3242 |
||
3243 |
@Override |
|
3244 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
3245 |
return false; |
|
3246 |
} |
|
22163 | 3247 |
} |
3248 |
||
3249 |
TypeRelation hasSameArgs_strict = new HasSameArgs(true); |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3250 |
TypeRelation hasSameArgs_nonstrict = new HasSameArgs(false); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
3251 |
|
10 | 3252 |
// </editor-fold> |
3253 |
||
3254 |
// <editor-fold defaultstate="collapsed" desc="subst"> |
|
3255 |
public List<Type> subst(List<Type> ts, |
|
3256 |
List<Type> from, |
|
3257 |
List<Type> to) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3258 |
return ts.map(new Subst(from, to)); |
10 | 3259 |
} |
3260 |
||
3261 |
/** |
|
3262 |
* Substitute all occurrences of a type in `from' with the |
|
3263 |
* corresponding type in `to' in 't'. Match lists `from' and `to' |
|
3264 |
* from the right: If lists have different length, discard leading |
|
3265 |
* elements of the longer list. |
|
3266 |
*/ |
|
3267 |
public Type subst(Type t, List<Type> from, List<Type> to) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3268 |
return t.map(new Subst(from, to)); |
10 | 3269 |
} |
3270 |
||
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
3271 |
private class Subst extends StructuralTypeMapping<Void> { |
10 | 3272 |
List<Type> from; |
3273 |
List<Type> to; |
|
3274 |
||
3275 |
public Subst(List<Type> from, List<Type> to) { |
|
3276 |
int fromLength = from.length(); |
|
3277 |
int toLength = to.length(); |
|
3278 |
while (fromLength > toLength) { |
|
3279 |
fromLength--; |
|
3280 |
from = from.tail; |
|
3281 |
} |
|
3282 |
while (fromLength < toLength) { |
|
3283 |
toLength--; |
|
3284 |
to = to.tail; |
|
3285 |
} |
|
3286 |
this.from = from; |
|
3287 |
this.to = to; |
|
3288 |
} |
|
3289 |
||
3290 |
@Override |
|
3291 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
3292 |
for (List<Type> from = this.from, to = this.to; |
|
3293 |
from.nonEmpty(); |
|
3294 |
from = from.tail, to = to.tail) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3295 |
if (t.equalsIgnoreMetadata(from.head)) { |
10 | 3296 |
return to.head.withTypeVar(t); |
3297 |
} |
|
3298 |
} |
|
3299 |
return t; |
|
3300 |
} |
|
3301 |
||
3302 |
@Override |
|
3303 |
public Type visitClassType(ClassType t, Void ignored) { |
|
3304 |
if (!t.isCompound()) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3305 |
return super.visitClassType(t, ignored); |
10 | 3306 |
} else { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3307 |
Type st = visit(supertype(t)); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3308 |
List<Type> is = visit(interfaces(t), ignored); |
10 | 3309 |
if (st == supertype(t) && is == interfaces(t)) |
3310 |
return t; |
|
3311 |
else |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
3312 |
return makeIntersectionType(is.prepend(st)); |
10 | 3313 |
} |
3314 |
} |
|
3315 |
||
3316 |
@Override |
|
3317 |
public Type visitWildcardType(WildcardType t, Void ignored) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3318 |
WildcardType t2 = (WildcardType)super.visitWildcardType(t, ignored); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3319 |
if (t2 != t && t.isExtendsBound() && t2.type.isExtendsBound()) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3320 |
t2.type = wildUpperBound(t2.type); |
10 | 3321 |
} |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3322 |
return t2; |
10 | 3323 |
} |
3324 |
||
3325 |
@Override |
|
3326 |
public Type visitForAll(ForAll t, Void ignored) { |
|
8230
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3327 |
if (Type.containsAny(to, t.tvars)) { |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3328 |
//perform alpha-renaming of free-variables in 't' |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3329 |
//if 'to' types contain variables that are free in 't' |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3330 |
List<Type> freevars = newInstances(t.tvars); |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3331 |
t = new ForAll(freevars, |
24396 | 3332 |
Types.this.subst(t.qtype, t.tvars, freevars)); |
8230
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
3333 |
} |
10 | 3334 |
List<Type> tvars1 = substBounds(t.tvars, from, to); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3335 |
Type qtype1 = visit(t.qtype); |
10 | 3336 |
if (tvars1 == t.tvars && qtype1 == t.qtype) { |
3337 |
return t; |
|
3338 |
} else if (tvars1 == t.tvars) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3339 |
return new ForAll(tvars1, qtype1) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3340 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3341 |
public boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3342 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3343 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3344 |
}; |
10 | 3345 |
} else { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3346 |
return new ForAll(tvars1, Types.this.subst(qtype1, t.tvars, tvars1)) { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3347 |
@Override |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3348 |
public boolean needsStripping() { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3349 |
return true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3350 |
} |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
3351 |
}; |
10 | 3352 |
} |
3353 |
} |
|
3354 |
} |
|
3355 |
||
3356 |
public List<Type> substBounds(List<Type> tvars, |
|
3357 |
List<Type> from, |
|
3358 |
List<Type> to) { |
|
3359 |
if (tvars.isEmpty()) |
|
3360 |
return tvars; |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
3361 |
ListBuffer<Type> newBoundsBuf = new ListBuffer<>(); |
10 | 3362 |
boolean changed = false; |
3363 |
// calculate new bounds |
|
3364 |
for (Type t : tvars) { |
|
3365 |
TypeVar tv = (TypeVar) t; |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3366 |
Type bound = subst(tv.getUpperBound(), from, to); |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3367 |
if (bound != tv.getUpperBound()) |
10 | 3368 |
changed = true; |
3369 |
newBoundsBuf.append(bound); |
|
3370 |
} |
|
3371 |
if (!changed) |
|
3372 |
return tvars; |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
3373 |
ListBuffer<Type> newTvars = new ListBuffer<>(); |
10 | 3374 |
// create new type variables without bounds |
3375 |
for (Type t : tvars) { |
|
24396 | 3376 |
newTvars.append(new TypeVar(t.tsym, null, syms.botType, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3377 |
t.getMetadata())); |
10 | 3378 |
} |
3379 |
// the new bounds should use the new type variables in place |
|
3380 |
// of the old |
|
3381 |
List<Type> newBounds = newBoundsBuf.toList(); |
|
3382 |
from = tvars; |
|
3383 |
to = newTvars.toList(); |
|
3384 |
for (; !newBounds.isEmpty(); newBounds = newBounds.tail) { |
|
3385 |
newBounds.head = subst(newBounds.head, from, to); |
|
3386 |
} |
|
3387 |
newBounds = newBoundsBuf.toList(); |
|
3388 |
// set the bounds of new type variables to the new bounds |
|
3389 |
for (Type t : newTvars.toList()) { |
|
3390 |
TypeVar tv = (TypeVar) t; |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3391 |
tv.setUpperBound( newBounds.head ); |
10 | 3392 |
newBounds = newBounds.tail; |
3393 |
} |
|
3394 |
return newTvars.toList(); |
|
3395 |
} |
|
3396 |
||
3397 |
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3398 |
Type bound1 = subst(t.getUpperBound(), from, to); |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3399 |
if (bound1 == t.getUpperBound()) |
10 | 3400 |
return t; |
1993
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3401 |
else { |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3402 |
// create new type variable without bounds |
24396 | 3403 |
TypeVar tv = new TypeVar(t.tsym, null, syms.botType, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3404 |
t.getMetadata()); |
1993
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3405 |
// the new bound should use the new type variable in place |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3406 |
// of the old |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3407 |
tv.setUpperBound( subst(bound1, List.of(t), List.of(tv)) ); |
1993
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3408 |
return tv; |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
3409 |
} |
10 | 3410 |
} |
3411 |
// </editor-fold> |
|
3412 |
||
3413 |
// <editor-fold defaultstate="collapsed" desc="hasSameBounds"> |
|
3414 |
/** |
|
3415 |
* Does t have the same bounds for quantified variables as s? |
|
3416 |
*/ |
|
19914 | 3417 |
public boolean hasSameBounds(ForAll t, ForAll s) { |
10 | 3418 |
List<Type> l1 = t.tvars; |
3419 |
List<Type> l2 = s.tvars; |
|
3420 |
while (l1.nonEmpty() && l2.nonEmpty() && |
|
3421 |
isSameType(l1.head.getUpperBound(), |
|
3422 |
subst(l2.head.getUpperBound(), |
|
3423 |
s.tvars, |
|
3424 |
t.tvars))) { |
|
3425 |
l1 = l1.tail; |
|
3426 |
l2 = l2.tail; |
|
3427 |
} |
|
3428 |
return l1.isEmpty() && l2.isEmpty(); |
|
3429 |
} |
|
3430 |
// </editor-fold> |
|
3431 |
||
3432 |
// <editor-fold defaultstate="collapsed" desc="newInstances"> |
|
3433 |
/** Create new vector of type variables from list of variables |
|
3434 |
* changing all recursive bounds from old to new list. |
|
3435 |
*/ |
|
3436 |
public List<Type> newInstances(List<Type> tvars) { |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3437 |
List<Type> tvars1 = tvars.map(newInstanceFun); |
10 | 3438 |
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) { |
3439 |
TypeVar tv = (TypeVar) l.head; |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3440 |
tv.setUpperBound( subst(tv.getUpperBound(), tvars, tvars1) ); |
10 | 3441 |
} |
3442 |
return tvars1; |
|
3443 |
} |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3444 |
private static final TypeMapping<Void> newInstanceFun = new TypeMapping<Void>() { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3445 |
@Override |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3446 |
public TypeVar visitTypeVar(TypeVar t, Void _unused) { |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3447 |
return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound(), t.getMetadata()); |
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
3448 |
} |
10 | 3449 |
}; |
3450 |
// </editor-fold> |
|
3451 |
||
8430 | 3452 |
public Type createMethodTypeWithParameters(Type original, List<Type> newParams) { |
3453 |
return original.accept(methodWithParameters, newParams); |
|
3454 |
} |
|
3455 |
// where |
|
3456 |
private final MapVisitor<List<Type>> methodWithParameters = new MapVisitor<List<Type>>() { |
|
3457 |
public Type visitType(Type t, List<Type> newParams) { |
|
3458 |
throw new IllegalArgumentException("Not a method type: " + t); |
|
3459 |
} |
|
3460 |
public Type visitMethodType(MethodType t, List<Type> newParams) { |
|
3461 |
return new MethodType(newParams, t.restype, t.thrown, t.tsym); |
|
3462 |
} |
|
3463 |
public Type visitForAll(ForAll t, List<Type> newParams) { |
|
3464 |
return new ForAll(t.tvars, t.qtype.accept(this, newParams)); |
|
3465 |
} |
|
3466 |
}; |
|
3467 |
||
3468 |
public Type createMethodTypeWithThrown(Type original, List<Type> newThrown) { |
|
3469 |
return original.accept(methodWithThrown, newThrown); |
|
3470 |
} |
|
3471 |
// where |
|
3472 |
private final MapVisitor<List<Type>> methodWithThrown = new MapVisitor<List<Type>>() { |
|
3473 |
public Type visitType(Type t, List<Type> newThrown) { |
|
3474 |
throw new IllegalArgumentException("Not a method type: " + t); |
|
3475 |
} |
|
3476 |
public Type visitMethodType(MethodType t, List<Type> newThrown) { |
|
3477 |
return new MethodType(t.argtypes, t.restype, newThrown, t.tsym); |
|
3478 |
} |
|
3479 |
public Type visitForAll(ForAll t, List<Type> newThrown) { |
|
3480 |
return new ForAll(t.tvars, t.qtype.accept(this, newThrown)); |
|
3481 |
} |
|
3482 |
}; |
|
3483 |
||
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3484 |
public Type createMethodTypeWithReturn(Type original, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3485 |
return original.accept(methodWithReturn, newReturn); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3486 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3487 |
// where |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3488 |
private final MapVisitor<Type> methodWithReturn = new MapVisitor<Type>() { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3489 |
public Type visitType(Type t, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3490 |
throw new IllegalArgumentException("Not a method type: " + t); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3491 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3492 |
public Type visitMethodType(MethodType t, Type newReturn) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3493 |
return new MethodType(t.argtypes, newReturn, t.thrown, t.tsym) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3494 |
@Override |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3495 |
public Type baseType() { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3496 |
return t; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3497 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3498 |
}; |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3499 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3500 |
public Type visitForAll(ForAll t, Type newReturn) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3501 |
return new ForAll(t.tvars, t.qtype.accept(this, newReturn)) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3502 |
@Override |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3503 |
public Type baseType() { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3504 |
return t; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3505 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31005
diff
changeset
|
3506 |
}; |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3507 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3508 |
}; |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
3509 |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3510 |
// <editor-fold defaultstate="collapsed" desc="createErrorType"> |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3511 |
public Type createErrorType(Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3512 |
return new ErrorType(originalType, syms.errSymbol); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3513 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3514 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3515 |
public Type createErrorType(ClassSymbol c, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3516 |
return new ErrorType(c, originalType); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3517 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3518 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3519 |
public Type createErrorType(Name name, TypeSymbol container, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3520 |
return new ErrorType(name, container, originalType); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3521 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3522 |
// </editor-fold> |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
3523 |
|
10 | 3524 |
// <editor-fold defaultstate="collapsed" desc="rank"> |
3525 |
/** |
|
3526 |
* The rank of a class is the length of the longest path between |
|
3527 |
* the class and java.lang.Object in the class inheritance |
|
3528 |
* graph. Undefined for all but reference types. |
|
3529 |
*/ |
|
3530 |
public int rank(Type t) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3531 |
switch(t.getTag()) { |
10 | 3532 |
case CLASS: { |
3533 |
ClassType cls = (ClassType)t; |
|
3534 |
if (cls.rank_field < 0) { |
|
3535 |
Name fullname = cls.tsym.getQualifiedName(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
3536 |
if (fullname == names.java_lang_Object) |
10 | 3537 |
cls.rank_field = 0; |
3538 |
else { |
|
3539 |
int r = rank(supertype(cls)); |
|
3540 |
for (List<Type> l = interfaces(cls); |
|
3541 |
l.nonEmpty(); |
|
3542 |
l = l.tail) { |
|
3543 |
if (rank(l.head) > r) |
|
3544 |
r = rank(l.head); |
|
3545 |
} |
|
3546 |
cls.rank_field = r + 1; |
|
3547 |
} |
|
3548 |
} |
|
3549 |
return cls.rank_field; |
|
3550 |
} |
|
3551 |
case TYPEVAR: { |
|
3552 |
TypeVar tvar = (TypeVar)t; |
|
3553 |
if (tvar.rank_field < 0) { |
|
3554 |
int r = rank(supertype(tvar)); |
|
3555 |
for (List<Type> l = interfaces(tvar); |
|
3556 |
l.nonEmpty(); |
|
3557 |
l = l.tail) { |
|
3558 |
if (rank(l.head) > r) r = rank(l.head); |
|
3559 |
} |
|
3560 |
tvar.rank_field = r + 1; |
|
3561 |
} |
|
3562 |
return tvar.rank_field; |
|
3563 |
} |
|
3564 |
case ERROR: |
|
23399
a7f649f8e860
8036007: javac crashes when encountering an unresolvable interface
vromero
parents:
22442
diff
changeset
|
3565 |
case NONE: |
10 | 3566 |
return 0; |
3567 |
default: |
|
3568 |
throw new AssertionError(); |
|
3569 |
} |
|
3570 |
} |
|
3571 |
// </editor-fold> |
|
3572 |
||
1357 | 3573 |
/** |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
3574 |
* Helper method for generating a string representation of a given type |
1357 | 3575 |
* accordingly to a given locale |
3576 |
*/ |
|
3577 |
public String toString(Type t, Locale locale) { |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
3578 |
return Printer.createStandardPrinter(messages).visit(t, locale); |
1357 | 3579 |
} |
3580 |
||
3581 |
/** |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
3582 |
* Helper method for generating a string representation of a given type |
1357 | 3583 |
* accordingly to a given locale |
3584 |
*/ |
|
3585 |
public String toString(Symbol t, Locale locale) { |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
3586 |
return Printer.createStandardPrinter(messages).visit(t, locale); |
1357 | 3587 |
} |
3588 |
||
10 | 3589 |
// <editor-fold defaultstate="collapsed" desc="toString"> |
3590 |
/** |
|
3591 |
* This toString is slightly more descriptive than the one on Type. |
|
1357 | 3592 |
* |
3593 |
* @deprecated Types.toString(Type t, Locale l) provides better support |
|
3594 |
* for localization |
|
10 | 3595 |
*/ |
1357 | 3596 |
@Deprecated |
10 | 3597 |
public String toString(Type t) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3598 |
if (t.hasTag(FORALL)) { |
10 | 3599 |
ForAll forAll = (ForAll)t; |
3600 |
return typaramsString(forAll.tvars) + forAll.qtype; |
|
3601 |
} |
|
3602 |
return "" + t; |
|
3603 |
} |
|
3604 |
// where |
|
3605 |
private String typaramsString(List<Type> tvars) { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8617
diff
changeset
|
3606 |
StringBuilder s = new StringBuilder(); |
10 | 3607 |
s.append('<'); |
3608 |
boolean first = true; |
|
3609 |
for (Type t : tvars) { |
|
3610 |
if (!first) s.append(", "); |
|
3611 |
first = false; |
|
24396 | 3612 |
appendTyparamString(((TypeVar)t), s); |
10 | 3613 |
} |
3614 |
s.append('>'); |
|
3615 |
return s.toString(); |
|
3616 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8617
diff
changeset
|
3617 |
private void appendTyparamString(TypeVar t, StringBuilder buf) { |
10 | 3618 |
buf.append(t); |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3619 |
if (t.getUpperBound() == null || |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3620 |
t.getUpperBound().tsym.getQualifiedName() == names.java_lang_Object) |
10 | 3621 |
return; |
3622 |
buf.append(" extends "); // Java syntax; no need for i18n |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
3623 |
Type bound = t.getUpperBound(); |
10 | 3624 |
if (!bound.isCompound()) { |
3625 |
buf.append(bound); |
|
3626 |
} else if ((erasure(t).tsym.flags() & INTERFACE) == 0) { |
|
3627 |
buf.append(supertype(t)); |
|
3628 |
for (Type intf : interfaces(t)) { |
|
3629 |
buf.append('&'); |
|
3630 |
buf.append(intf); |
|
3631 |
} |
|
3632 |
} else { |
|
3633 |
// No superclass was given in bounds. |
|
3634 |
// In this case, supertype is Object, erasure is first interface. |
|
3635 |
boolean first = true; |
|
3636 |
for (Type intf : interfaces(t)) { |
|
3637 |
if (!first) buf.append('&'); |
|
3638 |
first = false; |
|
3639 |
buf.append(intf); |
|
3640 |
} |
|
3641 |
} |
|
3642 |
} |
|
3643 |
// </editor-fold> |
|
3644 |
||
3645 |
// <editor-fold defaultstate="collapsed" desc="Determining least upper bounds of types"> |
|
3646 |
/** |
|
3647 |
* A cache for closures. |
|
3648 |
* |
|
3649 |
* <p>A closure is a list of all the supertypes and interfaces of |
|
3650 |
* a class or interface type, ordered by ClassSymbol.precedes |
|
3651 |
* (that is, subclasses come first, arbitrary but fixed |
|
3652 |
* otherwise). |
|
3653 |
*/ |
|
22163 | 3654 |
private Map<Type,List<Type>> closureCache = new HashMap<>(); |
10 | 3655 |
|
3656 |
/** |
|
3657 |
* Returns the closure of a class or interface type. |
|
3658 |
*/ |
|
3659 |
public List<Type> closure(Type t) { |
|
3660 |
List<Type> cl = closureCache.get(t); |
|
3661 |
if (cl == null) { |
|
3662 |
Type st = supertype(t); |
|
3663 |
if (!t.isCompound()) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3664 |
if (st.hasTag(CLASS)) { |
10 | 3665 |
cl = insert(closure(st), t); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3666 |
} else if (st.hasTag(TYPEVAR)) { |
10 | 3667 |
cl = closure(st).prepend(t); |
3668 |
} else { |
|
3669 |
cl = List.of(t); |
|
3670 |
} |
|
3671 |
} else { |
|
3672 |
cl = closure(supertype(t)); |
|
3673 |
} |
|
3674 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) |
|
3675 |
cl = union(cl, closure(l.head)); |
|
3676 |
closureCache.put(t, cl); |
|
3677 |
} |
|
3678 |
return cl; |
|
3679 |
} |
|
3680 |
||
3681 |
/** |
|
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3682 |
* Collect types into a new closure (using a @code{ClosureHolder}) |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3683 |
*/ |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3684 |
public Collector<Type, ClosureHolder, List<Type>> closureCollector(boolean minClosure, BiPredicate<Type, Type> shouldSkip) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3685 |
return Collector.of(() -> new ClosureHolder(minClosure, shouldSkip), |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3686 |
ClosureHolder::add, |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3687 |
ClosureHolder::merge, |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3688 |
ClosureHolder::closure); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3689 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3690 |
//where |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3691 |
class ClosureHolder { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3692 |
List<Type> closure; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3693 |
final boolean minClosure; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3694 |
final BiPredicate<Type, Type> shouldSkip; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3695 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3696 |
ClosureHolder(boolean minClosure, BiPredicate<Type, Type> shouldSkip) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3697 |
this.closure = List.nil(); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3698 |
this.minClosure = minClosure; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3699 |
this.shouldSkip = shouldSkip; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3700 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3701 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3702 |
void add(Type type) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3703 |
closure = insert(closure, type, shouldSkip); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3704 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3705 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3706 |
ClosureHolder merge(ClosureHolder other) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3707 |
closure = union(closure, other.closure, shouldSkip); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3708 |
return this; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3709 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3710 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3711 |
List<Type> closure() { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3712 |
return minClosure ? closureMin(closure) : closure; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3713 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3714 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3715 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3716 |
BiPredicate<Type, Type> basicClosureSkip = (t1, t2) -> t1.tsym == t2.tsym; |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3717 |
|
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3718 |
/** |
10 | 3719 |
* Insert a type in a closure |
3720 |
*/ |
|
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3721 |
public List<Type> insert(List<Type> cl, Type t, BiPredicate<Type, Type> shouldSkip) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3722 |
if (cl.isEmpty()) { |
10 | 3723 |
return cl.prepend(t); |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3724 |
} else if (shouldSkip.test(t, cl.head)) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3725 |
return cl; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3726 |
} else if (t.tsym.precedes(cl.head.tsym, this)) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3727 |
return cl.prepend(t); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3728 |
} else { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3729 |
// t comes after head, or the two are unrelated |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3730 |
return insert(cl.tail, t, shouldSkip).prepend(cl.head); |
10 | 3731 |
} |
3732 |
} |
|
3733 |
||
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3734 |
public List<Type> insert(List<Type> cl, Type t) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3735 |
return insert(cl, t, basicClosureSkip); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3736 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3737 |
|
10 | 3738 |
/** |
3739 |
* Form the union of two closures |
|
3740 |
*/ |
|
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3741 |
public List<Type> union(List<Type> cl1, List<Type> cl2, BiPredicate<Type, Type> shouldSkip) { |
10 | 3742 |
if (cl1.isEmpty()) { |
3743 |
return cl2; |
|
3744 |
} else if (cl2.isEmpty()) { |
|
3745 |
return cl1; |
|
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3746 |
} else if (shouldSkip.test(cl1.head, cl2.head)) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3747 |
return union(cl1.tail, cl2.tail, shouldSkip).prepend(cl1.head); |
10 | 3748 |
} else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) { |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3749 |
return union(cl1, cl2.tail, shouldSkip).prepend(cl2.head); |
10 | 3750 |
} else { |
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3751 |
return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head); |
10 | 3752 |
} |
3753 |
} |
|
3754 |
||
29555
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3755 |
public List<Type> union(List<Type> cl1, List<Type> cl2) { |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3756 |
return union(cl1, cl2, basicClosureSkip); |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3757 |
} |
71f15ff4b409
8048838: type inference performance regression
mcimadamore
parents:
29554
diff
changeset
|
3758 |
|
10 | 3759 |
/** |
3760 |
* Intersect two closures |
|
3761 |
*/ |
|
3762 |
public List<Type> intersect(List<Type> cl1, List<Type> cl2) { |
|
3763 |
if (cl1 == cl2) |
|
3764 |
return cl1; |
|
3765 |
if (cl1.isEmpty() || cl2.isEmpty()) |
|
3766 |
return List.nil(); |
|
3767 |
if (cl1.head.tsym.precedes(cl2.head.tsym, this)) |
|
3768 |
return intersect(cl1.tail, cl2); |
|
3769 |
if (cl2.head.tsym.precedes(cl1.head.tsym, this)) |
|
3770 |
return intersect(cl1, cl2.tail); |
|
3771 |
if (isSameType(cl1.head, cl2.head)) |
|
3772 |
return intersect(cl1.tail, cl2.tail).prepend(cl1.head); |
|
3773 |
if (cl1.head.tsym == cl2.head.tsym && |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3774 |
cl1.head.hasTag(CLASS) && cl2.head.hasTag(CLASS)) { |
10 | 3775 |
if (cl1.head.isParameterized() && cl2.head.isParameterized()) { |
3776 |
Type merge = merge(cl1.head,cl2.head); |
|
3777 |
return intersect(cl1.tail, cl2.tail).prepend(merge); |
|
3778 |
} |
|
3779 |
if (cl1.head.isRaw() || cl2.head.isRaw()) |
|
3780 |
return intersect(cl1.tail, cl2.tail).prepend(erasure(cl1.head)); |
|
3781 |
} |
|
3782 |
return intersect(cl1.tail, cl2.tail); |
|
3783 |
} |
|
3784 |
// where |
|
3785 |
class TypePair { |
|
3786 |
final Type t1; |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
3787 |
final Type t2;; |
24899
ead62a035849
8043725: javac fails with StackOverflowException
mcimadamore
parents:
24647
diff
changeset
|
3788 |
|
10 | 3789 |
TypePair(Type t1, Type t2) { |
3790 |
this.t1 = t1; |
|
3791 |
this.t2 = t2; |
|
3792 |
} |
|
3793 |
@Override |
|
3794 |
public int hashCode() { |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
3795 |
return 127 * Types.this.hashCode(t1) + Types.this.hashCode(t2); |
10 | 3796 |
} |
3797 |
@Override |
|
3798 |
public boolean equals(Object obj) { |
|
3799 |
if (!(obj instanceof TypePair)) |
|
3800 |
return false; |
|
3801 |
TypePair typePair = (TypePair)obj; |
|
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
3802 |
return isSameType(t1, typePair.t1) |
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
3803 |
&& isSameType(t2, typePair.t2); |
10 | 3804 |
} |
3805 |
} |
|
22163 | 3806 |
Set<TypePair> mergeCache = new HashSet<>(); |
10 | 3807 |
private Type merge(Type c1, Type c2) { |
3808 |
ClassType class1 = (ClassType) c1; |
|
3809 |
List<Type> act1 = class1.getTypeArguments(); |
|
3810 |
ClassType class2 = (ClassType) c2; |
|
3811 |
List<Type> act2 = class2.getTypeArguments(); |
|
22163 | 3812 |
ListBuffer<Type> merged = new ListBuffer<>(); |
10 | 3813 |
List<Type> typarams = class1.tsym.type.getTypeArguments(); |
3814 |
||
3815 |
while (act1.nonEmpty() && act2.nonEmpty() && typarams.nonEmpty()) { |
|
3816 |
if (containsType(act1.head, act2.head)) { |
|
3817 |
merged.append(act1.head); |
|
3818 |
} else if (containsType(act2.head, act1.head)) { |
|
3819 |
merged.append(act2.head); |
|
3820 |
} else { |
|
3821 |
TypePair pair = new TypePair(c1, c2); |
|
3822 |
Type m; |
|
3823 |
if (mergeCache.add(pair)) { |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
3824 |
m = new WildcardType(lub(wildUpperBound(act1.head), |
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
3825 |
wildUpperBound(act2.head)), |
10 | 3826 |
BoundKind.EXTENDS, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3827 |
syms.boundClass); |
10 | 3828 |
mergeCache.remove(pair); |
3829 |
} else { |
|
3830 |
m = new WildcardType(syms.objectType, |
|
3831 |
BoundKind.UNBOUND, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3832 |
syms.boundClass); |
10 | 3833 |
} |
3834 |
merged.append(m.withTypeVar(typarams.head)); |
|
3835 |
} |
|
3836 |
act1 = act1.tail; |
|
3837 |
act2 = act2.tail; |
|
3838 |
typarams = typarams.tail; |
|
3839 |
} |
|
8032 | 3840 |
Assert.check(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty()); |
24396 | 3841 |
// There is no spec detailing how type annotations are to |
3842 |
// be inherited. So set it to noAnnotations for now |
|
3843 |
return new ClassType(class1.getEnclosingType(), merged.toList(), |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3844 |
class1.tsym); |
10 | 3845 |
} |
3846 |
||
3847 |
/** |
|
3848 |
* Return the minimum type of a closure, a compound type if no |
|
3849 |
* unique minimum exists. |
|
3850 |
*/ |
|
3851 |
private Type compoundMin(List<Type> cl) { |
|
3852 |
if (cl.isEmpty()) return syms.objectType; |
|
3853 |
List<Type> compound = closureMin(cl); |
|
3854 |
if (compound.isEmpty()) |
|
3855 |
return null; |
|
3856 |
else if (compound.tail.isEmpty()) |
|
3857 |
return compound.head; |
|
3858 |
else |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
3859 |
return makeIntersectionType(compound); |
10 | 3860 |
} |
3861 |
||
3862 |
/** |
|
3863 |
* Return the minimum types of a closure, suitable for computing |
|
3864 |
* compoundMin or glb. |
|
3865 |
*/ |
|
3866 |
private List<Type> closureMin(List<Type> cl) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
3867 |
ListBuffer<Type> classes = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
3868 |
ListBuffer<Type> interfaces = new ListBuffer<>(); |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3869 |
Set<Type> toSkip = new HashSet<>(); |
10 | 3870 |
while (!cl.isEmpty()) { |
3871 |
Type current = cl.head; |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3872 |
boolean keep = !toSkip.contains(current); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3873 |
if (keep && current.hasTag(TYPEVAR)) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3874 |
// skip lower-bounded variables with a subtype in cl.tail |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3875 |
for (Type t : cl.tail) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3876 |
if (isSubtypeNoCapture(t, current)) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3877 |
keep = false; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3878 |
break; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3879 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3880 |
} |
10 | 3881 |
} |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3882 |
if (keep) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3883 |
if (current.isInterface()) |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3884 |
interfaces.append(current); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3885 |
else |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3886 |
classes.append(current); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3887 |
for (Type t : cl.tail) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3888 |
// skip supertypes of 'current' in cl.tail |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3889 |
if (isSubtypeNoCapture(current, t)) |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3890 |
toSkip.add(t); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3891 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3892 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
3893 |
cl = cl.tail; |
10 | 3894 |
} |
3895 |
return classes.appendList(interfaces).toList(); |
|
3896 |
} |
|
3897 |
||
3898 |
/** |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3899 |
* Return the least upper bound of list of types. if the lub does |
10 | 3900 |
* not exist return null. |
3901 |
*/ |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3902 |
public Type lub(List<Type> ts) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3903 |
return lub(ts.toArray(new Type[ts.length()])); |
10 | 3904 |
} |
3905 |
||
3906 |
/** |
|
3907 |
* Return the least upper bound (lub) of set of types. If the lub |
|
3908 |
* does not exist return the type of null (bottom). |
|
3909 |
*/ |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3910 |
public Type lub(Type... ts) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3911 |
final int UNKNOWN_BOUND = 0; |
10 | 3912 |
final int ARRAY_BOUND = 1; |
3913 |
final int CLASS_BOUND = 2; |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3914 |
|
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3915 |
int[] kinds = new int[ts.length]; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3916 |
|
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3917 |
int boundkind = UNKNOWN_BOUND; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3918 |
for (int i = 0 ; i < ts.length ; i++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3919 |
Type t = ts[i]; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3920 |
switch (t.getTag()) { |
10 | 3921 |
case CLASS: |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3922 |
boundkind |= kinds[i] = CLASS_BOUND; |
10 | 3923 |
break; |
3924 |
case ARRAY: |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3925 |
boundkind |= kinds[i] = ARRAY_BOUND; |
10 | 3926 |
break; |
3927 |
case TYPEVAR: |
|
3928 |
do { |
|
3929 |
t = t.getUpperBound(); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3930 |
} while (t.hasTag(TYPEVAR)); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3931 |
if (t.hasTag(ARRAY)) { |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3932 |
boundkind |= kinds[i] = ARRAY_BOUND; |
10 | 3933 |
} else { |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3934 |
boundkind |= kinds[i] = CLASS_BOUND; |
10 | 3935 |
} |
3936 |
break; |
|
3937 |
default: |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3938 |
kinds[i] = UNKNOWN_BOUND; |
10 | 3939 |
if (t.isPrimitive()) |
162
6620f2a8e265
6611449: Internal Error thrown during generic method/constructor invocation
mcimadamore
parents:
10
diff
changeset
|
3940 |
return syms.errType; |
10 | 3941 |
} |
3942 |
} |
|
3943 |
switch (boundkind) { |
|
3944 |
case 0: |
|
3945 |
return syms.botType; |
|
3946 |
||
3947 |
case ARRAY_BOUND: |
|
3948 |
// calculate lub(A[], B[]) |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3949 |
Type[] elements = new Type[ts.length]; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3950 |
for (int i = 0 ; i < ts.length ; i++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3951 |
Type elem = elements[i] = elemTypeFun.apply(ts[i]); |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3952 |
if (elem.isPrimitive()) { |
10 | 3953 |
// if a primitive type is found, then return |
3954 |
// arraySuperType unless all the types are the |
|
3955 |
// same |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3956 |
Type first = ts[0]; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3957 |
for (int j = 1 ; j < ts.length ; j++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3958 |
if (!isSameType(first, ts[j])) { |
10 | 3959 |
// lub(int[], B[]) is Cloneable & Serializable |
3960 |
return arraySuperType(); |
|
3961 |
} |
|
3962 |
} |
|
3963 |
// all the array types are the same, return one |
|
3964 |
// lub(int[], int[]) is int[] |
|
3965 |
return first; |
|
3966 |
} |
|
3967 |
} |
|
3968 |
// lub(A[], B[]) is lub(A, B)[] |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
3969 |
return new ArrayType(lub(elements), syms.arrayClass); |
10 | 3970 |
|
3971 |
case CLASS_BOUND: |
|
3972 |
// calculate lub(A, B) |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3973 |
int startIdx = 0; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3974 |
for (int i = 0; i < ts.length ; i++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3975 |
Type t = ts[i]; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3976 |
if (t.hasTag(CLASS) || t.hasTag(TYPEVAR)) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3977 |
break; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3978 |
} else { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3979 |
startIdx++; |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3980 |
} |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3981 |
} |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3982 |
Assert.check(startIdx < ts.length); |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3983 |
//step 1 - compute erased candidate set (EC) |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3984 |
List<Type> cl = erasedSupertypes(ts[startIdx]); |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3985 |
for (int i = startIdx + 1 ; i < ts.length ; i++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3986 |
Type t = ts[i]; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
3987 |
if (t.hasTag(CLASS) || t.hasTag(TYPEVAR)) |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3988 |
cl = intersect(cl, erasedSupertypes(t)); |
10 | 3989 |
} |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3990 |
//step 2 - compute minimal erased candidate set (MEC) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3991 |
List<Type> mec = closureMin(cl); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3992 |
//step 3 - for each element G in MEC, compute lci(Inv(G)) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3993 |
List<Type> candidates = List.nil(); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3994 |
for (Type erasedSupertype : mec) { |
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3995 |
List<Type> lci = List.of(asSuper(ts[startIdx], erasedSupertype.tsym)); |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
3996 |
for (int i = startIdx + 1 ; i < ts.length ; i++) { |
27228
da96e0643b5c
8057800: Method reference with generic type creates NPE when compiling
vromero
parents:
27224
diff
changeset
|
3997 |
Type superType = asSuper(ts[i], erasedSupertype.tsym); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42819
diff
changeset
|
3998 |
lci = intersect(lci, superType != null ? List.of(superType) : List.nil()); |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
3999 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4000 |
candidates = candidates.appendList(lci); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4001 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4002 |
//step 4 - let MEC be { G1, G2 ... Gn }, then we have that |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4003 |
//lub = lci(Inv(G1)) & lci(Inv(G2)) & ... & lci(Inv(Gn)) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4004 |
return compoundMin(candidates); |
10 | 4005 |
|
4006 |
default: |
|
4007 |
// calculate lub(A, B[]) |
|
4008 |
List<Type> classes = List.of(arraySuperType()); |
|
27125
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
4009 |
for (int i = 0 ; i < ts.length ; i++) { |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
4010 |
if (kinds[i] != ARRAY_BOUND) // Filter out any arrays |
6c718c5086b3
8058511: StackOverflowError at com.sun.tools.javac.code.Types.lub
mcimadamore
parents:
26781
diff
changeset
|
4011 |
classes = classes.prepend(ts[i]); |
10 | 4012 |
} |
4013 |
// lub(A, B[]) is lub(A, arraySuperType) |
|
4014 |
return lub(classes); |
|
4015 |
} |
|
4016 |
} |
|
4017 |
// where |
|
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4018 |
List<Type> erasedSupertypes(Type t) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
4019 |
ListBuffer<Type> buf = new ListBuffer<>(); |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4020 |
for (Type sup : closure(t)) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4021 |
if (sup.hasTag(TYPEVAR)) { |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4022 |
buf.append(sup); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4023 |
} else { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4024 |
buf.append(erasure(sup)); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4025 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4026 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4027 |
return buf.toList(); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4028 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
4029 |
|
10 | 4030 |
private Type arraySuperType = null; |
4031 |
private Type arraySuperType() { |
|
4032 |
// initialized lazily to avoid problems during compiler startup |
|
4033 |
if (arraySuperType == null) { |
|
4034 |
synchronized (this) { |
|
4035 |
if (arraySuperType == null) { |
|
4036 |
// JLS 10.8: all arrays implement Cloneable and Serializable. |
|
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
4037 |
arraySuperType = makeIntersectionType(List.of(syms.serializableType, |
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
4038 |
syms.cloneableType), true); |
10 | 4039 |
} |
4040 |
} |
|
4041 |
} |
|
4042 |
return arraySuperType; |
|
4043 |
} |
|
4044 |
// </editor-fold> |
|
4045 |
||
4046 |
// <editor-fold defaultstate="collapsed" desc="Greatest lower bound"> |
|
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4047 |
public Type glb(List<Type> ts) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4048 |
Type t1 = ts.head; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4049 |
for (Type t2 : ts.tail) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4050 |
if (t1.isErroneous()) |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4051 |
return t1; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4052 |
t1 = glb(t1, t2); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4053 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4054 |
return t1; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4055 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
4056 |
//where |
10 | 4057 |
public Type glb(Type t, Type s) { |
4058 |
if (s == null) |
|
4059 |
return t; |
|
7331
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4060 |
else if (t.isPrimitive() || s.isPrimitive()) |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4061 |
return syms.errType; |
10 | 4062 |
else if (isSubtypeNoCapture(t, s)) |
4063 |
return t; |
|
4064 |
else if (isSubtypeNoCapture(s, t)) |
|
4065 |
return s; |
|
4066 |
||
4067 |
List<Type> closure = union(closure(t), closure(s)); |
|
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4068 |
return glbFlattened(closure, t); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4069 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4070 |
//where |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4071 |
/** |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4072 |
* Perform glb for a list of non-primitive, non-error, non-compound types; |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4073 |
* redundant elements are removed. Bounds should be ordered according to |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4074 |
* {@link Symbol#precedes(TypeSymbol,Types)}. |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4075 |
* |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4076 |
* @param flatBounds List of type to glb |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4077 |
* @param errT Original type to use if the result is an error type |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4078 |
*/ |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4079 |
private Type glbFlattened(List<Type> flatBounds, Type errT) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4080 |
List<Type> bounds = closureMin(flatBounds); |
10 | 4081 |
|
4082 |
if (bounds.isEmpty()) { // length == 0 |
|
4083 |
return syms.objectType; |
|
4084 |
} else if (bounds.tail.isEmpty()) { // length == 1 |
|
4085 |
return bounds.head; |
|
4086 |
} else { // length > 1 |
|
4087 |
int classCount = 0; |
|
43025
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4088 |
List<Type> cvars = List.nil(); |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4089 |
List<Type> lowers = List.nil(); |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4090 |
for (Type bound : bounds) { |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4091 |
if (!bound.isInterface()) { |
10 | 4092 |
classCount++; |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4093 |
Type lower = cvarLowerBound(bound); |
43025
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4094 |
if (bound != lower && !lower.hasTag(BOT)) { |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4095 |
cvars = cvars.append(bound); |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4096 |
lowers = lowers.append(lower); |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4097 |
} |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4098 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4099 |
} |
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4100 |
if (classCount > 1) { |
43025
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4101 |
if (lowers.isEmpty()) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4102 |
return createErrorType(errT); |
43025
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4103 |
} else { |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4104 |
// try again with lower bounds included instead of capture variables |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4105 |
List<Type> newBounds = bounds.diff(cvars).appendList(lowers); |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4106 |
return glb(newBounds); |
b6e87a8600a4
8144066: StackOverflowException when computing glb
dlsmith
parents:
42973
diff
changeset
|
4107 |
} |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4108 |
} |
10 | 4109 |
} |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29146
diff
changeset
|
4110 |
return makeIntersectionType(bounds); |
10 | 4111 |
} |
4112 |
// </editor-fold> |
|
4113 |
||
4114 |
// <editor-fold defaultstate="collapsed" desc="hashCode"> |
|
4115 |
/** |
|
4116 |
* Compute a hash code on a type. |
|
4117 |
*/ |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4118 |
public int hashCode(Type t) { |
32915
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4119 |
return hashCode(t, false); |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4120 |
} |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4121 |
|
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4122 |
public int hashCode(Type t, boolean strict) { |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4123 |
return strict ? |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4124 |
hashCodeStrictVisitor.visit(t) : |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4125 |
hashCodeVisitor.visit(t); |
10 | 4126 |
} |
4127 |
// where |
|
32915
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4128 |
private static final HashCodeVisitor hashCodeVisitor = new HashCodeVisitor(); |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4129 |
private static final HashCodeVisitor hashCodeStrictVisitor = new HashCodeVisitor() { |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4130 |
@Override |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4131 |
public Integer visitTypeVar(TypeVar t, Void ignored) { |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4132 |
return System.identityHashCode(t); |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4133 |
} |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4134 |
}; |
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4135 |
|
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4136 |
private static class HashCodeVisitor extends UnaryVisitor<Integer> { |
10 | 4137 |
public Integer visitType(Type t, Void ignored) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4138 |
return t.getTag().ordinal(); |
10 | 4139 |
} |
4140 |
||
4141 |
@Override |
|
4142 |
public Integer visitClassType(ClassType t, Void ignored) { |
|
4143 |
int result = visit(t.getEnclosingType()); |
|
4144 |
result *= 127; |
|
4145 |
result += t.tsym.flatName().hashCode(); |
|
4146 |
for (Type s : t.getTypeArguments()) { |
|
4147 |
result *= 127; |
|
4148 |
result += visit(s); |
|
4149 |
} |
|
4150 |
return result; |
|
4151 |
} |
|
4152 |
||
4153 |
@Override |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4154 |
public Integer visitMethodType(MethodType t, Void ignored) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4155 |
int h = METHOD.ordinal(); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4156 |
for (List<Type> thisargs = t.argtypes; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4157 |
thisargs.tail != null; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4158 |
thisargs = thisargs.tail) |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4159 |
h = (h << 5) + visit(thisargs.head); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4160 |
return (h << 5) + visit(t.restype); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4161 |
} |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4162 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4163 |
@Override |
10 | 4164 |
public Integer visitWildcardType(WildcardType t, Void ignored) { |
4165 |
int result = t.kind.hashCode(); |
|
4166 |
if (t.type != null) { |
|
4167 |
result *= 127; |
|
4168 |
result += visit(t.type); |
|
4169 |
} |
|
4170 |
return result; |
|
4171 |
} |
|
4172 |
||
4173 |
@Override |
|
4174 |
public Integer visitArrayType(ArrayType t, Void ignored) { |
|
4175 |
return visit(t.elemtype) + 12; |
|
4176 |
} |
|
4177 |
||
4178 |
@Override |
|
4179 |
public Integer visitTypeVar(TypeVar t, Void ignored) { |
|
33917
45d04023e689
8067767: type inference performance regression
mcimadamore
parents:
33915
diff
changeset
|
4180 |
return System.identityHashCode(t); |
10 | 4181 |
} |
4182 |
||
4183 |
@Override |
|
4184 |
public Integer visitUndetVar(UndetVar t, Void ignored) { |
|
4185 |
return System.identityHashCode(t); |
|
4186 |
} |
|
4187 |
||
4188 |
@Override |
|
4189 |
public Integer visitErrorType(ErrorType t, Void ignored) { |
|
4190 |
return 0; |
|
4191 |
} |
|
32915
eb290482d42f
8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables
vromero
parents:
32709
diff
changeset
|
4192 |
} |
10 | 4193 |
// </editor-fold> |
4194 |
||
4195 |
// <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable"> |
|
4196 |
/** |
|
4197 |
* Does t have a result that is a subtype of the result type of s, |
|
4198 |
* suitable for covariant returns? It is assumed that both types |
|
4199 |
* are (possibly polymorphic) method types. Monomorphic method |
|
4200 |
* types are handled in the obvious way. Polymorphic method types |
|
4201 |
* require renaming all type variables of one to corresponding |
|
4202 |
* type variables in the other, where correspondence is by |
|
4203 |
* position in the type parameter list. */ |
|
4204 |
public boolean resultSubtype(Type t, Type s, Warner warner) { |
|
4205 |
List<Type> tvars = t.getTypeArguments(); |
|
4206 |
List<Type> svars = s.getTypeArguments(); |
|
4207 |
Type tres = t.getReturnType(); |
|
4208 |
Type sres = subst(s.getReturnType(), svars, tvars); |
|
4209 |
return covariantReturnType(tres, sres, warner); |
|
4210 |
} |
|
4211 |
||
4212 |
/** |
|
4213 |
* Return-Type-Substitutable. |
|
54952
a978d86ac389
8224175: Fix inconsistencies in @jls and @jvms tags
darcy
parents:
54762
diff
changeset
|
4214 |
* @jls 8.4.5 Method Result |
10 | 4215 |
*/ |
4216 |
public boolean returnTypeSubstitutable(Type r1, Type r2) { |
|
4217 |
if (hasSameArgs(r1, r2)) |
|
14547 | 4218 |
return resultSubtype(r1, r2, noWarnings); |
10 | 4219 |
else |
4220 |
return covariantReturnType(r1.getReturnType(), |
|
1874 | 4221 |
erasure(r2.getReturnType()), |
14547 | 4222 |
noWarnings); |
1874 | 4223 |
} |
4224 |
||
4225 |
public boolean returnTypeSubstitutable(Type r1, |
|
4226 |
Type r2, Type r2res, |
|
4227 |
Warner warner) { |
|
4228 |
if (isSameType(r1.getReturnType(), r2res)) |
|
4229 |
return true; |
|
4230 |
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive()) |
|
4231 |
return false; |
|
4232 |
||
4233 |
if (hasSameArgs(r1, r2)) |
|
4234 |
return covariantReturnType(r1.getReturnType(), r2res, warner); |
|
4235 |
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner)) |
|
4236 |
return true; |
|
53046
9b0d6ecd8e45
8215625: javax/sql/testng/util/xxxxx.java tests compilation failed after JDK-8207224
vromero
parents:
53040
diff
changeset
|
4237 |
if (!isSubtype(r1.getReturnType(), erasure(r2res))) |
9b0d6ecd8e45
8215625: javax/sql/testng/util/xxxxx.java tests compilation failed after JDK-8207224
vromero
parents:
53040
diff
changeset
|
4238 |
return false; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
4239 |
warner.warn(LintCategory.UNCHECKED); |
1874 | 4240 |
return true; |
10 | 4241 |
} |
4242 |
||
4243 |
/** |
|
4244 |
* Is t an appropriate return type in an overrider for a |
|
4245 |
* method that returns s? |
|
4246 |
*/ |
|
4247 |
public boolean covariantReturnType(Type t, Type s, Warner warner) { |
|
1874 | 4248 |
return |
4249 |
isSameType(t, s) || |
|
10 | 4250 |
!t.isPrimitive() && |
1874 | 4251 |
!s.isPrimitive() && |
4252 |
isAssignable(t, s, warner); |
|
10 | 4253 |
} |
4254 |
// </editor-fold> |
|
4255 |
||
4256 |
// <editor-fold defaultstate="collapsed" desc="Box/unbox support"> |
|
4257 |
/** |
|
4258 |
* Return the class that boxes the given primitive. |
|
4259 |
*/ |
|
4260 |
public ClassSymbol boxedClass(Type t) { |
|
36526 | 4261 |
return syms.enterClass(syms.java_base, syms.boxedName[t.getTag().ordinal()]); |
10 | 4262 |
} |
4263 |
||
4264 |
/** |
|
7331
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4265 |
* Return the boxed type if 't' is primitive, otherwise return 't' itself. |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4266 |
*/ |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4267 |
public Type boxedTypeOrType(Type t) { |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4268 |
return t.isPrimitive() ? |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4269 |
boxedClass(t).type : |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4270 |
t; |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4271 |
} |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4272 |
|
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
4273 |
/** |
10 | 4274 |
* Return the primitive type corresponding to a boxed type. |
4275 |
*/ |
|
4276 |
public Type unboxedType(Type t) { |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
4277 |
for (int i=0; i<syms.boxedName.length; i++) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
4278 |
Name box = syms.boxedName[i]; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
4279 |
if (box != null && |
36526 | 4280 |
asSuper(t, syms.enterClass(syms.java_base, box)) != null) |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
4281 |
return syms.typeOfTag[i]; |
10 | 4282 |
} |
4283 |
return Type.noType; |
|
4284 |
} |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4285 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4286 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4287 |
* Return the unboxed type if 't' is a boxed class, otherwise return 't' itself. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4288 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4289 |
public Type unboxedTypeOrType(Type t) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4290 |
Type unboxedType = unboxedType(t); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4291 |
return unboxedType.hasTag(NONE) ? t : unboxedType; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
4292 |
} |
10 | 4293 |
// </editor-fold> |
4294 |
||
4295 |
// <editor-fold defaultstate="collapsed" desc="Capture conversion"> |
|
4296 |
/* |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
4297 |
* JLS 5.1.10 Capture Conversion: |
10 | 4298 |
* |
4299 |
* Let G name a generic type declaration with n formal type |
|
4300 |
* parameters A1 ... An with corresponding bounds U1 ... Un. There |
|
4301 |
* exists a capture conversion from G<T1 ... Tn> to G<S1 ... Sn>, |
|
4302 |
* where, for 1 <= i <= n: |
|
4303 |
* |
|
4304 |
* + If Ti is a wildcard type argument (4.5.1) of the form ? then |
|
4305 |
* Si is a fresh type variable whose upper bound is |
|
4306 |
* Ui[A1 := S1, ..., An := Sn] and whose lower bound is the null |
|
4307 |
* type. |
|
4308 |
* |
|
4309 |
* + If Ti is a wildcard type argument of the form ? extends Bi, |
|
4310 |
* then Si is a fresh type variable whose upper bound is |
|
4311 |
* glb(Bi, Ui[A1 := S1, ..., An := Sn]) and whose lower bound is |
|
4312 |
* the null type, where glb(V1,... ,Vm) is V1 & ... & Vm. It is |
|
4313 |
* a compile-time error if for any two classes (not interfaces) |
|
4314 |
* Vi and Vj,Vi is not a subclass of Vj or vice versa. |
|
4315 |
* |
|
4316 |
* + If Ti is a wildcard type argument of the form ? super Bi, |
|
4317 |
* then Si is a fresh type variable whose upper bound is |
|
4318 |
* Ui[A1 := S1, ..., An := Sn] and whose lower bound is Bi. |
|
4319 |
* |
|
4320 |
* + Otherwise, Si = Ti. |
|
4321 |
* |
|
4322 |
* Capture conversion on any type other than a parameterized type |
|
4323 |
* (4.5) acts as an identity conversion (5.1.1). Capture |
|
4324 |
* conversions never require a special action at run time and |
|
4325 |
* therefore never throw an exception at run time. |
|
4326 |
* |
|
4327 |
* Capture conversion is not applied recursively. |
|
4328 |
*/ |
|
4329 |
/** |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
4330 |
* Capture conversion as specified by the JLS. |
10 | 4331 |
*/ |
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4332 |
|
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4333 |
public List<Type> capture(List<Type> ts) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4334 |
List<Type> buf = List.nil(); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4335 |
for (Type t : ts) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4336 |
buf = buf.prepend(capture(t)); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4337 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4338 |
return buf.reverse(); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
4339 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
4340 |
|
10 | 4341 |
public Type capture(Type t) { |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
4342 |
if (!t.hasTag(CLASS)) { |
10 | 4343 |
return t; |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23810
diff
changeset
|
4344 |
} |
6350
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4345 |
if (t.getEnclosingType() != Type.noType) { |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4346 |
Type capturedEncl = capture(t.getEnclosingType()); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4347 |
if (capturedEncl != t.getEnclosingType()) { |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4348 |
Type type1 = memberType(capturedEncl, t.tsym); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4349 |
t = subst(type1, t.tsym.type.getTypeArguments(), t.getTypeArguments()); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4350 |
} |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
4351 |
} |
10 | 4352 |
ClassType cls = (ClassType)t; |
4353 |
if (cls.isRaw() || !cls.isParameterized()) |
|
4354 |
return cls; |
|
4355 |
||
4356 |
ClassType G = (ClassType)cls.asElement().asType(); |
|
4357 |
List<Type> A = G.getTypeArguments(); |
|
4358 |
List<Type> T = cls.getTypeArguments(); |
|
4359 |
List<Type> S = freshTypeVariables(T); |
|
4360 |
||
4361 |
List<Type> currentA = A; |
|
4362 |
List<Type> currentT = T; |
|
4363 |
List<Type> currentS = S; |
|
4364 |
boolean captured = false; |
|
4365 |
while (!currentA.isEmpty() && |
|
4366 |
!currentT.isEmpty() && |
|
4367 |
!currentS.isEmpty()) { |
|
4368 |
if (currentS.head != currentT.head) { |
|
4369 |
captured = true; |
|
24396 | 4370 |
WildcardType Ti = (WildcardType)currentT.head; |
10 | 4371 |
Type Ui = currentA.head.getUpperBound(); |
24396 | 4372 |
CapturedType Si = (CapturedType)currentS.head; |
10 | 4373 |
if (Ui == null) |
4374 |
Ui = syms.objectType; |
|
4375 |
switch (Ti.kind) { |
|
4376 |
case UNBOUND: |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4377 |
Si.setUpperBound( subst(Ui, A, S) ); |
10 | 4378 |
Si.lower = syms.botType; |
4379 |
break; |
|
4380 |
case EXTENDS: |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4381 |
Si.setUpperBound( glb(Ti.getExtendsBound(), subst(Ui, A, S)) ); |
10 | 4382 |
Si.lower = syms.botType; |
4383 |
break; |
|
4384 |
case SUPER: |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4385 |
Si.setUpperBound( subst(Ui, A, S) ); |
10 | 4386 |
Si.lower = Ti.getSuperBound(); |
4387 |
break; |
|
4388 |
} |
|
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4389 |
Type tmpBound = Si.getUpperBound().hasTag(UNDETVAR) ? ((UndetVar)Si.getUpperBound()).qtype : Si.getUpperBound(); |
24291
440746208be7
8033437: javac, inconsistent generic types behaviour when compiling together vs. separate
pgovereau
parents:
24226
diff
changeset
|
4390 |
Type tmpLower = Si.lower.hasTag(UNDETVAR) ? ((UndetVar)Si.lower).qtype : Si.lower; |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4391 |
if (!Si.getUpperBound().hasTag(ERROR) && |
24291
440746208be7
8033437: javac, inconsistent generic types behaviour when compiling together vs. separate
pgovereau
parents:
24226
diff
changeset
|
4392 |
!Si.lower.hasTag(ERROR) && |
48661
19173eb3358b
8196074: Remove uses of loose type equality tests
mcimadamore
parents:
48054
diff
changeset
|
4393 |
isSameType(tmpBound, tmpLower)) { |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4394 |
currentS.head = Si.getUpperBound(); |
24291
440746208be7
8033437: javac, inconsistent generic types behaviour when compiling together vs. separate
pgovereau
parents:
24226
diff
changeset
|
4395 |
} |
10 | 4396 |
} |
4397 |
currentA = currentA.tail; |
|
4398 |
currentT = currentT.tail; |
|
4399 |
currentS = currentS.tail; |
|
4400 |
} |
|
4401 |
if (!currentA.isEmpty() || !currentT.isEmpty() || !currentS.isEmpty()) |
|
4402 |
return erasure(t); // some "rare" type involved |
|
4403 |
||
4404 |
if (captured) |
|
24396 | 4405 |
return new ClassType(cls.getEnclosingType(), S, cls.tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4406 |
cls.getMetadata()); |
10 | 4407 |
else |
4408 |
return t; |
|
4409 |
} |
|
4410 |
// where |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
4411 |
public List<Type> freshTypeVariables(List<Type> types) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
4412 |
ListBuffer<Type> result = new ListBuffer<>(); |
10 | 4413 |
for (Type t : types) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4414 |
if (t.hasTag(WILDCARD)) { |
10 | 4415 |
Type bound = ((WildcardType)t).getExtendsBound(); |
4416 |
if (bound == null) |
|
4417 |
bound = syms.objectType; |
|
4418 |
result.append(new CapturedType(capturedName, |
|
4419 |
syms.noSymbol, |
|
4420 |
bound, |
|
4421 |
syms.botType, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4422 |
(WildcardType)t)); |
10 | 4423 |
} else { |
4424 |
result.append(t); |
|
4425 |
} |
|
4426 |
} |
|
4427 |
return result.toList(); |
|
4428 |
} |
|
4429 |
// </editor-fold> |
|
4430 |
||
4431 |
// <editor-fold defaultstate="collapsed" desc="Internal utility methods"> |
|
4432 |
private boolean sideCast(Type from, Type to, Warner warn) { |
|
4433 |
// We are casting from type $from$ to type $to$, which are |
|
4434 |
// non-final unrelated types. This method |
|
4435 |
// tries to reject a cast by transferring type parameters |
|
4436 |
// from $to$ to $from$ by common superinterfaces. |
|
4437 |
boolean reverse = false; |
|
4438 |
Type target = to; |
|
4439 |
if ((to.tsym.flags() & INTERFACE) == 0) { |
|
8032 | 4440 |
Assert.check((from.tsym.flags() & INTERFACE) != 0); |
10 | 4441 |
reverse = true; |
4442 |
to = from; |
|
4443 |
from = target; |
|
4444 |
} |
|
4445 |
List<Type> commonSupers = superClosure(to, erasure(from)); |
|
4446 |
boolean giveWarning = commonSupers.isEmpty(); |
|
4447 |
// The arguments to the supers could be unified here to |
|
4448 |
// get a more accurate analysis |
|
4449 |
while (commonSupers.nonEmpty()) { |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
4450 |
Type t1 = asSuper(from, commonSupers.head.tsym); |
10 | 4451 |
Type t2 = commonSupers.head; // same as asSuper(to, commonSupers.head.tsym); |
4452 |
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments())) |
|
4453 |
return false; |
|
4454 |
giveWarning = giveWarning || (reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)); |
|
4455 |
commonSupers = commonSupers.tail; |
|
4456 |
} |
|
1792 | 4457 |
if (giveWarning && !isReifiable(reverse ? from : to)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
4458 |
warn.warn(LintCategory.UNCHECKED); |
10 | 4459 |
return true; |
4460 |
} |
|
4461 |
||
4462 |
private boolean sideCastFinal(Type from, Type to, Warner warn) { |
|
4463 |
// We are casting from type $from$ to type $to$, which are |
|
4464 |
// unrelated types one of which is final and the other of |
|
4465 |
// which is an interface. This method |
|
4466 |
// tries to reject a cast by transferring type parameters |
|
4467 |
// from the final class to the interface. |
|
4468 |
boolean reverse = false; |
|
4469 |
Type target = to; |
|
4470 |
if ((to.tsym.flags() & INTERFACE) == 0) { |
|
8032 | 4471 |
Assert.check((from.tsym.flags() & INTERFACE) != 0); |
10 | 4472 |
reverse = true; |
4473 |
to = from; |
|
4474 |
from = target; |
|
4475 |
} |
|
8032 | 4476 |
Assert.check((from.tsym.flags() & FINAL) != 0); |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21041
diff
changeset
|
4477 |
Type t1 = asSuper(from, to.tsym); |
10 | 4478 |
if (t1 == null) return false; |
4479 |
Type t2 = to; |
|
4480 |
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments())) |
|
4481 |
return false; |
|
4482 |
if (!isReifiable(target) && |
|
4483 |
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2))) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
4484 |
warn.warn(LintCategory.UNCHECKED); |
10 | 4485 |
return true; |
4486 |
} |
|
4487 |
||
4488 |
private boolean giveWarning(Type from, Type to) { |
|
16565
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4489 |
List<Type> bounds = to.isCompound() ? |
33556
a14a556cf2c9
8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents:
32915
diff
changeset
|
4490 |
directSupertypes(to) : List.of(to); |
16565
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4491 |
for (Type b : bounds) { |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4492 |
Type subFrom = asSub(from, b.tsym); |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4493 |
if (b.isParameterized() && |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4494 |
(!(isUnbounded(b) || |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4495 |
isSubtype(from, b) || |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4496 |
((subFrom != null) && containsType(b.allparams(), subFrom.allparams()))))) { |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4497 |
return true; |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4498 |
} |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4499 |
} |
aee0d0aaec44
8010101: Intersection type cast issues redundant unchecked warning
mcimadamore
parents:
16556
diff
changeset
|
4500 |
return false; |
10 | 4501 |
} |
4502 |
||
4503 |
private List<Type> superClosure(Type t, Type s) { |
|
4504 |
List<Type> cl = List.nil(); |
|
4505 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |
|
4506 |
if (isSubtype(s, erasure(l.head))) { |
|
4507 |
cl = insert(cl, l.head); |
|
4508 |
} else { |
|
4509 |
cl = union(cl, superClosure(l.head, s)); |
|
4510 |
} |
|
4511 |
} |
|
4512 |
return cl; |
|
4513 |
} |
|
4514 |
||
4515 |
private boolean containsTypeEquivalent(Type t, Type s) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
4516 |
return isSameType(t, s) || // shortcut |
10 | 4517 |
containsType(t, s) && containsType(s, t); |
4518 |
} |
|
4519 |
||
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4520 |
// <editor-fold defaultstate="collapsed" desc="adapt"> |
10 | 4521 |
/** |
4522 |
* Adapt a type by computing a substitution which maps a source |
|
4523 |
* type to a target type. |
|
4524 |
* |
|
4525 |
* @param source the source type |
|
4526 |
* @param target the target type |
|
4527 |
* @param from the type variables of the computed substitution |
|
4528 |
* @param to the types of the computed substitution. |
|
4529 |
*/ |
|
4530 |
public void adapt(Type source, |
|
4531 |
Type target, |
|
4532 |
ListBuffer<Type> from, |
|
4533 |
ListBuffer<Type> to) throws AdaptFailure { |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4534 |
new Adapter(from, to).adapt(source, target); |
10 | 4535 |
} |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4536 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4537 |
class Adapter extends SimpleVisitor<Void, Type> { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4538 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4539 |
ListBuffer<Type> from; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4540 |
ListBuffer<Type> to; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4541 |
Map<Symbol,Type> mapping; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4542 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4543 |
Adapter(ListBuffer<Type> from, ListBuffer<Type> to) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4544 |
this.from = from; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4545 |
this.to = to; |
22163 | 4546 |
mapping = new HashMap<>(); |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4547 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4548 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4549 |
public void adapt(Type source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4550 |
visit(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4551 |
List<Type> fromList = from.toList(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4552 |
List<Type> toList = to.toList(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4553 |
while (!fromList.isEmpty()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4554 |
Type val = mapping.get(fromList.head.tsym); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4555 |
if (toList.head != val) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4556 |
toList.head = val; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4557 |
fromList = fromList.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4558 |
toList = toList.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4559 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4560 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4561 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4562 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4563 |
public Void visitClassType(ClassType source, Type target) throws AdaptFailure { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4564 |
if (target.hasTag(CLASS)) |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4565 |
adaptRecursive(source.allparams(), target.allparams()); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4566 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4567 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4568 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4569 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4570 |
public Void visitArrayType(ArrayType source, Type target) throws AdaptFailure { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4571 |
if (target.hasTag(ARRAY)) |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4572 |
adaptRecursive(elemtype(source), elemtype(target)); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4573 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4574 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4575 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4576 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4577 |
public Void visitWildcardType(WildcardType source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4578 |
if (source.isExtendsBound()) |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
4579 |
adaptRecursive(wildUpperBound(source), wildUpperBound(target)); |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4580 |
else if (source.isSuperBound()) |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4581 |
adaptRecursive(wildLowerBound(source), wildLowerBound(target)); |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4582 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4583 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4584 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4585 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4586 |
public Void visitTypeVar(TypeVar source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4587 |
// Check to see if there is |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4588 |
// already a mapping for $source$, in which case |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4589 |
// the old mapping will be merged with the new |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4590 |
Type val = mapping.get(source.tsym); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4591 |
if (val != null) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4592 |
if (val.isSuperBound() && target.isSuperBound()) { |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24291
diff
changeset
|
4593 |
val = isSubtype(wildLowerBound(val), wildLowerBound(target)) |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4594 |
? target : val; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4595 |
} else if (val.isExtendsBound() && target.isExtendsBound()) { |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
4596 |
val = isSubtype(wildUpperBound(val), wildUpperBound(target)) |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4597 |
? val : target; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4598 |
} else if (!isSameType(val, target)) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4599 |
throw new AdaptFailure(); |
10 | 4600 |
} |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4601 |
} else { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4602 |
val = target; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4603 |
from.append(source); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4604 |
to.append(target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4605 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4606 |
mapping.put(source.tsym, val); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4607 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4608 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4609 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4610 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4611 |
public Void visitType(Type source, Type target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4612 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4613 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4614 |
|
22163 | 4615 |
private Set<TypePair> cache = new HashSet<>(); |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4616 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4617 |
private void adaptRecursive(Type source, Type target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4618 |
TypePair pair = new TypePair(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4619 |
if (cache.add(pair)) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4620 |
try { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4621 |
visit(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4622 |
} finally { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4623 |
cache.remove(pair); |
10 | 4624 |
} |
4625 |
} |
|
4626 |
} |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4627 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4628 |
private void adaptRecursive(List<Type> source, List<Type> target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4629 |
if (source.length() == target.length()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4630 |
while (source.nonEmpty()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4631 |
adaptRecursive(source.head, target.head); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4632 |
source = source.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4633 |
target = target.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4634 |
} |
10 | 4635 |
} |
4636 |
} |
|
4637 |
} |
|
4638 |
||
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4639 |
public static class AdaptFailure extends RuntimeException { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4640 |
static final long serialVersionUID = -7490231548272701566L; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4641 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4642 |
|
10 | 4643 |
private void adaptSelf(Type t, |
4644 |
ListBuffer<Type> from, |
|
4645 |
ListBuffer<Type> to) { |
|
4646 |
try { |
|
4647 |
//if (t.tsym.type != t) |
|
4648 |
adapt(t.tsym.type, t, from, to); |
|
4649 |
} catch (AdaptFailure ex) { |
|
4650 |
// Adapt should never fail calculating a mapping from |
|
4651 |
// t.tsym.type to t as there can be no merge problem. |
|
4652 |
throw new AssertionError(ex); |
|
4653 |
} |
|
4654 |
} |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
4655 |
// </editor-fold> |
10 | 4656 |
|
4657 |
/** |
|
4658 |
* Rewrite all type variables (universal quantifiers) in the given |
|
4659 |
* type to wildcards (existential quantifiers). This is used to |
|
4660 |
* determine if a cast is allowed. For example, if high is true |
|
4661 |
* and {@code T <: Number}, then {@code List<T>} is rewritten to |
|
4662 |
* {@code List<? extends Number>}. Since {@code List<Integer> <: |
|
4663 |
* List<? extends Number>} a {@code List<T>} can be cast to {@code |
|
4664 |
* List<Integer>} with a warning. |
|
4665 |
* @param t a type |
|
4666 |
* @param high if true return an upper bound; otherwise a lower |
|
4667 |
* bound |
|
4668 |
* @param rewriteTypeVars only rewrite captured wildcards if false; |
|
4669 |
* otherwise rewrite all type variables |
|
4670 |
* @return the type rewritten with wildcards (existential |
|
4671 |
* quantifiers) only |
|
4672 |
*/ |
|
4673 |
private Type rewriteQuantifiers(Type t, boolean high, boolean rewriteTypeVars) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4674 |
return new Rewriter(high, rewriteTypeVars).visit(t); |
1530 | 4675 |
} |
4676 |
||
4677 |
class Rewriter extends UnaryVisitor<Type> { |
|
4678 |
||
4679 |
boolean high; |
|
4680 |
boolean rewriteTypeVars; |
|
4681 |
||
4682 |
Rewriter(boolean high, boolean rewriteTypeVars) { |
|
4683 |
this.high = high; |
|
4684 |
this.rewriteTypeVars = rewriteTypeVars; |
|
4685 |
} |
|
4686 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4687 |
@Override |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4688 |
public Type visitClassType(ClassType t, Void s) { |
22163 | 4689 |
ListBuffer<Type> rewritten = new ListBuffer<>(); |
1530 | 4690 |
boolean changed = false; |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4691 |
for (Type arg : t.allparams()) { |
1530 | 4692 |
Type bound = visit(arg); |
4693 |
if (arg != bound) { |
|
4694 |
changed = true; |
|
4695 |
} |
|
4696 |
rewritten.append(bound); |
|
10 | 4697 |
} |
1530 | 4698 |
if (changed) |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4699 |
return subst(t.tsym.type, |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4700 |
t.tsym.type.allparams(), |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4701 |
rewritten.toList()); |
1530 | 4702 |
else |
4703 |
return t; |
|
4704 |
} |
|
4705 |
||
4706 |
public Type visitType(Type t, Void s) { |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
4707 |
return t; |
1530 | 4708 |
} |
4709 |
||
4710 |
@Override |
|
4711 |
public Type visitCapturedType(CapturedType t, Void s) { |
|
11549
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4712 |
Type w_bound = t.wildcard.type; |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4713 |
Type bound = w_bound.contains(t) ? |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4714 |
erasure(w_bound) : |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4715 |
visit(w_bound); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4716 |
return rewriteAsWildcardType(visit(bound), t.wildcard.bound, t.wildcard.kind); |
10 | 4717 |
} |
1530 | 4718 |
|
4719 |
@Override |
|
4720 |
public Type visitTypeVar(TypeVar t, Void s) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4721 |
if (rewriteTypeVars) { |
53515
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4722 |
Type bound = t.getUpperBound().contains(t) ? |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4723 |
erasure(t.getUpperBound()) : |
a772e65727c5
8193367: Annotated type variable bounds crash javac
bsrbnd
parents:
53046
diff
changeset
|
4724 |
visit(t.getUpperBound()); |
11549
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4725 |
return rewriteAsWildcardType(bound, t, EXTENDS); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4726 |
} else { |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4727 |
return t; |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4728 |
} |
1530 | 4729 |
} |
4730 |
||
4731 |
@Override |
|
4732 |
public Type visitWildcardType(WildcardType t, Void s) { |
|
11549
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4733 |
Type bound2 = visit(t.type); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4734 |
return t.type == bound2 ? t : rewriteAsWildcardType(bound2, t.bound, t.kind); |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4735 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4736 |
|
11549
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4737 |
private Type rewriteAsWildcardType(Type bound, TypeVar formal, BoundKind bk) { |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4738 |
switch (bk) { |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4739 |
case EXTENDS: return high ? |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4740 |
makeExtendsWildcard(B(bound), formal) : |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4741 |
makeExtendsWildcard(syms.objectType, formal); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4742 |
case SUPER: return high ? |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4743 |
makeSuperWildcard(syms.botType, formal) : |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4744 |
makeSuperWildcard(B(bound), formal); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4745 |
case UNBOUND: return makeExtendsWildcard(syms.objectType, formal); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4746 |
default: |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4747 |
Assert.error("Invalid bound kind " + bk); |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4748 |
return null; |
cc901a28adc3
7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>
mcimadamore
parents:
10810
diff
changeset
|
4749 |
} |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4750 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4751 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4752 |
Type B(Type t) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4753 |
while (t.hasTag(WILDCARD)) { |
24396 | 4754 |
WildcardType w = (WildcardType)t; |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4755 |
t = high ? |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4756 |
w.getExtendsBound() : |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4757 |
w.getSuperBound(); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4758 |
if (t == null) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4759 |
t = high ? syms.objectType : syms.botType; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4760 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4761 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4762 |
return t; |
1530 | 4763 |
} |
10 | 4764 |
} |
4765 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
4766 |
|
10 | 4767 |
/** |
4768 |
* Create a wildcard with the given upper (extends) bound; create |
|
4769 |
* an unbounded wildcard if bound is Object. |
|
4770 |
* |
|
4771 |
* @param bound the upper bound |
|
4772 |
* @param formal the formal type parameter that will be |
|
4773 |
* substituted by the wildcard |
|
4774 |
*/ |
|
4775 |
private WildcardType makeExtendsWildcard(Type bound, TypeVar formal) { |
|
4776 |
if (bound == syms.objectType) { |
|
4777 |
return new WildcardType(syms.objectType, |
|
4778 |
BoundKind.UNBOUND, |
|
4779 |
syms.boundClass, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4780 |
formal); |
10 | 4781 |
} else { |
4782 |
return new WildcardType(bound, |
|
4783 |
BoundKind.EXTENDS, |
|
4784 |
syms.boundClass, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4785 |
formal); |
10 | 4786 |
} |
4787 |
} |
|
4788 |
||
4789 |
/** |
|
4790 |
* Create a wildcard with the given lower (super) bound; create an |
|
4791 |
* unbounded wildcard if bound is bottom (type of {@code null}). |
|
4792 |
* |
|
4793 |
* @param bound the lower bound |
|
4794 |
* @param formal the formal type parameter that will be |
|
4795 |
* substituted by the wildcard |
|
4796 |
*/ |
|
4797 |
private WildcardType makeSuperWildcard(Type bound, TypeVar formal) { |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18412
diff
changeset
|
4798 |
if (bound.hasTag(BOT)) { |
10 | 4799 |
return new WildcardType(syms.objectType, |
4800 |
BoundKind.UNBOUND, |
|
4801 |
syms.boundClass, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4802 |
formal); |
10 | 4803 |
} else { |
4804 |
return new WildcardType(bound, |
|
4805 |
BoundKind.SUPER, |
|
4806 |
syms.boundClass, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26107
diff
changeset
|
4807 |
formal); |
10 | 4808 |
} |
4809 |
} |
|
4810 |
||
4811 |
/** |
|
4812 |
* A wrapper for a type that allows use in sets. |
|
4813 |
*/ |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4814 |
public static class UniqueType { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4815 |
public final Type type; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4816 |
final Types types; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4817 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4818 |
public UniqueType(Type type, Types types) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4819 |
this.type = type; |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4820 |
this.types = types; |
10 | 4821 |
} |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4822 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4823 |
public int hashCode() { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4824 |
return types.hashCode(type); |
10 | 4825 |
} |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4826 |
|
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4827 |
public boolean equals(Object obj) { |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4828 |
return (obj instanceof UniqueType) && |
24396 | 4829 |
types.isSameType(type, ((UniqueType)obj).type); |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4830 |
} |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4831 |
|
10 | 4832 |
public String toString() { |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4833 |
return type.toString(); |
10 | 4834 |
} |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14801
diff
changeset
|
4835 |
|
10 | 4836 |
} |
4837 |
// </editor-fold> |
|
4838 |
||
4839 |
// <editor-fold defaultstate="collapsed" desc="Visitors"> |
|
4840 |
/** |
|
4841 |
* A default visitor for types. All visitor methods except |
|
4842 |
* visitType are implemented by delegating to visitType. Concrete |
|
4843 |
* subclasses must provide an implementation of visitType and can |
|
4844 |
* override other methods as needed. |
|
4845 |
* |
|
4846 |
* @param <R> the return type of the operation implemented by this |
|
4847 |
* visitor; use Void if no return type is needed. |
|
4848 |
* @param <S> the type of the second argument (the first being the |
|
4849 |
* type itself) of the operation implemented by this visitor; use |
|
4850 |
* Void if a second argument is not needed. |
|
4851 |
*/ |
|
4852 |
public static abstract class DefaultTypeVisitor<R,S> implements Type.Visitor<R,S> { |
|
4853 |
final public R visit(Type t, S s) { return t.accept(this, s); } |
|
4854 |
public R visitClassType(ClassType t, S s) { return visitType(t, s); } |
|
4855 |
public R visitWildcardType(WildcardType t, S s) { return visitType(t, s); } |
|
4856 |
public R visitArrayType(ArrayType t, S s) { return visitType(t, s); } |
|
4857 |
public R visitMethodType(MethodType t, S s) { return visitType(t, s); } |
|
4858 |
public R visitPackageType(PackageType t, S s) { return visitType(t, s); } |
|
36526 | 4859 |
public R visitModuleType(ModuleType t, S s) { return visitType(t, s); } |
10 | 4860 |
public R visitTypeVar(TypeVar t, S s) { return visitType(t, s); } |
4861 |
public R visitCapturedType(CapturedType t, S s) { return visitType(t, s); } |
|
4862 |
public R visitForAll(ForAll t, S s) { return visitType(t, s); } |
|
4863 |
public R visitUndetVar(UndetVar t, S s) { return visitType(t, s); } |
|
4864 |
public R visitErrorType(ErrorType t, S s) { return visitType(t, s); } |
|
4865 |
} |
|
4866 |
||
4867 |
/** |
|
1357 | 4868 |
* A default visitor for symbols. All visitor methods except |
4869 |
* visitSymbol are implemented by delegating to visitSymbol. Concrete |
|
4870 |
* subclasses must provide an implementation of visitSymbol and can |
|
4871 |
* override other methods as needed. |
|
4872 |
* |
|
4873 |
* @param <R> the return type of the operation implemented by this |
|
4874 |
* visitor; use Void if no return type is needed. |
|
4875 |
* @param <S> the type of the second argument (the first being the |
|
4876 |
* symbol itself) of the operation implemented by this visitor; use |
|
4877 |
* Void if a second argument is not needed. |
|
4878 |
*/ |
|
4879 |
public static abstract class DefaultSymbolVisitor<R,S> implements Symbol.Visitor<R,S> { |
|
4880 |
final public R visit(Symbol s, S arg) { return s.accept(this, arg); } |
|
4881 |
public R visitClassSymbol(ClassSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4882 |
public R visitMethodSymbol(MethodSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4883 |
public R visitOperatorSymbol(OperatorSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4884 |
public R visitPackageSymbol(PackageSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4885 |
public R visitTypeSymbol(TypeSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4886 |
public R visitVarSymbol(VarSymbol s, S arg) { return visitSymbol(s, arg); } |
|
4887 |
} |
|
4888 |
||
4889 |
/** |
|
10 | 4890 |
* A <em>simple</em> visitor for types. This visitor is simple as |
4891 |
* captured wildcards, for-all types (generic methods), and |
|
4892 |
* undetermined type variables (part of inference) are hidden. |
|
4893 |
* Captured wildcards are hidden by treating them as type |
|
4894 |
* variables and the rest are hidden by visiting their qtypes. |
|
4895 |
* |
|
4896 |
* @param <R> the return type of the operation implemented by this |
|
4897 |
* visitor; use Void if no return type is needed. |
|
4898 |
* @param <S> the type of the second argument (the first being the |
|
4899 |
* type itself) of the operation implemented by this visitor; use |
|
4900 |
* Void if a second argument is not needed. |
|
4901 |
*/ |
|
4902 |
public static abstract class SimpleVisitor<R,S> extends DefaultTypeVisitor<R,S> { |
|
4903 |
@Override |
|
4904 |
public R visitCapturedType(CapturedType t, S s) { |
|
4905 |
return visitTypeVar(t, s); |
|
4906 |
} |
|
4907 |
@Override |
|
4908 |
public R visitForAll(ForAll t, S s) { |
|
4909 |
return visit(t.qtype, s); |
|
4910 |
} |
|
4911 |
@Override |
|
4912 |
public R visitUndetVar(UndetVar t, S s) { |
|
4913 |
return visit(t.qtype, s); |
|
4914 |
} |
|
4915 |
} |
|
4916 |
||
4917 |
/** |
|
4918 |
* A plain relation on types. That is a 2-ary function on the |
|
4919 |
* form Type × Type → Boolean. |
|
4920 |
* <!-- In plain text: Type x Type -> Boolean --> |
|
4921 |
*/ |
|
4922 |
public static abstract class TypeRelation extends SimpleVisitor<Boolean,Type> {} |
|
4923 |
||
4924 |
/** |
|
4925 |
* A convenience visitor for implementing operations that only |
|
4926 |
* require one argument (the type itself), that is, unary |
|
4927 |
* operations. |
|
4928 |
* |
|
4929 |
* @param <R> the return type of the operation implemented by this |
|
4930 |
* visitor; use Void if no return type is needed. |
|
4931 |
*/ |
|
4932 |
public static abstract class UnaryVisitor<R> extends SimpleVisitor<R,Void> { |
|
4933 |
final public R visit(Type t) { return t.accept(this, null); } |
|
4934 |
} |
|
4935 |
||
4936 |
/** |
|
4937 |
* A visitor for implementing a mapping from types to types. The |
|
4938 |
* default behavior of this class is to implement the identity |
|
4939 |
* mapping (mapping a type to itself). This can be overridden in |
|
4940 |
* subclasses. |
|
4941 |
* |
|
4942 |
* @param <S> the type of the second argument (the first being the |
|
4943 |
* type itself) of this mapping; use Void if a second argument is |
|
4944 |
* not needed. |
|
4945 |
*/ |
|
4946 |
public static class MapVisitor<S> extends DefaultTypeVisitor<Type,S> { |
|
4947 |
final public Type visit(Type t) { return t.accept(this, null); } |
|
4948 |
public Type visitType(Type t, S s) { return t; } |
|
4949 |
} |
|
44186
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4950 |
|
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4951 |
/** |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4952 |
* An abstract class for mappings from types to types (see {@link Type#map(TypeMapping)}. |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4953 |
* This class implements the functional interface {@code Function}, that allows it to be used |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4954 |
* fluently in stream-like processing. |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4955 |
*/ |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4956 |
public static class TypeMapping<S> extends MapVisitor<S> implements Function<Type, Type> { |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4957 |
@Override |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4958 |
public Type apply(Type type) { return visit(type); } |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4959 |
|
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4960 |
List<Type> visit(List<Type> ts, S s) { |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4961 |
return ts.map(t -> visit(t, s)); |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4962 |
} |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4963 |
|
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4964 |
@Override |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4965 |
public Type visitCapturedType(CapturedType t, S s) { |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4966 |
return visitTypeVar(t, s); |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4967 |
} |
fe848a208b20
8176265: Method overload resolution on a covariant base type doesn't work in 9
mcimadamore
parents:
43025
diff
changeset
|
4968 |
} |
10 | 4969 |
// </editor-fold> |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4970 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4971 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4972 |
// <editor-fold defaultstate="collapsed" desc="Annotation support"> |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4973 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4974 |
public RetentionPolicy getRetention(Attribute.Compound a) { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
4975 |
return getRetention(a.type.tsym); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
4976 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
4977 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29555
diff
changeset
|
4978 |
public RetentionPolicy getRetention(TypeSymbol sym) { |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4979 |
RetentionPolicy vis = RetentionPolicy.CLASS; // the default |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13633
diff
changeset
|
4980 |
Attribute.Compound c = sym.attribute(syms.retentionType.tsym); |
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4981 |
if (c != null) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4982 |
Attribute value = c.member(names.value); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4983 |
if (value != null && value instanceof Attribute.Enum) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4984 |
Name levelName = ((Attribute.Enum)value).value.name; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4985 |
if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4986 |
else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4987 |
else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4988 |
else ;// /* fail soft */ throw new AssertionError(levelName); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4989 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4990 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4991 |
return vis; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4992 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
4993 |
// </editor-fold> |
16300 | 4994 |
|
4995 |
// <editor-fold defaultstate="collapsed" desc="Signature Generation"> |
|
4996 |
||
4997 |
public static abstract class SignatureGenerator { |
|
4998 |
||
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
4999 |
public static class InvalidSignatureException extends RuntimeException { |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5000 |
private static final long serialVersionUID = 0; |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5001 |
|
58350
e23e560afbcb
8231414: Mark various instance fields of javac internal types as transient
darcy
parents:
54952
diff
changeset
|
5002 |
private final transient Type type; |
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5003 |
|
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5004 |
InvalidSignatureException(Type type) { |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5005 |
this.type = type; |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5006 |
} |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5007 |
|
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5008 |
public Type type() { |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5009 |
return type; |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5010 |
} |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5011 |
} |
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5012 |
|
16300 | 5013 |
private final Types types; |
5014 |
||
5015 |
protected abstract void append(char ch); |
|
5016 |
protected abstract void append(byte[] ba); |
|
5017 |
protected abstract void append(Name name); |
|
5018 |
protected void classReference(ClassSymbol c) { /* by default: no-op */ } |
|
5019 |
||
5020 |
protected SignatureGenerator(Types types) { |
|
5021 |
this.types = types; |
|
5022 |
} |
|
5023 |
||
51670
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5024 |
protected void reportIllegalSignature(Type t) { |
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5025 |
throw new InvalidSignatureException(t); |
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5026 |
} |
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5027 |
|
16300 | 5028 |
/** |
5029 |
* Assemble signature of given type in string buffer. |
|
5030 |
*/ |
|
5031 |
public void assembleSig(Type type) { |
|
5032 |
switch (type.getTag()) { |
|
5033 |
case BYTE: |
|
5034 |
append('B'); |
|
5035 |
break; |
|
5036 |
case SHORT: |
|
5037 |
append('S'); |
|
5038 |
break; |
|
5039 |
case CHAR: |
|
5040 |
append('C'); |
|
5041 |
break; |
|
5042 |
case INT: |
|
5043 |
append('I'); |
|
5044 |
break; |
|
5045 |
case LONG: |
|
5046 |
append('J'); |
|
5047 |
break; |
|
5048 |
case FLOAT: |
|
5049 |
append('F'); |
|
5050 |
break; |
|
5051 |
case DOUBLE: |
|
5052 |
append('D'); |
|
5053 |
break; |
|
5054 |
case BOOLEAN: |
|
5055 |
append('Z'); |
|
5056 |
break; |
|
5057 |
case VOID: |
|
5058 |
append('V'); |
|
5059 |
break; |
|
5060 |
case CLASS: |
|
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5061 |
if (type.isCompound()) { |
51670
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5062 |
reportIllegalSignature(type); |
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5063 |
} |
16300 | 5064 |
append('L'); |
5065 |
assembleClassSig(type); |
|
5066 |
append(';'); |
|
5067 |
break; |
|
5068 |
case ARRAY: |
|
5069 |
ArrayType at = (ArrayType) type; |
|
5070 |
append('['); |
|
5071 |
assembleSig(at.elemtype); |
|
5072 |
break; |
|
5073 |
case METHOD: |
|
5074 |
MethodType mt = (MethodType) type; |
|
5075 |
append('('); |
|
5076 |
assembleSig(mt.argtypes); |
|
5077 |
append(')'); |
|
5078 |
assembleSig(mt.restype); |
|
5079 |
if (hasTypeVar(mt.thrown)) { |
|
5080 |
for (List<Type> l = mt.thrown; l.nonEmpty(); l = l.tail) { |
|
5081 |
append('^'); |
|
5082 |
assembleSig(l.head); |
|
5083 |
} |
|
5084 |
} |
|
5085 |
break; |
|
5086 |
case WILDCARD: { |
|
5087 |
Type.WildcardType ta = (Type.WildcardType) type; |
|
5088 |
switch (ta.kind) { |
|
5089 |
case SUPER: |
|
5090 |
append('-'); |
|
5091 |
assembleSig(ta.type); |
|
5092 |
break; |
|
5093 |
case EXTENDS: |
|
5094 |
append('+'); |
|
5095 |
assembleSig(ta.type); |
|
5096 |
break; |
|
5097 |
case UNBOUND: |
|
5098 |
append('*'); |
|
5099 |
break; |
|
5100 |
default: |
|
5101 |
throw new AssertionError(ta.kind); |
|
5102 |
} |
|
5103 |
break; |
|
5104 |
} |
|
5105 |
case TYPEVAR: |
|
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5106 |
if (((TypeVar)type).isCaptured()) { |
51670
2dddc9394b49
8210495: compiler crashes because of illegal signature in otherwise legal code
mcimadamore
parents:
51047
diff
changeset
|
5107 |
reportIllegalSignature(type); |
50213
3085969bdf91
8203436: javac should fail early when emitting illegal signature attributes
mcimadamore
parents:
50181
diff
changeset
|
5108 |
} |
16300 | 5109 |
append('T'); |
5110 |
append(type.tsym.name); |
|
5111 |
append(';'); |
|
5112 |
break; |
|
5113 |
case FORALL: |
|
5114 |
Type.ForAll ft = (Type.ForAll) type; |
|
5115 |
assembleParamsSig(ft.tvars); |
|
5116 |
assembleSig(ft.qtype); |
|
5117 |
break; |
|
5118 |
default: |
|
5119 |
throw new AssertionError("typeSig " + type.getTag()); |
|
5120 |
} |
|
5121 |
} |
|
5122 |
||
5123 |
public boolean hasTypeVar(List<Type> l) { |
|
5124 |
while (l.nonEmpty()) { |
|
5125 |
if (l.head.hasTag(TypeTag.TYPEVAR)) { |
|
5126 |
return true; |
|
5127 |
} |
|
5128 |
l = l.tail; |
|
5129 |
} |
|
5130 |
return false; |
|
5131 |
} |
|
5132 |
||
5133 |
public void assembleClassSig(Type type) { |
|
5134 |
ClassType ct = (ClassType) type; |
|
5135 |
ClassSymbol c = (ClassSymbol) ct.tsym; |
|
5136 |
classReference(c); |
|
5137 |
Type outer = ct.getEnclosingType(); |
|
5138 |
if (outer.allparams().nonEmpty()) { |
|
5139 |
boolean rawOuter = |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27125
diff
changeset
|
5140 |
c.owner.kind == MTH || // either a local class |
16300 | 5141 |
c.name == types.names.empty; // or anonymous |
5142 |
assembleClassSig(rawOuter |
|
5143 |
? types.erasure(outer) |
|
5144 |
: outer); |
|
24647
4435712075de
8037934: Javac generates invalid signatures for local types
pgovereau
parents:
24612
diff
changeset
|
5145 |
append(rawOuter ? '$' : '.'); |
16300 | 5146 |
Assert.check(c.flatname.startsWith(c.owner.enclClass().flatname)); |
5147 |
append(rawOuter |
|
5148 |
? c.flatname.subName(c.owner.enclClass().flatname.getByteLength() + 1, c.flatname.getByteLength()) |
|
5149 |
: c.name); |
|
5150 |
} else { |
|
5151 |
append(externalize(c.flatname)); |
|
5152 |
} |
|
5153 |
if (ct.getTypeArguments().nonEmpty()) { |
|
5154 |
append('<'); |
|
5155 |
assembleSig(ct.getTypeArguments()); |
|
5156 |
append('>'); |
|
5157 |
} |
|
5158 |
} |
|
5159 |
||
5160 |
public void assembleParamsSig(List<Type> typarams) { |
|
5161 |
append('<'); |
|
5162 |
for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) { |
|
5163 |
Type.TypeVar tvar = (Type.TypeVar) ts.head; |
|
5164 |
append(tvar.tsym.name); |
|
5165 |
List<Type> bounds = types.getBounds(tvar); |
|
5166 |
if ((bounds.head.tsym.flags() & INTERFACE) != 0) { |
|
5167 |
append(':'); |
|
5168 |
} |
|
5169 |
for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) { |
|
5170 |
append(':'); |
|
5171 |
assembleSig(l.head); |
|
5172 |
} |
|
5173 |
} |
|
5174 |
append('>'); |
|
5175 |
} |
|
5176 |
||
5177 |
private void assembleSig(List<Type> types) { |
|
5178 |
for (List<Type> ts = types; ts.nonEmpty(); ts = ts.tail) { |
|
5179 |
assembleSig(ts.head); |
|
5180 |
} |
|
5181 |
} |
|
5182 |
} |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5183 |
|
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5184 |
public Type constantType(LoadableConstant c) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5185 |
switch (c.poolTag()) { |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5186 |
case ClassFile.CONSTANT_Class: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5187 |
return syms.classType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5188 |
case ClassFile.CONSTANT_String: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5189 |
return syms.stringType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5190 |
case ClassFile.CONSTANT_Integer: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5191 |
return syms.intType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5192 |
case ClassFile.CONSTANT_Float: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5193 |
return syms.floatType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5194 |
case ClassFile.CONSTANT_Long: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5195 |
return syms.longType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5196 |
case ClassFile.CONSTANT_Double: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5197 |
return syms.doubleType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5198 |
case ClassFile.CONSTANT_MethodHandle: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5199 |
return syms.methodHandleType; |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5200 |
case ClassFile.CONSTANT_MethodType: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5201 |
return syms.methodTypeType; |
54762 | 5202 |
case ClassFile.CONSTANT_Dynamic: |
5203 |
return ((DynamicVarSymbol)c).type; |
|
54568
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5204 |
default: |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5205 |
throw new AssertionError("Not a loadable constant: " + c.poolTag()); |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5206 |
} |
b2ed96c35687
8222289: Overhaul logic for reading/writing constant pool entries
mcimadamore
parents:
53515
diff
changeset
|
5207 |
} |
16300 | 5208 |
// </editor-fold> |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5209 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5210 |
public void newRound() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5211 |
descCache._map.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5212 |
isDerivedRawCache.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5213 |
implCache._map.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5214 |
membersCache._map.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5215 |
closureCache.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23399
diff
changeset
|
5216 |
} |
10 | 5217 |
} |