author | jjg |
Mon, 21 Jan 2013 01:27:42 -0500 | |
changeset 15724 | 3063fb01c8a1 |
parent 14953 | 89a34297b198 |
child 15725 | e0516b913894 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, 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.comp; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
import java.util.Set; |
|
30 |
||
31 |
import javax.lang.model.element.ElementKind; |
|
32 |
import javax.tools.JavaFileObject; |
|
10 | 33 |
|
34 |
import com.sun.source.tree.IdentifierTree; |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
35 |
import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
10 | 36 |
import com.sun.source.tree.MemberSelectTree; |
37 |
import com.sun.source.tree.TreeVisitor; |
|
38 |
import com.sun.source.util.SimpleTreeVisitor; |
|
14258 | 39 |
import com.sun.tools.javac.code.*; |
40 |
import com.sun.tools.javac.code.Lint.LintCategory; |
|
41 |
import com.sun.tools.javac.code.Symbol.*; |
|
42 |
import com.sun.tools.javac.code.Type.*; |
|
43 |
import com.sun.tools.javac.comp.Check.CheckContext; |
|
44 |
import com.sun.tools.javac.comp.DeferredAttr.AttrMode; |
|
45 |
import com.sun.tools.javac.comp.Infer.InferenceContext; |
|
46 |
import com.sun.tools.javac.comp.Infer.InferenceContext.FreeTypeListener; |
|
47 |
import com.sun.tools.javac.jvm.*; |
|
48 |
import com.sun.tools.javac.jvm.Target; |
|
49 |
import com.sun.tools.javac.tree.*; |
|
50 |
import com.sun.tools.javac.tree.JCTree.*; |
|
51 |
import com.sun.tools.javac.util.*; |
|
52 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
53 |
import com.sun.tools.javac.util.List; |
|
10 | 54 |
import static com.sun.tools.javac.code.Flags.*; |
10950 | 55 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
56 |
import static com.sun.tools.javac.code.Flags.BLOCK; |
|
10 | 57 |
import static com.sun.tools.javac.code.Kinds.*; |
10950 | 58 |
import static com.sun.tools.javac.code.Kinds.ERRONEOUS; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
59 |
import static com.sun.tools.javac.code.TypeTag.*; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
60 |
import static com.sun.tools.javac.code.TypeTag.WILDCARD; |
10950 | 61 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
10 | 62 |
|
63 |
/** This is the main context-dependent analysis phase in GJC. It |
|
64 |
* encompasses name resolution, type checking and constant folding as |
|
65 |
* subtasks. Some subtasks involve auxiliary classes. |
|
66 |
* @see Check |
|
67 |
* @see Resolve |
|
68 |
* @see ConstFold |
|
69 |
* @see Infer |
|
70 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
71 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
72 |
* If you write code that depends on this, you do so at your own risk. |
10 | 73 |
* This code and its internal interfaces are subject to change or |
74 |
* deletion without notice.</b> |
|
75 |
*/ |
|
76 |
public class Attr extends JCTree.Visitor { |
|
77 |
protected static final Context.Key<Attr> attrKey = |
|
78 |
new Context.Key<Attr>(); |
|
79 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
80 |
final Names names; |
10 | 81 |
final Log log; |
82 |
final Symtab syms; |
|
83 |
final Resolve rs; |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
84 |
final Infer infer; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
85 |
final DeferredAttr deferredAttr; |
10 | 86 |
final Check chk; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
87 |
final Flow flow; |
10 | 88 |
final MemberEnter memberEnter; |
89 |
final TreeMaker make; |
|
90 |
final ConstFold cfolder; |
|
91 |
final Enter enter; |
|
92 |
final Target target; |
|
93 |
final Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
94 |
final JCDiagnostic.Factory diags; |
10 | 95 |
final Annotate annotate; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
96 |
final DeferredLintHandler deferredLintHandler; |
10 | 97 |
|
98 |
public static Attr instance(Context context) { |
|
99 |
Attr instance = context.get(attrKey); |
|
100 |
if (instance == null) |
|
101 |
instance = new Attr(context); |
|
102 |
return instance; |
|
103 |
} |
|
104 |
||
105 |
protected Attr(Context context) { |
|
106 |
context.put(attrKey, this); |
|
107 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
108 |
names = Names.instance(context); |
10 | 109 |
log = Log.instance(context); |
110 |
syms = Symtab.instance(context); |
|
111 |
rs = Resolve.instance(context); |
|
112 |
chk = Check.instance(context); |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
113 |
flow = Flow.instance(context); |
10 | 114 |
memberEnter = MemberEnter.instance(context); |
115 |
make = TreeMaker.instance(context); |
|
116 |
enter = Enter.instance(context); |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
117 |
infer = Infer.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
118 |
deferredAttr = DeferredAttr.instance(context); |
10 | 119 |
cfolder = ConstFold.instance(context); |
120 |
target = Target.instance(context); |
|
121 |
types = Types.instance(context); |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
122 |
diags = JCDiagnostic.Factory.instance(context); |
10 | 123 |
annotate = Annotate.instance(context); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
124 |
deferredLintHandler = DeferredLintHandler.instance(context); |
10 | 125 |
|
126 |
Options options = Options.instance(context); |
|
127 |
||
128 |
Source source = Source.instance(context); |
|
129 |
allowGenerics = source.allowGenerics(); |
|
130 |
allowVarargs = source.allowVarargs(); |
|
131 |
allowEnums = source.allowEnums(); |
|
132 |
allowBoxing = source.allowBoxing(); |
|
133 |
allowCovariantReturns = source.allowCovariantReturns(); |
|
134 |
allowAnonOuterThis = source.allowAnonOuterThis(); |
|
4142 | 135 |
allowStringsInSwitch = source.allowStringsInSwitch(); |
14547 | 136 |
allowPoly = source.allowPoly(); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
137 |
allowLambda = source.allowLambda(); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
138 |
allowDefaultMethods = source.allowDefaultMethods(); |
4142 | 139 |
sourceName = source.name; |
6721 | 140 |
relax = (options.isSet("-retrofit") || |
141 |
options.isSet("-relax")); |
|
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
142 |
findDiamonds = options.get("findDiamond") != null && |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
143 |
source.allowDiamond(); |
6721 | 144 |
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
145 |
identifyLambdaCandidate = options.getBoolean("identifyLambdaCandidate", false); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
146 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
147 |
statInfo = new ResultInfo(NIL, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
148 |
varInfo = new ResultInfo(VAR, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
149 |
unknownExprInfo = new ResultInfo(VAL, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
150 |
unknownTypeInfo = new ResultInfo(TYP, Type.noType); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
151 |
recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); |
10 | 152 |
} |
153 |
||
154 |
/** Switch: relax some constraints for retrofit mode. |
|
155 |
*/ |
|
156 |
boolean relax; |
|
157 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
158 |
/** Switch: support target-typing inference |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
159 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
160 |
boolean allowPoly; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
161 |
|
10 | 162 |
/** Switch: support generics? |
163 |
*/ |
|
164 |
boolean allowGenerics; |
|
165 |
||
166 |
/** Switch: allow variable-arity methods. |
|
167 |
*/ |
|
168 |
boolean allowVarargs; |
|
169 |
||
170 |
/** Switch: support enums? |
|
171 |
*/ |
|
172 |
boolean allowEnums; |
|
173 |
||
174 |
/** Switch: support boxing and unboxing? |
|
175 |
*/ |
|
176 |
boolean allowBoxing; |
|
177 |
||
178 |
/** Switch: support covariant result types? |
|
179 |
*/ |
|
180 |
boolean allowCovariantReturns; |
|
181 |
||
14547 | 182 |
/** Switch: support lambda expressions ? |
183 |
*/ |
|
184 |
boolean allowLambda; |
|
185 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
186 |
/** Switch: support default methods ? |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
187 |
*/ |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
188 |
boolean allowDefaultMethods; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
189 |
|
10 | 190 |
/** Switch: allow references to surrounding object from anonymous |
191 |
* objects during constructor call? |
|
192 |
*/ |
|
193 |
boolean allowAnonOuterThis; |
|
194 |
||
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
195 |
/** Switch: generates a warning if diamond can be safely applied |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
196 |
* to a given new expression |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
197 |
*/ |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
198 |
boolean findDiamonds; |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
199 |
|
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
200 |
/** |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
201 |
* Internally enables/disables diamond finder feature |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
202 |
*/ |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
203 |
static final boolean allowDiamondFinder = true; |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
204 |
|
10 | 205 |
/** |
206 |
* Switch: warn about use of variable before declaration? |
|
207 |
* RFE: 6425594 |
|
208 |
*/ |
|
209 |
boolean useBeforeDeclarationWarning; |
|
210 |
||
3661 | 211 |
/** |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
212 |
* Switch: generate warnings whenever an anonymous inner class that is convertible |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
213 |
* to a lambda expression is found |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
214 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
215 |
boolean identifyLambdaCandidate; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
216 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
217 |
/** |
4142 | 218 |
* Switch: allow strings in switch? |
219 |
*/ |
|
220 |
boolean allowStringsInSwitch; |
|
221 |
||
222 |
/** |
|
223 |
* Switch: name of source level; used for error reporting. |
|
224 |
*/ |
|
225 |
String sourceName; |
|
226 |
||
10 | 227 |
/** Check kind and type of given tree against protokind and prototype. |
228 |
* If check succeeds, store type in tree and return it. |
|
229 |
* If check fails, store errType in tree and return it. |
|
230 |
* No checks are performed if the prototype is a method type. |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
231 |
* It is not necessary in this case since we know that kind and type |
10 | 232 |
* are correct. |
233 |
* |
|
234 |
* @param tree The tree whose kind and type is checked |
|
235 |
* @param ownkind The computed kind of the tree |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
236 |
* @param resultInfo The expected result of the tree |
10 | 237 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
238 |
Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
239 |
InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
240 |
Type owntype = found; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
241 |
if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
242 |
if (inferenceContext.free(found)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
243 |
inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), new FreeTypeListener() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
244 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
245 |
public void typesInferred(InferenceContext inferenceContext) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
246 |
ResultInfo pendingResult = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
247 |
resultInfo.dup(inferenceContext.asInstType(resultInfo.pt, types)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
248 |
check(tree, inferenceContext.asInstType(found, types), ownkind, pendingResult); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
249 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
250 |
}); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
251 |
return tree.type = resultInfo.pt; |
10 | 252 |
} else { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
253 |
if ((ownkind & ~resultInfo.pkind) == 0) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
254 |
owntype = resultInfo.check(tree, owntype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
255 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
256 |
log.error(tree.pos(), "unexpected.type", |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
257 |
kindNames(resultInfo.pkind), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
258 |
kindName(ownkind)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
259 |
owntype = types.createErrorType(owntype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
260 |
} |
10 | 261 |
} |
262 |
} |
|
263 |
tree.type = owntype; |
|
264 |
return owntype; |
|
265 |
} |
|
266 |
||
267 |
/** Is given blank final variable assignable, i.e. in a scope where it |
|
268 |
* may be assigned to even though it is final? |
|
269 |
* @param v The blank final variable. |
|
270 |
* @param env The current environment. |
|
271 |
*/ |
|
272 |
boolean isAssignableAsBlankFinal(VarSymbol v, Env<AttrContext> env) { |
|
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
273 |
Symbol owner = owner(env); |
10 | 274 |
// owner refers to the innermost variable, method or |
275 |
// initializer block declaration at this point. |
|
276 |
return |
|
277 |
v.owner == owner |
|
278 |
|| |
|
279 |
((owner.name == names.init || // i.e. we are in a constructor |
|
280 |
owner.kind == VAR || // i.e. we are in a variable initializer |
|
281 |
(owner.flags() & BLOCK) != 0) // i.e. we are in an initializer block |
|
282 |
&& |
|
283 |
v.owner == owner.owner |
|
284 |
&& |
|
285 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env)); |
|
286 |
} |
|
287 |
||
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
288 |
/** |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
289 |
* Return the innermost enclosing owner symbol in a given attribution context |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
290 |
*/ |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
291 |
Symbol owner(Env<AttrContext> env) { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
292 |
while (true) { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
293 |
switch (env.tree.getTag()) { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
294 |
case VARDEF: |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
295 |
//a field can be owner |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
296 |
VarSymbol vsym = ((JCVariableDecl)env.tree).sym; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
297 |
if (vsym.owner.kind == TYP) { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
298 |
return vsym; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
299 |
} |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
300 |
break; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
301 |
case METHODDEF: |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
302 |
//method def is always an owner |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
303 |
return ((JCMethodDecl)env.tree).sym; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
304 |
case CLASSDEF: |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
305 |
//class def is always an owner |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
306 |
return ((JCClassDecl)env.tree).sym; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
307 |
case LAMBDA: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
308 |
//a lambda is an owner - return a fresh synthetic method symbol |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
309 |
return new MethodSymbol(0, names.empty, null, syms.methodClass); |
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
310 |
case BLOCK: |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
311 |
//static/instance init blocks are owner |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
312 |
Symbol blockSym = env.info.scope.owner; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
313 |
if ((blockSym.flags() & BLOCK) != 0) { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
314 |
return blockSym; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
315 |
} |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
316 |
break; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
317 |
case TOPLEVEL: |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
318 |
//toplevel is always an owner (for pkge decls) |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
319 |
return env.info.scope.owner; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
320 |
} |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
321 |
Assert.checkNonNull(env.next); |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
322 |
env = env.next; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
323 |
} |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
324 |
} |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
325 |
|
10 | 326 |
/** Check that variable can be assigned to. |
327 |
* @param pos The current source code position. |
|
328 |
* @param v The assigned varaible |
|
329 |
* @param base If the variable is referred to in a Select, the part |
|
330 |
* to the left of the `.', null otherwise. |
|
331 |
* @param env The current environment. |
|
332 |
*/ |
|
333 |
void checkAssignable(DiagnosticPosition pos, VarSymbol v, JCTree base, Env<AttrContext> env) { |
|
334 |
if ((v.flags() & FINAL) != 0 && |
|
335 |
((v.flags() & HASINIT) != 0 |
|
336 |
|| |
|
337 |
!((base == null || |
|
10950 | 338 |
(base.hasTag(IDENT) && TreeInfo.name(base) == names._this)) && |
10 | 339 |
isAssignableAsBlankFinal(v, env)))) { |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
340 |
if (v.isResourceVariable()) { //TWR resource |
7211
163fe60f63de
6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents:
7208
diff
changeset
|
341 |
log.error(pos, "try.resource.may.not.be.assigned", v); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
342 |
} else { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
343 |
log.error(pos, "cant.assign.val.to.final.var", v); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
344 |
} |
10 | 345 |
} |
346 |
} |
|
347 |
||
348 |
/** Does tree represent a static reference to an identifier? |
|
349 |
* It is assumed that tree is either a SELECT or an IDENT. |
|
350 |
* We have to weed out selects from non-type names here. |
|
351 |
* @param tree The candidate tree. |
|
352 |
*/ |
|
353 |
boolean isStaticReference(JCTree tree) { |
|
10950 | 354 |
if (tree.hasTag(SELECT)) { |
10 | 355 |
Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected); |
356 |
if (lsym == null || lsym.kind != TYP) { |
|
357 |
return false; |
|
358 |
} |
|
359 |
} |
|
360 |
return true; |
|
361 |
} |
|
362 |
||
363 |
/** Is this symbol a type? |
|
364 |
*/ |
|
365 |
static boolean isType(Symbol sym) { |
|
366 |
return sym != null && sym.kind == TYP; |
|
367 |
} |
|
368 |
||
369 |
/** The current `this' symbol. |
|
370 |
* @param env The current environment. |
|
371 |
*/ |
|
372 |
Symbol thisSym(DiagnosticPosition pos, Env<AttrContext> env) { |
|
373 |
return rs.resolveSelf(pos, env, env.enclClass.sym, names._this); |
|
374 |
} |
|
375 |
||
376 |
/** Attribute a parsed identifier. |
|
377 |
* @param tree Parsed identifier name |
|
378 |
* @param topLevel The toplevel to use |
|
379 |
*/ |
|
380 |
public Symbol attribIdent(JCTree tree, JCCompilationUnit topLevel) { |
|
381 |
Env<AttrContext> localEnv = enter.topLevelEnv(topLevel); |
|
382 |
localEnv.enclClass = make.ClassDef(make.Modifiers(0), |
|
383 |
syms.errSymbol.name, |
|
384 |
null, null, null, null); |
|
385 |
localEnv.enclClass.sym = syms.errSymbol; |
|
386 |
return tree.accept(identAttributer, localEnv); |
|
387 |
} |
|
388 |
// where |
|
389 |
private TreeVisitor<Symbol,Env<AttrContext>> identAttributer = new IdentAttributer(); |
|
390 |
private class IdentAttributer extends SimpleTreeVisitor<Symbol,Env<AttrContext>> { |
|
391 |
@Override |
|
392 |
public Symbol visitMemberSelect(MemberSelectTree node, Env<AttrContext> env) { |
|
393 |
Symbol site = visit(node.getExpression(), env); |
|
394 |
if (site.kind == ERR) |
|
395 |
return site; |
|
396 |
Name name = (Name)node.getIdentifier(); |
|
397 |
if (site.kind == PCK) { |
|
398 |
env.toplevel.packge = (PackageSymbol)site; |
|
399 |
return rs.findIdentInPackage(env, (TypeSymbol)site, name, TYP | PCK); |
|
400 |
} else { |
|
401 |
env.enclClass.sym = (ClassSymbol)site; |
|
402 |
return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
@Override |
|
407 |
public Symbol visitIdentifier(IdentifierTree node, Env<AttrContext> env) { |
|
408 |
return rs.findIdent(env, (Name)node.getName(), TYP | PCK); |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
public Type coerce(Type etype, Type ttype) { |
|
413 |
return cfolder.coerce(etype, ttype); |
|
414 |
} |
|
415 |
||
416 |
public Type attribType(JCTree node, TypeSymbol sym) { |
|
417 |
Env<AttrContext> env = enter.typeEnvs.get(sym); |
|
418 |
Env<AttrContext> localEnv = env.dup(node, env.info.dup()); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
419 |
return attribTree(node, localEnv, unknownTypeInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
420 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
421 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
422 |
public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
423 |
// Attribute qualifying package or class. |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
424 |
JCFieldAccess s = (JCFieldAccess)tree.qualid; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
425 |
return attribTree(s.selected, |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
426 |
env, |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
427 |
new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
428 |
Type.noType)); |
10 | 429 |
} |
430 |
||
431 |
public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) { |
|
432 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
433 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 434 |
try { |
435 |
attribExpr(expr, env); |
|
436 |
} catch (BreakAttr b) { |
|
437 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
438 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
439 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
440 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
441 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
442 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
443 |
} |
10 | 444 |
} finally { |
445 |
breakTree = null; |
|
446 |
log.useSource(prev); |
|
447 |
} |
|
448 |
return env; |
|
449 |
} |
|
450 |
||
451 |
public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) { |
|
452 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
453 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 454 |
try { |
455 |
attribStat(stmt, env); |
|
456 |
} catch (BreakAttr b) { |
|
457 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
458 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
459 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
460 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
461 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
462 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
463 |
} |
10 | 464 |
} finally { |
465 |
breakTree = null; |
|
466 |
log.useSource(prev); |
|
467 |
} |
|
468 |
return env; |
|
469 |
} |
|
470 |
||
471 |
private JCTree breakTree = null; |
|
472 |
||
473 |
private static class BreakAttr extends RuntimeException { |
|
474 |
static final long serialVersionUID = -6924771130405446405L; |
|
475 |
private Env<AttrContext> env; |
|
476 |
private BreakAttr(Env<AttrContext> env) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
477 |
this.env = copyEnv(env); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
478 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
479 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
480 |
private Env<AttrContext> copyEnv(Env<AttrContext> env) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
481 |
Env<AttrContext> newEnv = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
482 |
env.dup(env.tree, env.info.dup(copyScope(env.info.scope))); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
483 |
if (newEnv.outer != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
484 |
newEnv.outer = copyEnv(newEnv.outer); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
485 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
486 |
return newEnv; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
487 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
488 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
489 |
private Scope copyScope(Scope sc) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
490 |
Scope newScope = new Scope(sc.owner); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
491 |
List<Symbol> elemsList = List.nil(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
492 |
while (sc != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
493 |
for (Scope.Entry e = sc.elems ; e != null ; e = e.sibling) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
494 |
elemsList = elemsList.prepend(e.sym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
495 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
496 |
sc = sc.next; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
497 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
498 |
for (Symbol s : elemsList) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
499 |
newScope.enter(s); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
500 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
501 |
return newScope; |
10 | 502 |
} |
503 |
} |
|
504 |
||
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
505 |
class ResultInfo { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
506 |
final int pkind; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
507 |
final Type pt; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
508 |
final CheckContext checkContext; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
509 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
510 |
ResultInfo(int pkind, Type pt) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
511 |
this(pkind, pt, chk.basicHandler); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
512 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
513 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
514 |
protected ResultInfo(int pkind, Type pt, CheckContext checkContext) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
515 |
this.pkind = pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
516 |
this.pt = pt; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
517 |
this.checkContext = checkContext; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
518 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
519 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
520 |
protected Type check(final DiagnosticPosition pos, final Type found) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
521 |
return chk.checkType(pos, found, pt, checkContext); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
522 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
523 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
524 |
protected ResultInfo dup(Type newPt) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
525 |
return new ResultInfo(pkind, newPt, checkContext); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
526 |
} |
14547 | 527 |
|
528 |
protected ResultInfo dup(CheckContext newContext) { |
|
529 |
return new ResultInfo(pkind, pt, newContext); |
|
530 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
531 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
532 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
533 |
class RecoveryInfo extends ResultInfo { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
534 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
535 |
public RecoveryInfo(final DeferredAttr.DeferredAttrContext deferredAttrContext) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
536 |
super(Kinds.VAL, Type.recoveryType, new Check.NestedCheckContext(chk.basicHandler) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
537 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
538 |
public DeferredAttr.DeferredAttrContext deferredAttrContext() { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
539 |
return deferredAttrContext; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
540 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
541 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
542 |
public boolean compatible(Type found, Type req, Warner warn) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
543 |
return true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
544 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
545 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
546 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
14547 | 547 |
chk.basicHandler.report(pos, details); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
548 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
549 |
}); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
550 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
551 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
552 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
553 |
protected Type check(DiagnosticPosition pos, Type found) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
554 |
return chk.checkNonVoid(pos, super.check(pos, found)); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
555 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
556 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
557 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
558 |
final ResultInfo statInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
559 |
final ResultInfo varInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
560 |
final ResultInfo unknownExprInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
561 |
final ResultInfo unknownTypeInfo; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
562 |
final ResultInfo recoveryInfo; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
563 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
564 |
Type pt() { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
565 |
return resultInfo.pt; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
566 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
567 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
568 |
int pkind() { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
569 |
return resultInfo.pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
570 |
} |
10 | 571 |
|
572 |
/* ************************************************************************ |
|
573 |
* Visitor methods |
|
574 |
*************************************************************************/ |
|
575 |
||
576 |
/** Visitor argument: the current environment. |
|
577 |
*/ |
|
578 |
Env<AttrContext> env; |
|
579 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
580 |
/** Visitor argument: the currently expected attribution result. |
10 | 581 |
*/ |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
582 |
ResultInfo resultInfo; |
10 | 583 |
|
584 |
/** Visitor result: the computed type. |
|
585 |
*/ |
|
586 |
Type result; |
|
587 |
||
588 |
/** Visitor method: attribute a tree, catching any completion failure |
|
589 |
* exceptions. Return the tree's type. |
|
590 |
* |
|
591 |
* @param tree The tree to be visited. |
|
592 |
* @param env The environment visitor argument. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
593 |
* @param resultInfo The result info visitor argument. |
10 | 594 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
595 |
Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
10 | 596 |
Env<AttrContext> prevEnv = this.env; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
597 |
ResultInfo prevResult = this.resultInfo; |
10 | 598 |
try { |
599 |
this.env = env; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
600 |
this.resultInfo = resultInfo; |
10 | 601 |
tree.accept(this); |
14547 | 602 |
if (tree == breakTree && |
603 |
resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { |
|
10 | 604 |
throw new BreakAttr(env); |
14547 | 605 |
} |
10 | 606 |
return result; |
607 |
} catch (CompletionFailure ex) { |
|
608 |
tree.type = syms.errType; |
|
609 |
return chk.completionError(tree.pos(), ex); |
|
610 |
} finally { |
|
611 |
this.env = prevEnv; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
612 |
this.resultInfo = prevResult; |
10 | 613 |
} |
614 |
} |
|
615 |
||
616 |
/** Derived visitor method: attribute an expression tree. |
|
617 |
*/ |
|
618 |
public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
619 |
return attribTree(tree, env, new ResultInfo(VAL, !pt.hasTag(ERROR) ? pt : Type.noType)); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
620 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
621 |
|
10 | 622 |
/** Derived visitor method: attribute an expression tree with |
623 |
* no constraints on the computed type. |
|
624 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14538
diff
changeset
|
625 |
public Type attribExpr(JCTree tree, Env<AttrContext> env) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
626 |
return attribTree(tree, env, unknownExprInfo); |
10 | 627 |
} |
628 |
||
629 |
/** Derived visitor method: attribute a type tree. |
|
630 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14538
diff
changeset
|
631 |
public Type attribType(JCTree tree, Env<AttrContext> env) { |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
632 |
Type result = attribType(tree, env, Type.noType); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
633 |
return result; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
634 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
635 |
|
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
636 |
/** Derived visitor method: attribute a type tree. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
637 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
638 |
Type attribType(JCTree tree, Env<AttrContext> env, Type pt) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
639 |
Type result = attribTree(tree, env, new ResultInfo(TYP, pt)); |
10 | 640 |
return result; |
641 |
} |
|
642 |
||
643 |
/** Derived visitor method: attribute a statement or definition tree. |
|
644 |
*/ |
|
645 |
public Type attribStat(JCTree tree, Env<AttrContext> env) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
646 |
return attribTree(tree, env, statInfo); |
10 | 647 |
} |
648 |
||
649 |
/** Attribute a list of expressions, returning a list of types. |
|
650 |
*/ |
|
651 |
List<Type> attribExprs(List<JCExpression> trees, Env<AttrContext> env, Type pt) { |
|
652 |
ListBuffer<Type> ts = new ListBuffer<Type>(); |
|
653 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
|
654 |
ts.append(attribExpr(l.head, env, pt)); |
|
655 |
return ts.toList(); |
|
656 |
} |
|
657 |
||
658 |
/** Attribute a list of statements, returning nothing. |
|
659 |
*/ |
|
660 |
<T extends JCTree> void attribStats(List<T> trees, Env<AttrContext> env) { |
|
661 |
for (List<T> l = trees; l.nonEmpty(); l = l.tail) |
|
662 |
attribStat(l.head, env); |
|
663 |
} |
|
664 |
||
665 |
/** Attribute the arguments in a method call, returning a list of types. |
|
666 |
*/ |
|
667 |
List<Type> attribArgs(List<JCExpression> trees, Env<AttrContext> env) { |
|
668 |
ListBuffer<Type> argtypes = new ListBuffer<Type>(); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
669 |
for (JCExpression arg : trees) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
670 |
Type argtype = allowPoly && TreeInfo.isPoly(arg, env.tree) ? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
671 |
deferredAttr.new DeferredType(arg, env) : |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
672 |
chk.checkNonVoid(arg, attribExpr(arg, env, Infer.anyPoly)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
673 |
argtypes.append(argtype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
674 |
} |
10 | 675 |
return argtypes.toList(); |
676 |
} |
|
677 |
||
678 |
/** Attribute a type argument list, returning a list of types. |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
679 |
* Caller is responsible for calling checkRefTypes. |
10 | 680 |
*/ |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
681 |
List<Type> attribAnyTypes(List<JCExpression> trees, Env<AttrContext> env) { |
10 | 682 |
ListBuffer<Type> argtypes = new ListBuffer<Type>(); |
683 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
684 |
argtypes.append(attribType(l.head, env)); |
10 | 685 |
return argtypes.toList(); |
686 |
} |
|
687 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
688 |
/** Attribute a type argument list, returning a list of types. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
689 |
* Check that all the types are references. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
690 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
691 |
List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
692 |
List<Type> types = attribAnyTypes(trees, env); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
693 |
return chk.checkRefTypes(trees, types); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
694 |
} |
10 | 695 |
|
696 |
/** |
|
697 |
* Attribute type variables (of generic classes or methods). |
|
698 |
* Compound types are attributed later in attribBounds. |
|
699 |
* @param typarams the type variables to enter |
|
700 |
* @param env the current environment |
|
701 |
*/ |
|
702 |
void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env) { |
|
703 |
for (JCTypeParameter tvar : typarams) { |
|
704 |
TypeVar a = (TypeVar)tvar.type; |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
705 |
a.tsym.flags_field |= UNATTRIBUTED; |
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
706 |
a.bound = Type.noType; |
10 | 707 |
if (!tvar.bounds.isEmpty()) { |
708 |
List<Type> bounds = List.of(attribType(tvar.bounds.head, env)); |
|
709 |
for (JCExpression bound : tvar.bounds.tail) |
|
710 |
bounds = bounds.prepend(attribType(bound, env)); |
|
711 |
types.setBounds(a, bounds.reverse()); |
|
712 |
} else { |
|
713 |
// if no bounds are given, assume a single bound of |
|
714 |
// java.lang.Object. |
|
715 |
types.setBounds(a, List.of(syms.objectType)); |
|
716 |
} |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
717 |
a.tsym.flags_field &= ~UNATTRIBUTED; |
10 | 718 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
719 |
for (JCTypeParameter tvar : typarams) { |
10 | 720 |
chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type); |
721 |
} |
|
722 |
} |
|
723 |
||
724 |
/** |
|
725 |
* Attribute the type references in a list of annotations. |
|
726 |
*/ |
|
727 |
void attribAnnotationTypes(List<JCAnnotation> annotations, |
|
728 |
Env<AttrContext> env) { |
|
729 |
for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) { |
|
730 |
JCAnnotation a = al.head; |
|
731 |
attribType(a.annotationType, env); |
|
732 |
} |
|
733 |
} |
|
734 |
||
8225 | 735 |
/** |
736 |
* Attribute a "lazy constant value". |
|
737 |
* @param env The env for the const value |
|
738 |
* @param initializer The initializer for the const value |
|
739 |
* @param type The expected type, or null |
|
14259 | 740 |
* @see VarSymbol#setLazyConstValue |
8225 | 741 |
*/ |
742 |
public Object attribLazyConstantValue(Env<AttrContext> env, |
|
743 |
JCTree.JCExpression initializer, |
|
744 |
Type type) { |
|
745 |
||
746 |
// in case no lint value has been set up for this env, scan up |
|
747 |
// env stack looking for smallest enclosing env for which it is set. |
|
748 |
Env<AttrContext> lintEnv = env; |
|
749 |
while (lintEnv.info.lint == null) |
|
750 |
lintEnv = lintEnv.next; |
|
751 |
||
752 |
// Having found the enclosing lint value, we can initialize the lint value for this class |
|
10459
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
753 |
// ... but ... |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
754 |
// There's a problem with evaluating annotations in the right order, such that |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
755 |
// env.info.enclVar.attributes_field might not yet have been evaluated, and so might be |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
756 |
// null. In that case, calling augment will throw an NPE. To avoid this, for now we |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
757 |
// revert to the jdk 6 behavior and ignore the (unevaluated) attributes. |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
758 |
if (env.info.enclVar.annotations.pendingCompletion()) { |
10459
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
759 |
env.info.lint = lintEnv.info.lint; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
760 |
} else { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
761 |
env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.annotations, |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
762 |
env.info.enclVar.flags()); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
763 |
} |
8225 | 764 |
|
765 |
Lint prevLint = chk.setLint(env.info.lint); |
|
766 |
JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); |
|
767 |
||
768 |
try { |
|
769 |
Type itype = attribExpr(initializer, env, type); |
|
770 |
if (itype.constValue() != null) |
|
771 |
return coerce(itype, type).constValue(); |
|
772 |
else |
|
773 |
return null; |
|
774 |
} finally { |
|
775 |
env.info.lint = prevLint; |
|
776 |
log.useSource(prevSource); |
|
777 |
} |
|
778 |
} |
|
779 |
||
10 | 780 |
/** Attribute type reference in an `extends' or `implements' clause. |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
781 |
* Supertypes of anonymous inner classes are usually already attributed. |
10 | 782 |
* |
783 |
* @param tree The tree making up the type reference. |
|
784 |
* @param env The environment current at the reference. |
|
785 |
* @param classExpected true if only a class is expected here. |
|
786 |
* @param interfaceExpected true if only an interface is expected here. |
|
787 |
*/ |
|
788 |
Type attribBase(JCTree tree, |
|
789 |
Env<AttrContext> env, |
|
790 |
boolean classExpected, |
|
791 |
boolean interfaceExpected, |
|
792 |
boolean checkExtensible) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
793 |
Type t = tree.type != null ? |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
794 |
tree.type : |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
795 |
attribType(tree, env); |
10 | 796 |
return checkBase(t, tree, env, classExpected, interfaceExpected, checkExtensible); |
797 |
} |
|
798 |
Type checkBase(Type t, |
|
799 |
JCTree tree, |
|
800 |
Env<AttrContext> env, |
|
801 |
boolean classExpected, |
|
802 |
boolean interfaceExpected, |
|
803 |
boolean checkExtensible) { |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
804 |
if (t.isErroneous()) |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
805 |
return t; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
806 |
if (t.hasTag(TYPEVAR) && !classExpected && !interfaceExpected) { |
10 | 807 |
// check that type variable is already visible |
808 |
if (t.getUpperBound() == null) { |
|
809 |
log.error(tree.pos(), "illegal.forward.ref"); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
810 |
return types.createErrorType(t); |
10 | 811 |
} |
812 |
} else { |
|
813 |
t = chk.checkClassType(tree.pos(), t, checkExtensible|!allowGenerics); |
|
814 |
} |
|
815 |
if (interfaceExpected && (t.tsym.flags() & INTERFACE) == 0) { |
|
816 |
log.error(tree.pos(), "intf.expected.here"); |
|
817 |
// return errType is necessary since otherwise there might |
|
818 |
// be undetected cycles which cause attribution to loop |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
819 |
return types.createErrorType(t); |
10 | 820 |
} else if (checkExtensible && |
821 |
classExpected && |
|
822 |
(t.tsym.flags() & INTERFACE) != 0) { |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
823 |
log.error(tree.pos(), "no.intf.expected.here"); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
824 |
return types.createErrorType(t); |
10 | 825 |
} |
826 |
if (checkExtensible && |
|
827 |
((t.tsym.flags() & FINAL) != 0)) { |
|
828 |
log.error(tree.pos(), |
|
829 |
"cant.inherit.from.final", t.tsym); |
|
830 |
} |
|
831 |
chk.checkNonCyclic(tree.pos(), t); |
|
832 |
return t; |
|
833 |
} |
|
834 |
||
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
835 |
Type attribIdentAsEnumType(Env<AttrContext> env, JCIdent id) { |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
836 |
Assert.check((env.enclClass.sym.flags() & ENUM) != 0); |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
837 |
id.type = env.info.scope.owner.type; |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
838 |
id.sym = env.info.scope.owner; |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
839 |
return id.type; |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
840 |
} |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
841 |
|
10 | 842 |
public void visitClassDef(JCClassDecl tree) { |
843 |
// Local classes have not been entered yet, so we need to do it now: |
|
844 |
if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) |
|
845 |
enter.classEnter(tree, env); |
|
846 |
||
847 |
ClassSymbol c = tree.sym; |
|
848 |
if (c == null) { |
|
849 |
// exit in case something drastic went wrong during enter. |
|
850 |
result = null; |
|
851 |
} else { |
|
852 |
// make sure class has been completed: |
|
853 |
c.complete(); |
|
854 |
||
855 |
// If this class appears as an anonymous class |
|
856 |
// in a superclass constructor call where |
|
857 |
// no explicit outer instance is given, |
|
858 |
// disable implicit outer instance from being passed. |
|
859 |
// (This would be an illegal access to "this before super"). |
|
860 |
if (env.info.isSelfCall && |
|
10950 | 861 |
env.tree.hasTag(NEWCLASS) && |
10 | 862 |
((JCNewClass) env.tree).encl == null) |
863 |
{ |
|
864 |
c.flags_field |= NOOUTERTHIS; |
|
865 |
} |
|
866 |
attribClass(tree.pos(), c); |
|
867 |
result = tree.type = c.type; |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
public void visitMethodDef(JCMethodDecl tree) { |
|
872 |
MethodSymbol m = tree.sym; |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14259
diff
changeset
|
873 |
boolean isDefaultMethod = (m.flags() & DEFAULT) != 0; |
10 | 874 |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
875 |
Lint lint = env.info.lint.augment(m.annotations, m.flags()); |
10 | 876 |
Lint prevLint = chk.setLint(lint); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
877 |
MethodSymbol prevMethod = chk.setMethod(m); |
10 | 878 |
try { |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
879 |
deferredLintHandler.flush(tree.pos()); |
10 | 880 |
chk.checkDeprecatedAnnotation(tree.pos(), m); |
881 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
882 |
// Create a new environment with local scope |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
883 |
// for attributing the method. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
884 |
Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
885 |
localEnv.info.lint = lint; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
886 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
887 |
attribStats(tree.typarams, localEnv); |
10 | 888 |
|
889 |
// If we override any other methods, check that we do so properly. |
|
890 |
// JLS ??? |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
891 |
if (m.isStatic()) { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
892 |
chk.checkHideClashes(tree.pos(), env.enclClass.type, m); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
893 |
} else { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
894 |
chk.checkOverrideClashes(tree.pos(), env.enclClass.type, m); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
895 |
} |
10 | 896 |
chk.checkOverride(tree, m); |
897 |
||
14547 | 898 |
if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
899 |
log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
900 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
901 |
|
10 | 902 |
// Enter all type parameters into the local method scope. |
903 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
|
904 |
localEnv.info.scope.enterIfAbsent(l.head.type.tsym); |
|
905 |
||
906 |
ClassSymbol owner = env.enclClass.sym; |
|
907 |
if ((owner.flags() & ANNOTATION) != 0 && |
|
908 |
tree.params.nonEmpty()) |
|
909 |
log.error(tree.params.head.pos(), |
|
910 |
"intf.annotation.members.cant.have.params"); |
|
911 |
||
912 |
// Attribute all value parameters. |
|
913 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
|
914 |
attribStat(l.head, localEnv); |
|
915 |
} |
|
916 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
917 |
chk.checkVarargsMethodDecl(localEnv, tree); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5654
diff
changeset
|
918 |
|
10 | 919 |
// Check that type parameters are well-formed. |
1358 | 920 |
chk.validate(tree.typarams, localEnv); |
10 | 921 |
|
922 |
// Check that result type is well-formed. |
|
1358 | 923 |
chk.validate(tree.restype, localEnv); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
924 |
|
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
925 |
// annotation method checks |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
926 |
if ((owner.flags() & ANNOTATION) != 0) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
927 |
// annotation method cannot have throws clause |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
928 |
if (tree.thrown.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
929 |
log.error(tree.thrown.head.pos(), |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
930 |
"throws.not.allowed.in.intf.annotation"); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
931 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
932 |
// annotation method cannot declare type-parameters |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
933 |
if (tree.typarams.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
934 |
log.error(tree.typarams.head.pos(), |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
935 |
"intf.annotation.members.cant.have.type.params"); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
936 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
937 |
// validate annotation method's return type (could be an annotation type) |
10 | 938 |
chk.validateAnnotationType(tree.restype); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
939 |
// ensure that annotation method does not clash with members of Object/Annotation |
10 | 940 |
chk.validateAnnotationMethod(tree.pos(), m); |
941 |
||
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
942 |
if (tree.defaultValue != null) { |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
943 |
// if default value is an annotation, check it is a well-formed |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
944 |
// annotation value (e.g. no duplicate values, no missing values, etc.) |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
945 |
chk.validateAnnotationTree(tree.defaultValue); |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
946 |
} |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
947 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
948 |
|
10 | 949 |
for (List<JCExpression> l = tree.thrown; l.nonEmpty(); l = l.tail) |
950 |
chk.checkType(l.head.pos(), l.head.type, syms.throwableType); |
|
951 |
||
952 |
if (tree.body == null) { |
|
953 |
// Empty bodies are only allowed for |
|
954 |
// abstract, native, or interface methods, or for methods |
|
955 |
// in a retrofit signature class. |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14259
diff
changeset
|
956 |
if (isDefaultMethod || ((owner.flags() & INTERFACE) == 0 && |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14259
diff
changeset
|
957 |
(tree.mods.flags & (ABSTRACT | NATIVE)) == 0) && |
10 | 958 |
!relax) |
959 |
log.error(tree.pos(), "missing.meth.body.or.decl.abstract"); |
|
960 |
if (tree.defaultValue != null) { |
|
961 |
if ((owner.flags() & ANNOTATION) == 0) |
|
962 |
log.error(tree.pos(), |
|
963 |
"default.allowed.in.intf.annotation.member"); |
|
964 |
} |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
965 |
} else if ((tree.sym.flags() & ABSTRACT) != 0 && !isDefaultMethod) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
966 |
if ((owner.flags() & INTERFACE) != 0) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
967 |
log.error(tree.body.pos(), "intf.meth.cant.have.body"); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
968 |
} else { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
969 |
log.error(tree.pos(), "abstract.meth.cant.have.body"); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
970 |
} |
10 | 971 |
} else if ((tree.mods.flags & NATIVE) != 0) { |
972 |
log.error(tree.pos(), "native.meth.cant.have.body"); |
|
973 |
} else { |
|
974 |
// Add an implicit super() call unless an explicit call to |
|
975 |
// super(...) or this(...) is given |
|
976 |
// or we are compiling class java.lang.Object. |
|
977 |
if (tree.name == names.init && owner.type != syms.objectType) { |
|
978 |
JCBlock body = tree.body; |
|
979 |
if (body.stats.isEmpty() || |
|
980 |
!TreeInfo.isSelfCall(body.stats.head)) { |
|
981 |
body.stats = body.stats. |
|
982 |
prepend(memberEnter.SuperCall(make.at(body.pos), |
|
983 |
List.<Type>nil(), |
|
984 |
List.<JCVariableDecl>nil(), |
|
985 |
false)); |
|
986 |
} else if ((env.enclClass.sym.flags() & ENUM) != 0 && |
|
987 |
(tree.mods.flags & GENERATEDCONSTR) == 0 && |
|
988 |
TreeInfo.isSuperCall(body.stats.head)) { |
|
989 |
// enum constructors are not allowed to call super |
|
990 |
// directly, so make sure there aren't any super calls |
|
991 |
// in enum constructors, except in the compiler |
|
992 |
// generated one. |
|
993 |
log.error(tree.body.stats.head.pos(), |
|
994 |
"call.to.super.not.allowed.in.enum.ctor", |
|
995 |
env.enclClass.sym); |
|
996 |
} |
|
997 |
} |
|
998 |
||
999 |
// Attribute method body. |
|
1000 |
attribStat(tree.body, localEnv); |
|
1001 |
} |
|
1002 |
localEnv.info.scope.leave(); |
|
1003 |
result = tree.type = m.type; |
|
1004 |
chk.validateAnnotations(tree.mods.annotations, m); |
|
1005 |
} |
|
1006 |
finally { |
|
1007 |
chk.setLint(prevLint); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1008 |
chk.setMethod(prevMethod); |
10 | 1009 |
} |
1010 |
} |
|
1011 |
||
1012 |
public void visitVarDef(JCVariableDecl tree) { |
|
1013 |
// Local variables have not been entered yet, so we need to do it now: |
|
1014 |
if (env.info.scope.owner.kind == MTH) { |
|
1015 |
if (tree.sym != null) { |
|
1016 |
// parameters have already been entered |
|
1017 |
env.info.scope.enter(tree.sym); |
|
1018 |
} else { |
|
1019 |
memberEnter.memberEnter(tree, env); |
|
1020 |
annotate.flush(); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
||
1024 |
VarSymbol v = tree.sym; |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
1025 |
Lint lint = env.info.lint.augment(v.annotations, v.flags()); |
10 | 1026 |
Lint prevLint = chk.setLint(lint); |
1027 |
||
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
1028 |
// Check that the variable's declared type is well-formed. |
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
1029 |
chk.validate(tree.vartype, env); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
1030 |
deferredLintHandler.flush(tree.pos()); |
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
1031 |
|
10 | 1032 |
try { |
1033 |
chk.checkDeprecatedAnnotation(tree.pos(), v); |
|
1034 |
||
1035 |
if (tree.init != null) { |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1036 |
if ((v.flags_field & FINAL) != 0 && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1037 |
!tree.init.hasTag(NEWCLASS) && |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1038 |
!tree.init.hasTag(LAMBDA) && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1039 |
!tree.init.hasTag(REFERENCE)) { |
10 | 1040 |
// In this case, `v' is final. Ensure that it's initializer is |
1041 |
// evaluated. |
|
1042 |
v.getConstValue(); // ensure initializer is evaluated |
|
1043 |
} else { |
|
1044 |
// Attribute initializer in a new environment |
|
1045 |
// with the declared variable as owner. |
|
1046 |
// Check that initializer conforms to variable's declared type. |
|
1047 |
Env<AttrContext> initEnv = memberEnter.initEnv(tree, env); |
|
1048 |
initEnv.info.lint = lint; |
|
1049 |
// In order to catch self-references, we set the variable's |
|
1050 |
// declaration position to maximal possible value, effectively |
|
1051 |
// marking the variable as undefined. |
|
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
1052 |
initEnv.info.enclVar = v; |
10 | 1053 |
attribExpr(tree.init, initEnv, v.type); |
1054 |
} |
|
1055 |
} |
|
1056 |
result = tree.type = v.type; |
|
1057 |
chk.validateAnnotations(tree.mods.annotations, v); |
|
1058 |
} |
|
1059 |
finally { |
|
1060 |
chk.setLint(prevLint); |
|
1061 |
} |
|
1062 |
} |
|
1063 |
||
1064 |
public void visitSkip(JCSkip tree) { |
|
1065 |
result = null; |
|
1066 |
} |
|
1067 |
||
1068 |
public void visitBlock(JCBlock tree) { |
|
1069 |
if (env.info.scope.owner.kind == TYP) { |
|
1070 |
// Block is a static or instance initializer; |
|
1071 |
// let the owner of the environment be a freshly |
|
1072 |
// created BLOCK-method. |
|
1073 |
Env<AttrContext> localEnv = |
|
1074 |
env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); |
|
1075 |
localEnv.info.scope.owner = |
|
1076 |
new MethodSymbol(tree.flags | BLOCK, names.empty, null, |
|
1077 |
env.info.scope.owner); |
|
1078 |
if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; |
|
1079 |
attribStats(tree.stats, localEnv); |
|
1080 |
} else { |
|
1081 |
// Create a new local environment with a local scope. |
|
1082 |
Env<AttrContext> localEnv = |
|
1083 |
env.dup(tree, env.info.dup(env.info.scope.dup())); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1084 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1085 |
attribStats(tree.stats, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1086 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1087 |
localEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1088 |
} |
10 | 1089 |
} |
1090 |
result = null; |
|
1091 |
} |
|
1092 |
||
1093 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
1094 |
attribStat(tree.body, env.dup(tree)); |
|
1095 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1096 |
result = null; |
|
1097 |
} |
|
1098 |
||
1099 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
1100 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1101 |
attribStat(tree.body, env.dup(tree)); |
|
1102 |
result = null; |
|
1103 |
} |
|
1104 |
||
1105 |
public void visitForLoop(JCForLoop tree) { |
|
1106 |
Env<AttrContext> loopEnv = |
|
1107 |
env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1108 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1109 |
attribStats(tree.init, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1110 |
if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1111 |
loopEnv.tree = tree; // before, we were not in loop! |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1112 |
attribStats(tree.step, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1113 |
attribStat(tree.body, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1114 |
result = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1115 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1116 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1117 |
loopEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1118 |
} |
10 | 1119 |
} |
1120 |
||
1121 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
1122 |
Env<AttrContext> loopEnv = |
|
1123 |
env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1124 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1125 |
attribStat(tree.var, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1126 |
Type exprType = types.upperBound(attribExpr(tree.expr, loopEnv)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1127 |
chk.checkNonVoid(tree.pos(), exprType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1128 |
Type elemtype = types.elemtype(exprType); // perhaps expr is an array? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1129 |
if (elemtype == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1130 |
// or perhaps expr implements Iterable<T>? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1131 |
Type base = types.asSuper(exprType, syms.iterableType.tsym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1132 |
if (base == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1133 |
log.error(tree.expr.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1134 |
"foreach.not.applicable.to.type", |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1135 |
exprType, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1136 |
diags.fragment("type.req.array.or.iterable")); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1137 |
elemtype = types.createErrorType(exprType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1138 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1139 |
List<Type> iterableParams = base.allparams(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1140 |
elemtype = iterableParams.isEmpty() |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1141 |
? syms.objectType |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1142 |
: types.upperBound(iterableParams.head); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1143 |
} |
10 | 1144 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1145 |
chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1146 |
loopEnv.tree = tree; // before, we were not in loop! |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1147 |
attribStat(tree.body, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1148 |
result = null; |
10 | 1149 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1150 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1151 |
loopEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1152 |
} |
10 | 1153 |
} |
1154 |
||
1155 |
public void visitLabelled(JCLabeledStatement tree) { |
|
1156 |
// Check that label is not used in an enclosing statement |
|
1157 |
Env<AttrContext> env1 = env; |
|
10950 | 1158 |
while (env1 != null && !env1.tree.hasTag(CLASSDEF)) { |
1159 |
if (env1.tree.hasTag(LABELLED) && |
|
10 | 1160 |
((JCLabeledStatement) env1.tree).label == tree.label) { |
1161 |
log.error(tree.pos(), "label.already.in.use", |
|
1162 |
tree.label); |
|
1163 |
break; |
|
1164 |
} |
|
1165 |
env1 = env1.next; |
|
1166 |
} |
|
1167 |
||
1168 |
attribStat(tree.body, env.dup(tree)); |
|
1169 |
result = null; |
|
1170 |
} |
|
1171 |
||
1172 |
public void visitSwitch(JCSwitch tree) { |
|
1173 |
Type seltype = attribExpr(tree.selector, env); |
|
1174 |
||
1175 |
Env<AttrContext> switchEnv = |
|
1176 |
env.dup(tree, env.info.dup(env.info.scope.dup())); |
|
1177 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1178 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1179 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1180 |
boolean enumSwitch = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1181 |
allowEnums && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1182 |
(seltype.tsym.flags() & Flags.ENUM) != 0; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1183 |
boolean stringSwitch = false; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1184 |
if (types.isSameType(seltype, syms.stringType)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1185 |
if (allowStringsInSwitch) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1186 |
stringSwitch = true; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1187 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1188 |
log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1189 |
} |
4142 | 1190 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1191 |
if (!enumSwitch && !stringSwitch) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1192 |
seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1193 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1194 |
// Attribute all cases and |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1195 |
// check that there are no duplicate case labels or default clauses. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1196 |
Set<Object> labels = new HashSet<Object>(); // The set of case labels. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1197 |
boolean hasDefault = false; // Is there a default label? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1198 |
for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1199 |
JCCase c = l.head; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1200 |
Env<AttrContext> caseEnv = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1201 |
switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1202 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1203 |
if (c.pat != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1204 |
if (enumSwitch) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1205 |
Symbol sym = enumConstant(c.pat, seltype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1206 |
if (sym == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1207 |
log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum"); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1208 |
} else if (!labels.add(sym)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1209 |
log.error(c.pos(), "duplicate.case.label"); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1210 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1211 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1212 |
Type pattype = attribExpr(c.pat, switchEnv, seltype); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1213 |
if (!pattype.hasTag(ERROR)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1214 |
if (pattype.constValue() == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1215 |
log.error(c.pat.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1216 |
(stringSwitch ? "string.const.req" : "const.expr.req")); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1217 |
} else if (labels.contains(pattype.constValue())) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1218 |
log.error(c.pos(), "duplicate.case.label"); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1219 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1220 |
labels.add(pattype.constValue()); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1221 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1222 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1223 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1224 |
} else if (hasDefault) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1225 |
log.error(c.pos(), "duplicate.default.label"); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1226 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1227 |
hasDefault = true; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1228 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1229 |
attribStats(c.stats, caseEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1230 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1231 |
caseEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1232 |
addVars(c.stats, switchEnv.info.scope); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1233 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1234 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1235 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1236 |
result = null; |
4142 | 1237 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1238 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1239 |
switchEnv.info.scope.leave(); |
10 | 1240 |
} |
1241 |
} |
|
1242 |
// where |
|
1243 |
/** Add any variables defined in stats to the switch scope. */ |
|
1244 |
private static void addVars(List<JCStatement> stats, Scope switchScope) { |
|
1245 |
for (;stats.nonEmpty(); stats = stats.tail) { |
|
1246 |
JCTree stat = stats.head; |
|
10950 | 1247 |
if (stat.hasTag(VARDEF)) |
10 | 1248 |
switchScope.enter(((JCVariableDecl) stat).sym); |
1249 |
} |
|
1250 |
} |
|
1251 |
// where |
|
1252 |
/** Return the selected enumeration constant symbol, or null. */ |
|
1253 |
private Symbol enumConstant(JCTree tree, Type enumType) { |
|
10950 | 1254 |
if (!tree.hasTag(IDENT)) { |
10 | 1255 |
log.error(tree.pos(), "enum.label.must.be.unqualified.enum"); |
1256 |
return syms.errSymbol; |
|
1257 |
} |
|
1258 |
JCIdent ident = (JCIdent)tree; |
|
1259 |
Name name = ident.name; |
|
1260 |
for (Scope.Entry e = enumType.tsym.members().lookup(name); |
|
1261 |
e.scope != null; e = e.next()) { |
|
1262 |
if (e.sym.kind == VAR) { |
|
1263 |
Symbol s = ident.sym = e.sym; |
|
1264 |
((VarSymbol)s).getConstValue(); // ensure initializer is evaluated |
|
1265 |
ident.type = s.type; |
|
1266 |
return ((s.flags_field & Flags.ENUM) == 0) |
|
1267 |
? null : s; |
|
1268 |
} |
|
1269 |
} |
|
1270 |
return null; |
|
1271 |
} |
|
1272 |
||
1273 |
public void visitSynchronized(JCSynchronized tree) { |
|
1274 |
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); |
|
1275 |
attribStat(tree.body, env); |
|
1276 |
result = null; |
|
1277 |
} |
|
1278 |
||
1279 |
public void visitTry(JCTry tree) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1280 |
// Create a new local environment with a local |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1281 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup())); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1282 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1283 |
boolean isTryWithResource = tree.resources.nonEmpty(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1284 |
// Create a nested environment for attributing the try block if needed |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1285 |
Env<AttrContext> tryEnv = isTryWithResource ? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1286 |
env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1287 |
localEnv; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1288 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1289 |
// Attribute resource declarations |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1290 |
for (JCTree resource : tree.resources) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1291 |
CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1292 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1293 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1294 |
chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1295 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1296 |
}; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1297 |
ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1298 |
if (resource.hasTag(VARDEF)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1299 |
attribStat(resource, tryEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1300 |
twrResult.check(resource, resource.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1301 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1302 |
//check that resource type cannot throw InterruptedException |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1303 |
checkAutoCloseable(resource.pos(), localEnv, resource.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1304 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1305 |
VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1306 |
var.setData(ElementKind.RESOURCE_VARIABLE); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1307 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1308 |
attribTree(resource, tryEnv, twrResult); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1309 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1310 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1311 |
// Attribute body |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1312 |
attribStat(tree.body, tryEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1313 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1314 |
if (isTryWithResource) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1315 |
tryEnv.info.scope.leave(); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1316 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1317 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1318 |
// Attribute catch clauses |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1319 |
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1320 |
JCCatch c = l.head; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1321 |
Env<AttrContext> catchEnv = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1322 |
localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1323 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1324 |
Type ctype = attribStat(c.param, catchEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1325 |
if (TreeInfo.isMultiCatch(c)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1326 |
//multi-catch parameter is implicitly marked as final |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1327 |
c.param.sym.flags_field |= FINAL | UNION; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1328 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1329 |
if (c.param.sym.kind == Kinds.VAR) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1330 |
c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1331 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1332 |
chk.checkType(c.param.vartype.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1333 |
chk.checkClassType(c.param.vartype.pos(), ctype), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1334 |
syms.throwableType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1335 |
attribStat(c.body, catchEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1336 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1337 |
catchEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1338 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1339 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1340 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1341 |
// Attribute finalizer |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1342 |
if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1343 |
result = null; |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1344 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1345 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1346 |
localEnv.info.scope.leave(); |
10 | 1347 |
} |
1348 |
} |
|
1349 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1350 |
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1351 |
if (!resource.isErroneous() && |
12013
fdcc73079b81
7148025: javac should not warn about InterrupttedException on the declaration of AutoCloseable itself
darcy
parents:
11144
diff
changeset
|
1352 |
types.asSuper(resource, syms.autoCloseableType.tsym) != null && |
fdcc73079b81
7148025: javac should not warn about InterrupttedException on the declaration of AutoCloseable itself
darcy
parents:
11144
diff
changeset
|
1353 |
!types.isSameType(resource, syms.autoCloseableType)) { // Don't emit warning for AutoCloseable itself |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1354 |
Symbol close = syms.noSymbol; |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14443
diff
changeset
|
1355 |
Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1356 |
try { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1357 |
close = rs.resolveQualifiedMethod(pos, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1358 |
env, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1359 |
resource, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1360 |
names.close, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1361 |
List.<Type>nil(), |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1362 |
List.<Type>nil()); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1363 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1364 |
finally { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14443
diff
changeset
|
1365 |
log.popDiagnosticHandler(discardHandler); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1366 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1367 |
if (close.kind == MTH && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1368 |
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1369 |
chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1370 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1371 |
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1372 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1373 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1374 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1375 |
|
10 | 1376 |
public void visitConditional(JCConditional tree) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1377 |
Type condtype = attribExpr(tree.cond, env, syms.booleanType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1378 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1379 |
boolean standaloneConditional = !allowPoly || |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1380 |
pt().hasTag(NONE) && pt() != Type.recoveryType || |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1381 |
isBooleanOrNumeric(env, tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1382 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1383 |
if (!standaloneConditional && resultInfo.pt.hasTag(VOID)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1384 |
//cannot get here (i.e. it means we are returning from void method - which is already an error) |
14547 | 1385 |
resultInfo.checkContext.report(tree, diags.fragment("conditional.target.cant.be.void")); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1386 |
result = tree.type = types.createErrorType(resultInfo.pt); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1387 |
return; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1388 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1389 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1390 |
ResultInfo condInfo = standaloneConditional ? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1391 |
unknownExprInfo : |
14547 | 1392 |
resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1393 |
//this will use enclosing check context to check compatibility of |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1394 |
//subexpression against target type; if we are in a method check context, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1395 |
//depending on whether boxing is allowed, we could have incompatibilities |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1396 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1397 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1398 |
enclosingContext.report(pos, diags.fragment("incompatible.type.in.conditional", details)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1399 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1400 |
}); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1401 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1402 |
Type truetype = attribTree(tree.truepart, env, condInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1403 |
Type falsetype = attribTree(tree.falsepart, env, condInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1404 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1405 |
Type owntype = standaloneConditional ? condType(tree, truetype, falsetype) : pt(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1406 |
if (condtype.constValue() != null && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1407 |
truetype.constValue() != null && |
14953
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14725
diff
changeset
|
1408 |
falsetype.constValue() != null && |
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14725
diff
changeset
|
1409 |
!owntype.hasTag(NONE)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1410 |
//constant folding |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1411 |
owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1412 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1413 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 1414 |
} |
1415 |
//where |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1416 |
private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1417 |
switch (tree.getTag()) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1418 |
case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
14547 | 1419 |
((JCLiteral)tree).typetag == BOOLEAN || |
1420 |
((JCLiteral)tree).typetag == BOT; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1421 |
case LAMBDA: case REFERENCE: return false; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1422 |
case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1423 |
case CONDEXPR: |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1424 |
JCConditional condTree = (JCConditional)tree; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1425 |
return isBooleanOrNumeric(env, condTree.truepart) && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1426 |
isBooleanOrNumeric(env, condTree.falsepart); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1427 |
default: |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1428 |
Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1429 |
speculativeType = types.unboxedTypeOrType(speculativeType); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1430 |
return speculativeType.isPrimitive(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1431 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1432 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1433 |
|
10 | 1434 |
/** Compute the type of a conditional expression, after |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1435 |
* checking that it exists. See JLS 15.25. Does not take into |
10 | 1436 |
* account the special case where condition and both arms |
1437 |
* are constants. |
|
1438 |
* |
|
1439 |
* @param pos The source position to be used for error |
|
1440 |
* diagnostics. |
|
1441 |
* @param thentype The type of the expression's then-part. |
|
1442 |
* @param elsetype The type of the expression's else-part. |
|
1443 |
*/ |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1444 |
private Type condType(DiagnosticPosition pos, |
10 | 1445 |
Type thentype, Type elsetype) { |
1446 |
// If same type, that is the result |
|
1447 |
if (types.isSameType(thentype, elsetype)) |
|
1448 |
return thentype.baseType(); |
|
1449 |
||
1450 |
Type thenUnboxed = (!allowBoxing || thentype.isPrimitive()) |
|
1451 |
? thentype : types.unboxedType(thentype); |
|
1452 |
Type elseUnboxed = (!allowBoxing || elsetype.isPrimitive()) |
|
1453 |
? elsetype : types.unboxedType(elsetype); |
|
1454 |
||
1455 |
// Otherwise, if both arms can be converted to a numeric |
|
1456 |
// type, return the least numeric type that fits both arms |
|
1457 |
// (i.e. return larger of the two, or return int if one |
|
1458 |
// arm is short, the other is char). |
|
1459 |
if (thenUnboxed.isPrimitive() && elseUnboxed.isPrimitive()) { |
|
1460 |
// If one arm has an integer subrange type (i.e., byte, |
|
1461 |
// short, or char), and the other is an integer constant |
|
1462 |
// that fits into the subrange, return the subrange type. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1463 |
if (thenUnboxed.getTag().isStrictSubRangeOf(INT) && elseUnboxed.hasTag(INT) && |
10 | 1464 |
types.isAssignable(elseUnboxed, thenUnboxed)) |
1465 |
return thenUnboxed.baseType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1466 |
if (elseUnboxed.getTag().isStrictSubRangeOf(INT) && thenUnboxed.hasTag(INT) && |
10 | 1467 |
types.isAssignable(thenUnboxed, elseUnboxed)) |
1468 |
return elseUnboxed.baseType(); |
|
1469 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1470 |
for (TypeTag tag : TypeTag.values()) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1471 |
if (tag.ordinal() >= TypeTag.getTypeTagCount()) break; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1472 |
Type candidate = syms.typeOfTag[tag.ordinal()]; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1473 |
if (candidate != null && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1474 |
candidate.isPrimitive() && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1475 |
types.isSubtype(thenUnboxed, candidate) && |
10 | 1476 |
types.isSubtype(elseUnboxed, candidate)) |
1477 |
return candidate; |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
// Those were all the cases that could result in a primitive |
|
1482 |
if (allowBoxing) { |
|
1483 |
if (thentype.isPrimitive()) |
|
1484 |
thentype = types.boxedClass(thentype).type; |
|
1485 |
if (elsetype.isPrimitive()) |
|
1486 |
elsetype = types.boxedClass(elsetype).type; |
|
1487 |
} |
|
1488 |
||
1489 |
if (types.isSubtype(thentype, elsetype)) |
|
1490 |
return elsetype.baseType(); |
|
1491 |
if (types.isSubtype(elsetype, thentype)) |
|
1492 |
return thentype.baseType(); |
|
1493 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1494 |
if (!allowBoxing || thentype.hasTag(VOID) || elsetype.hasTag(VOID)) { |
10 | 1495 |
log.error(pos, "neither.conditional.subtype", |
1496 |
thentype, elsetype); |
|
1497 |
return thentype.baseType(); |
|
1498 |
} |
|
1499 |
||
1500 |
// both are known to be reference types. The result is |
|
1501 |
// lub(thentype,elsetype). This cannot fail, as it will |
|
1502 |
// always be possible to infer "Object" if nothing better. |
|
1503 |
return types.lub(thentype.baseType(), elsetype.baseType()); |
|
1504 |
} |
|
1505 |
||
1506 |
public void visitIf(JCIf tree) { |
|
1507 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1508 |
attribStat(tree.thenpart, env); |
|
1509 |
if (tree.elsepart != null) |
|
1510 |
attribStat(tree.elsepart, env); |
|
1511 |
chk.checkEmptyIf(tree); |
|
1512 |
result = null; |
|
1513 |
} |
|
1514 |
||
1515 |
public void visitExec(JCExpressionStatement tree) { |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1516 |
//a fresh environment is required for 292 inference to work properly --- |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1517 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1518 |
Env<AttrContext> localEnv = env.dup(tree); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1519 |
attribExpr(tree.expr, localEnv); |
10 | 1520 |
result = null; |
1521 |
} |
|
1522 |
||
1523 |
public void visitBreak(JCBreak tree) { |
|
1524 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1525 |
result = null; |
|
1526 |
} |
|
1527 |
||
1528 |
public void visitContinue(JCContinue tree) { |
|
1529 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1530 |
result = null; |
|
1531 |
} |
|
1532 |
//where |
|
1533 |
/** Return the target of a break or continue statement, if it exists, |
|
1534 |
* report an error if not. |
|
1535 |
* Note: The target of a labelled break or continue is the |
|
1536 |
* (non-labelled) statement tree referred to by the label, |
|
1537 |
* not the tree representing the labelled statement itself. |
|
1538 |
* |
|
1539 |
* @param pos The position to be used for error diagnostics |
|
1540 |
* @param tag The tag of the jump statement. This is either |
|
1541 |
* Tree.BREAK or Tree.CONTINUE. |
|
1542 |
* @param label The label of the jump statement, or null if no |
|
1543 |
* label is given. |
|
1544 |
* @param env The environment current at the jump statement. |
|
1545 |
*/ |
|
1546 |
private JCTree findJumpTarget(DiagnosticPosition pos, |
|
10950 | 1547 |
JCTree.Tag tag, |
10 | 1548 |
Name label, |
1549 |
Env<AttrContext> env) { |
|
1550 |
// Search environments outwards from the point of jump. |
|
1551 |
Env<AttrContext> env1 = env; |
|
1552 |
LOOP: |
|
1553 |
while (env1 != null) { |
|
1554 |
switch (env1.tree.getTag()) { |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1555 |
case LABELLED: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1556 |
JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1557 |
if (label == labelled.label) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1558 |
// If jump is a continue, check that target is a loop. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1559 |
if (tag == CONTINUE) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1560 |
if (!labelled.body.hasTag(DOLOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1561 |
!labelled.body.hasTag(WHILELOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1562 |
!labelled.body.hasTag(FORLOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1563 |
!labelled.body.hasTag(FOREACHLOOP)) |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1564 |
log.error(pos, "not.loop.label", label); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1565 |
// Found labelled statement target, now go inwards |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1566 |
// to next non-labelled tree. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1567 |
return TreeInfo.referencedStatement(labelled); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1568 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1569 |
return labelled; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1570 |
} |
10 | 1571 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1572 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1573 |
case DOLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1574 |
case WHILELOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1575 |
case FORLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1576 |
case FOREACHLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1577 |
if (label == null) return env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1578 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1579 |
case SWITCH: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1580 |
if (label == null && tag == BREAK) return env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1581 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1582 |
case LAMBDA: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1583 |
case METHODDEF: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1584 |
case CLASSDEF: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1585 |
break LOOP; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1586 |
default: |
10 | 1587 |
} |
1588 |
env1 = env1.next; |
|
1589 |
} |
|
1590 |
if (label != null) |
|
1591 |
log.error(pos, "undef.label", label); |
|
10950 | 1592 |
else if (tag == CONTINUE) |
10 | 1593 |
log.error(pos, "cont.outside.loop"); |
1594 |
else |
|
1595 |
log.error(pos, "break.outside.switch.loop"); |
|
1596 |
return null; |
|
1597 |
} |
|
1598 |
||
1599 |
public void visitReturn(JCReturn tree) { |
|
1600 |
// Check that there is an enclosing method which is |
|
1601 |
// nested within than the enclosing class. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1602 |
if (env.info.returnResult == null) { |
10 | 1603 |
log.error(tree.pos(), "ret.outside.meth"); |
1604 |
} else { |
|
1605 |
// Attribute return expression, if it exists, and check that |
|
1606 |
// it conforms to result type of enclosing method. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1607 |
if (tree.expr != null) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1608 |
if (env.info.returnResult.pt.hasTag(VOID)) { |
14547 | 1609 |
env.info.returnResult.checkContext.report(tree.expr.pos(), |
1610 |
diags.fragment("unexpected.ret.val")); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1611 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1612 |
attribTree(tree.expr, env, env.info.returnResult); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1613 |
} else if (!env.info.returnResult.pt.hasTag(VOID)) { |
14547 | 1614 |
env.info.returnResult.checkContext.report(tree.pos(), |
1615 |
diags.fragment("missing.ret.val")); |
|
10 | 1616 |
} |
1617 |
} |
|
1618 |
result = null; |
|
1619 |
} |
|
1620 |
||
1621 |
public void visitThrow(JCThrow tree) { |
|
14547 | 1622 |
Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType); |
1623 |
if (allowPoly) { |
|
1624 |
chk.checkType(tree, owntype, syms.throwableType); |
|
1625 |
} |
|
10 | 1626 |
result = null; |
1627 |
} |
|
1628 |
||
1629 |
public void visitAssert(JCAssert tree) { |
|
1630 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1631 |
if (tree.detail != null) { |
|
1632 |
chk.checkNonVoid(tree.detail.pos(), attribExpr(tree.detail, env)); |
|
1633 |
} |
|
1634 |
result = null; |
|
1635 |
} |
|
1636 |
||
1637 |
/** Visitor method for method invocations. |
|
1638 |
* NOTE: The method part of an application will have in its type field |
|
1639 |
* the return type of the method, not the method's type itself! |
|
1640 |
*/ |
|
1641 |
public void visitApply(JCMethodInvocation tree) { |
|
1642 |
// The local environment of a method application is |
|
1643 |
// a new environment nested in the current one. |
|
1644 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
1645 |
||
1646 |
// The types of the actual method arguments. |
|
1647 |
List<Type> argtypes; |
|
1648 |
||
1649 |
// The types of the actual method type arguments. |
|
1650 |
List<Type> typeargtypes = null; |
|
1651 |
||
1652 |
Name methName = TreeInfo.name(tree.meth); |
|
1653 |
||
1654 |
boolean isConstructorCall = |
|
1655 |
methName == names._this || methName == names._super; |
|
1656 |
||
1657 |
if (isConstructorCall) { |
|
1658 |
// We are seeing a ...this(...) or ...super(...) call. |
|
1659 |
// Check that this is the first statement in a constructor. |
|
1660 |
if (checkFirstConstructorStat(tree, env)) { |
|
1661 |
||
1662 |
// Record the fact |
|
1663 |
// that this is a constructor call (using isSelfCall). |
|
1664 |
localEnv.info.isSelfCall = true; |
|
1665 |
||
1666 |
// Attribute arguments, yielding list of argument types. |
|
1667 |
argtypes = attribArgs(tree.args, localEnv); |
|
1668 |
typeargtypes = attribTypes(tree.typeargs, localEnv); |
|
1669 |
||
1670 |
// Variable `site' points to the class in which the called |
|
1671 |
// constructor is defined. |
|
1672 |
Type site = env.enclClass.sym.type; |
|
1673 |
if (methName == names._super) { |
|
1674 |
if (site == syms.objectType) { |
|
1675 |
log.error(tree.meth.pos(), "no.superclass", site); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
1676 |
site = types.createErrorType(syms.objectType); |
10 | 1677 |
} else { |
1678 |
site = types.supertype(site); |
|
1679 |
} |
|
1680 |
} |
|
1681 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1682 |
if (site.hasTag(CLASS)) { |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1683 |
Type encl = site.getEnclosingType(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1684 |
while (encl != null && encl.hasTag(TYPEVAR)) |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1685 |
encl = encl.getUpperBound(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1686 |
if (encl.hasTag(CLASS)) { |
10 | 1687 |
// we are calling a nested class |
1688 |
||
10950 | 1689 |
if (tree.meth.hasTag(SELECT)) { |
10 | 1690 |
JCTree qualifier = ((JCFieldAccess) tree.meth).selected; |
1691 |
||
1692 |
// We are seeing a prefixed call, of the form |
|
1693 |
// <expr>.super(...). |
|
1694 |
// Check that the prefix expression conforms |
|
1695 |
// to the outer instance type of the class. |
|
1696 |
chk.checkRefType(qualifier.pos(), |
|
1697 |
attribExpr(qualifier, localEnv, |
|
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1698 |
encl)); |
10 | 1699 |
} else if (methName == names._super) { |
1700 |
// qualifier omitted; check for existence |
|
1701 |
// of an appropriate implicit qualifier. |
|
1702 |
rs.resolveImplicitThis(tree.meth.pos(), |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8616
diff
changeset
|
1703 |
localEnv, site, true); |
10 | 1704 |
} |
10950 | 1705 |
} else if (tree.meth.hasTag(SELECT)) { |
10 | 1706 |
log.error(tree.meth.pos(), "illegal.qual.not.icls", |
1707 |
site.tsym); |
|
1708 |
} |
|
1709 |
||
1710 |
// if we're calling a java.lang.Enum constructor, |
|
1711 |
// prefix the implicit String and int parameters |
|
1712 |
if (site.tsym == syms.enumSym && allowEnums) |
|
1713 |
argtypes = argtypes.prepend(syms.intType).prepend(syms.stringType); |
|
1714 |
||
1715 |
// Resolve the called constructor under the assumption |
|
1716 |
// that we are referring to a superclass instance of the |
|
1717 |
// current instance (JLS ???). |
|
1718 |
boolean selectSuperPrev = localEnv.info.selectSuper; |
|
1719 |
localEnv.info.selectSuper = true; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1720 |
localEnv.info.pendingResolutionPhase = null; |
10 | 1721 |
Symbol sym = rs.resolveConstructor( |
1722 |
tree.meth.pos(), localEnv, site, argtypes, typeargtypes); |
|
1723 |
localEnv.info.selectSuper = selectSuperPrev; |
|
1724 |
||
1725 |
// Set method symbol to resolved constructor... |
|
1726 |
TreeInfo.setSymbol(tree.meth, sym); |
|
1727 |
||
1728 |
// ...and check that it is legal in the current context. |
|
1729 |
// (this will also set the tree's type) |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
1730 |
Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1731 |
checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt)); |
10 | 1732 |
} |
1733 |
// Otherwise, `site' is an error type and we do nothing |
|
1734 |
} |
|
1735 |
result = tree.type = syms.voidType; |
|
1736 |
} else { |
|
1737 |
// Otherwise, we are seeing a regular method call. |
|
1738 |
// Attribute the arguments, yielding list of argument types, ... |
|
1739 |
argtypes = attribArgs(tree.args, localEnv); |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1740 |
typeargtypes = attribAnyTypes(tree.typeargs, localEnv); |
10 | 1741 |
|
1742 |
// ... and attribute the method using as a prototype a methodtype |
|
1743 |
// whose formal argument types is exactly the list of actual |
|
1744 |
// arguments (this will also set the method symbol). |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
1745 |
Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1746 |
localEnv.info.pendingResolutionPhase = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1747 |
Type mtype = attribTree(tree.meth, localEnv, new ResultInfo(VAL, mpt, resultInfo.checkContext)); |
10 | 1748 |
|
1749 |
// Compute the result type. |
|
1750 |
Type restype = mtype.getReturnType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1751 |
if (restype.hasTag(WILDCARD)) |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6594
diff
changeset
|
1752 |
throw new AssertionError(mtype); |
10 | 1753 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1754 |
Type qualifier = (tree.meth.hasTag(SELECT)) |
10 | 1755 |
? ((JCFieldAccess) tree.meth).selected.type |
1756 |
: env.enclClass.sym.type; |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1757 |
restype = adjustMethodReturnType(qualifier, methName, argtypes, restype); |
10 | 1758 |
|
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
1759 |
chk.checkRefTypes(tree.typeargs, typeargtypes); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1760 |
|
10 | 1761 |
// Check that value of resulting type is admissible in the |
1762 |
// current context. Also, capture the return type |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1763 |
result = check(tree, capture(restype), VAL, resultInfo); |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1764 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1765 |
if (localEnv.info.lastResolveVarargs()) |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1766 |
Assert.check(result.isErroneous() || tree.varargsElement != null); |
10 | 1767 |
} |
1358 | 1768 |
chk.validate(tree.typeargs, localEnv); |
10 | 1769 |
} |
1770 |
//where |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1771 |
Type adjustMethodReturnType(Type qualifierType, Name methodName, List<Type> argtypes, Type restype) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1772 |
if (allowCovariantReturns && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1773 |
methodName == names.clone && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1774 |
types.isArray(qualifierType)) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1775 |
// as a special case, array.clone() has a result that is |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1776 |
// the same as static type of the array being cloned |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1777 |
return qualifierType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1778 |
} else if (allowGenerics && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1779 |
methodName == names.getClass && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1780 |
argtypes.isEmpty()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1781 |
// as a special case, x.getClass() has type Class<? extends |X|> |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1782 |
return new ClassType(restype.getEnclosingType(), |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1783 |
List.<Type>of(new WildcardType(types.erasure(qualifierType), |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1784 |
BoundKind.EXTENDS, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1785 |
syms.boundClass)), |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1786 |
restype.tsym); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1787 |
} else { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1788 |
return restype; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1789 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1790 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1791 |
|
10 | 1792 |
/** Check that given application node appears as first statement |
1793 |
* in a constructor call. |
|
1794 |
* @param tree The application node |
|
1795 |
* @param env The environment current at the application. |
|
1796 |
*/ |
|
1797 |
boolean checkFirstConstructorStat(JCMethodInvocation tree, Env<AttrContext> env) { |
|
1798 |
JCMethodDecl enclMethod = env.enclMethod; |
|
1799 |
if (enclMethod != null && enclMethod.name == names.init) { |
|
1800 |
JCBlock body = enclMethod.body; |
|
10950 | 1801 |
if (body.stats.head.hasTag(EXEC) && |
10 | 1802 |
((JCExpressionStatement) body.stats.head).expr == tree) |
1803 |
return true; |
|
1804 |
} |
|
1805 |
log.error(tree.pos(),"call.must.be.first.stmt.in.ctor", |
|
1806 |
TreeInfo.name(tree.meth)); |
|
1807 |
return false; |
|
1808 |
} |
|
1809 |
||
1810 |
/** Obtain a method type with given argument types. |
|
1811 |
*/ |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
1812 |
Type newMethodTemplate(Type restype, List<Type> argtypes, List<Type> typeargtypes) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1813 |
MethodType mt = new MethodType(argtypes, restype, List.<Type>nil(), syms.methodClass); |
10 | 1814 |
return (typeargtypes == null) ? mt : (Type)new ForAll(typeargtypes, mt); |
1815 |
} |
|
1816 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1817 |
public void visitNewClass(final JCNewClass tree) { |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
1818 |
Type owntype = types.createErrorType(tree.type); |
10 | 1819 |
|
1820 |
// The local environment of a class creation is |
|
1821 |
// a new environment nested in the current one. |
|
1822 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
1823 |
||
1824 |
// The anonymous inner class definition of the new expression, |
|
1825 |
// if one is defined by it. |
|
1826 |
JCClassDecl cdef = tree.def; |
|
1827 |
||
1828 |
// If enclosing class is given, attribute it, and |
|
1829 |
// complete class name to be fully qualified |
|
1830 |
JCExpression clazz = tree.clazz; // Class field following new |
|
1831 |
JCExpression clazzid = // Identifier in class field |
|
10950 | 1832 |
(clazz.hasTag(TYPEAPPLY)) |
10 | 1833 |
? ((JCTypeApply) clazz).clazz |
1834 |
: clazz; |
|
1835 |
||
1836 |
JCExpression clazzid1 = clazzid; // The same in fully qualified form |
|
1837 |
||
1838 |
if (tree.encl != null) { |
|
1839 |
// We are seeing a qualified new, of the form |
|
1840 |
// <expr>.new C <...> (...) ... |
|
1841 |
// In this case, we let clazz stand for the name of the |
|
1842 |
// allocated class C prefixed with the type of the qualifier |
|
1843 |
// expression, so that we can |
|
1844 |
// resolve it with standard techniques later. I.e., if |
|
1845 |
// <expr> has type T, then <expr>.new C <...> (...) |
|
1846 |
// yields a clazz T.C. |
|
1847 |
Type encltype = chk.checkRefType(tree.encl.pos(), |
|
1848 |
attribExpr(tree.encl, env)); |
|
1849 |
clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), |
|
1850 |
((JCIdent) clazzid).name); |
|
10950 | 1851 |
if (clazz.hasTag(TYPEAPPLY)) |
10 | 1852 |
clazz = make.at(tree.pos). |
1853 |
TypeApply(clazzid1, |
|
1854 |
((JCTypeApply) clazz).arguments); |
|
1855 |
else |
|
1856 |
clazz = clazzid1; |
|
1857 |
} |
|
1858 |
||
1859 |
// Attribute clazz expression and store |
|
1860 |
// symbol + type back into the attributed tree. |
|
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
1861 |
Type clazztype = TreeInfo.isEnumInit(env.tree) ? |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
1862 |
attribIdentAsEnumType(env, (JCIdent)clazz) : |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
1863 |
attribType(clazz, env); |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
1864 |
|
8635
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
1865 |
clazztype = chk.checkDiamond(tree, clazztype); |
1358 | 1866 |
chk.validate(clazz, localEnv); |
10 | 1867 |
if (tree.encl != null) { |
1868 |
// We have to work in this case to store |
|
1869 |
// symbol + type back into the attributed tree. |
|
1870 |
tree.clazz.type = clazztype; |
|
1871 |
TreeInfo.setSymbol(clazzid, TreeInfo.symbol(clazzid1)); |
|
1872 |
clazzid.type = ((JCIdent) clazzid).sym.type; |
|
1873 |
if (!clazztype.isErroneous()) { |
|
1874 |
if (cdef != null && clazztype.tsym.isInterface()) { |
|
1875 |
log.error(tree.encl.pos(), "anon.class.impl.intf.no.qual.for.new"); |
|
1876 |
} else if (clazztype.tsym.isStatic()) { |
|
1877 |
log.error(tree.encl.pos(), "qualified.new.of.static.class", clazztype.tsym); |
|
1878 |
} |
|
1879 |
} |
|
1880 |
} else if (!clazztype.tsym.isInterface() && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1881 |
clazztype.getEnclosingType().hasTag(CLASS)) { |
10 | 1882 |
// Check for the existence of an apropos outer instance |
1883 |
rs.resolveImplicitThis(tree.pos(), env, clazztype); |
|
1884 |
} |
|
1885 |
||
1886 |
// Attribute constructor arguments. |
|
1887 |
List<Type> argtypes = attribArgs(tree.args, localEnv); |
|
1888 |
List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
|
1889 |
||
1890 |
// If we have made no mistakes in the class type... |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1891 |
if (clazztype.hasTag(CLASS)) { |
10 | 1892 |
// Enums may not be instantiated except implicitly |
1893 |
if (allowEnums && |
|
1894 |
(clazztype.tsym.flags_field&Flags.ENUM) != 0 && |
|
10950 | 1895 |
(!env.tree.hasTag(VARDEF) || |
10 | 1896 |
(((JCVariableDecl) env.tree).mods.flags&Flags.ENUM) == 0 || |
1897 |
((JCVariableDecl) env.tree).init != tree)) |
|
1898 |
log.error(tree.pos(), "enum.cant.be.instantiated"); |
|
1899 |
// Check that class is not abstract |
|
1900 |
if (cdef == null && |
|
1901 |
(clazztype.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
|
1902 |
log.error(tree.pos(), "abstract.cant.be.instantiated", |
|
1903 |
clazztype.tsym); |
|
1904 |
} else if (cdef != null && clazztype.tsym.isInterface()) { |
|
1905 |
// Check that no constructor arguments are given to |
|
1906 |
// anonymous classes implementing an interface |
|
1907 |
if (!argtypes.isEmpty()) |
|
1908 |
log.error(tree.args.head.pos(), "anon.class.impl.intf.no.args"); |
|
1909 |
||
1910 |
if (!typeargtypes.isEmpty()) |
|
1911 |
log.error(tree.typeargs.head.pos(), "anon.class.impl.intf.no.typeargs"); |
|
1912 |
||
1913 |
// Error recovery: pretend no arguments were supplied. |
|
1914 |
argtypes = List.nil(); |
|
1915 |
typeargtypes = List.nil(); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1916 |
} else if (TreeInfo.isDiamond(tree)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1917 |
ClassType site = new ClassType(clazztype.getEnclosingType(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1918 |
clazztype.tsym.type.getTypeArguments(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1919 |
clazztype.tsym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1920 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1921 |
Env<AttrContext> diamondEnv = localEnv.dup(tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1922 |
diamondEnv.info.selectSuper = cdef != null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1923 |
diamondEnv.info.pendingResolutionPhase = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1924 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1925 |
//if the type of the instance creation expression is a class type |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1926 |
//apply method resolution inference (JLS 15.12.2.7). The return type |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1927 |
//of the resolved constructor will be a partially instantiated type |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1928 |
Symbol constructor = rs.resolveDiamond(tree.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1929 |
diamondEnv, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1930 |
site, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1931 |
argtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1932 |
typeargtypes); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1933 |
tree.constructor = constructor.baseSymbol(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1934 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1935 |
final TypeSymbol csym = clazztype.tsym; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1936 |
ResultInfo diamondResult = new ResultInfo(MTH, newMethodTemplate(resultInfo.pt, argtypes, typeargtypes), new Check.NestedCheckContext(resultInfo.checkContext) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1937 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1938 |
public void report(DiagnosticPosition _unused, JCDiagnostic details) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1939 |
enclosingContext.report(tree.clazz, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1940 |
diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", csym), details)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1941 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1942 |
}); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1943 |
Type constructorType = tree.constructorType = types.createErrorType(clazztype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1944 |
constructorType = checkId(tree, site, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1945 |
constructor, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1946 |
diamondEnv, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1947 |
diamondResult); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1948 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1949 |
tree.clazz.type = types.createErrorType(clazztype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1950 |
if (!constructorType.isErroneous()) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1951 |
tree.clazz.type = clazztype = constructorType.getReturnType(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1952 |
tree.constructorType = types.createMethodTypeWithReturn(constructorType, syms.voidType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1953 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1954 |
clazztype = chk.checkClassType(tree.clazz, tree.clazz.type, true); |
10 | 1955 |
} |
1956 |
||
1957 |
// Resolve the called constructor under the assumption |
|
1958 |
// that we are referring to a superclass instance of the |
|
1959 |
// current instance (JLS ???). |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1960 |
else { |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1961 |
//the following code alters some of the fields in the current |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1962 |
//AttrContext - hence, the current context must be dup'ed in |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1963 |
//order to avoid downstream failures |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1964 |
Env<AttrContext> rsEnv = localEnv.dup(tree); |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1965 |
rsEnv.info.selectSuper = cdef != null; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1966 |
rsEnv.info.pendingResolutionPhase = null; |
10 | 1967 |
tree.constructor = rs.resolveConstructor( |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1968 |
tree.pos(), rsEnv, clazztype, argtypes, typeargtypes); |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1969 |
if (cdef == null) { //do not check twice! |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1970 |
tree.constructorType = checkId(tree, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1971 |
clazztype, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1972 |
tree.constructor, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1973 |
rsEnv, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1974 |
new ResultInfo(MTH, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1975 |
if (rsEnv.info.lastResolveVarargs()) |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1976 |
Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null); |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
1977 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1978 |
findDiamondIfNeeded(localEnv, tree, clazztype); |
10 | 1979 |
} |
1980 |
||
1981 |
if (cdef != null) { |
|
1982 |
// We are seeing an anonymous class instance creation. |
|
1983 |
// In this case, the class instance creation |
|
1984 |
// expression |
|
1985 |
// |
|
1986 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
|
1987 |
// |
|
1988 |
// is represented internally as |
|
1989 |
// |
|
1990 |
// E . new <typeargs1>C<typargs2>(args) ( class <empty-name> { ... } ) . |
|
1991 |
// |
|
1992 |
// This expression is then *transformed* as follows: |
|
1993 |
// |
|
1994 |
// (1) add a STATIC flag to the class definition |
|
1995 |
// if the current environment is static |
|
1996 |
// (2) add an extends or implements clause |
|
1997 |
// (3) add a constructor. |
|
1998 |
// |
|
1999 |
// For instance, if C is a class, and ET is the type of E, |
|
2000 |
// the expression |
|
2001 |
// |
|
2002 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
|
2003 |
// |
|
2004 |
// is translated to (where X is a fresh name and typarams is the |
|
2005 |
// parameter list of the super constructor): |
|
2006 |
// |
|
2007 |
// new <typeargs1>X(<*nullchk*>E, args) where |
|
2008 |
// X extends C<typargs2> { |
|
2009 |
// <typarams> X(ET e, args) { |
|
2010 |
// e.<typeargs1>super(args) |
|
2011 |
// } |
|
2012 |
// ... |
|
2013 |
// } |
|
2014 |
if (Resolve.isStatic(env)) cdef.mods.flags |= STATIC; |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
2015 |
|
10 | 2016 |
if (clazztype.tsym.isInterface()) { |
2017 |
cdef.implementing = List.of(clazz); |
|
2018 |
} else { |
|
2019 |
cdef.extending = clazz; |
|
2020 |
} |
|
2021 |
||
2022 |
attribStat(cdef, localEnv); |
|
2023 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2024 |
checkLambdaCandidate(tree, cdef.sym, clazztype); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2025 |
|
10 | 2026 |
// If an outer instance is given, |
2027 |
// prefix it to the constructor arguments |
|
2028 |
// and delete it from the new expression |
|
2029 |
if (tree.encl != null && !clazztype.tsym.isInterface()) { |
|
2030 |
tree.args = tree.args.prepend(makeNullCheck(tree.encl)); |
|
2031 |
argtypes = argtypes.prepend(tree.encl.type); |
|
2032 |
tree.encl = null; |
|
2033 |
} |
|
2034 |
||
2035 |
// Reassign clazztype and recompute constructor. |
|
2036 |
clazztype = cdef.sym.type; |
|
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2037 |
Symbol sym = tree.constructor = rs.resolveConstructor( |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2038 |
tree.pos(), localEnv, clazztype, argtypes, typeargtypes); |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2039 |
Assert.check(sym.kind < AMBIGUOUS); |
10 | 2040 |
tree.constructor = sym; |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2041 |
tree.constructorType = checkId(tree, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2042 |
clazztype, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2043 |
tree.constructor, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2044 |
localEnv, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2045 |
new ResultInfo(VAL, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); |
10 | 2046 |
} |
2047 |
||
2048 |
if (tree.constructor != null && tree.constructor.kind == MTH) |
|
2049 |
owntype = clazztype; |
|
2050 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2051 |
result = check(tree, owntype, VAL, resultInfo); |
1358 | 2052 |
chk.validate(tree.typeargs, localEnv); |
10 | 2053 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2054 |
//where |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2055 |
void findDiamondIfNeeded(Env<AttrContext> env, JCNewClass tree, Type clazztype) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2056 |
if (tree.def == null && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2057 |
!clazztype.isErroneous() && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2058 |
clazztype.getTypeArguments().nonEmpty() && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2059 |
findDiamonds) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2060 |
JCTypeApply ta = (JCTypeApply)tree.clazz; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2061 |
List<JCExpression> prevTypeargs = ta.arguments; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2062 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2063 |
//create a 'fake' diamond AST node by removing type-argument trees |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2064 |
ta.arguments = List.nil(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2065 |
ResultInfo findDiamondResult = new ResultInfo(VAL, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2066 |
resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2067 |
Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2068 |
if (!inferred.isErroneous() && |
14547 | 2069 |
types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), types.noWarnings)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2070 |
String key = types.isSameType(clazztype, inferred) ? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2071 |
"diamond.redundant.args" : |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2072 |
"diamond.redundant.args.1"; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2073 |
log.warning(tree.clazz.pos(), key, clazztype, inferred); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2074 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2075 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2076 |
ta.arguments = prevTypeargs; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2077 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2078 |
} |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
2079 |
} |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
2080 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2081 |
private void checkLambdaCandidate(JCNewClass tree, ClassSymbol csym, Type clazztype) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2082 |
if (allowLambda && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2083 |
identifyLambdaCandidate && |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2084 |
clazztype.hasTag(CLASS) && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2085 |
!pt().hasTag(NONE) && |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2086 |
types.isFunctionalInterface(clazztype.tsym)) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2087 |
Symbol descriptor = types.findDescriptorSymbol(clazztype.tsym); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2088 |
int count = 0; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2089 |
boolean found = false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2090 |
for (Symbol sym : csym.members().getElements()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2091 |
if ((sym.flags() & SYNTHETIC) != 0 || |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2092 |
sym.isConstructor()) continue; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2093 |
count++; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2094 |
if (sym.kind != MTH || |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2095 |
!sym.name.equals(descriptor.name)) continue; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2096 |
Type mtype = types.memberType(clazztype, sym); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2097 |
if (types.overrideEquivalent(mtype, types.memberType(clazztype, descriptor))) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2098 |
found = true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2099 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2100 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2101 |
if (found && count == 1) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2102 |
log.note(tree.def, "potential.lambda.found"); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2103 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2104 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2105 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2106 |
|
10 | 2107 |
/** Make an attributed null check tree. |
2108 |
*/ |
|
2109 |
public JCExpression makeNullCheck(JCExpression arg) { |
|
2110 |
// optimization: X.this is never null; skip null check |
|
2111 |
Name name = TreeInfo.name(arg); |
|
2112 |
if (name == names._this || name == names._super) return arg; |
|
2113 |
||
10950 | 2114 |
JCTree.Tag optag = NULLCHK; |
10 | 2115 |
JCUnary tree = make.at(arg.pos).Unary(optag, arg); |
2116 |
tree.operator = syms.nullcheck; |
|
2117 |
tree.type = arg.type; |
|
2118 |
return tree; |
|
2119 |
} |
|
2120 |
||
2121 |
public void visitNewArray(JCNewArray tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2122 |
Type owntype = types.createErrorType(tree.type); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2123 |
Env<AttrContext> localEnv = env.dup(tree); |
10 | 2124 |
Type elemtype; |
2125 |
if (tree.elemtype != null) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2126 |
elemtype = attribType(tree.elemtype, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2127 |
chk.validate(tree.elemtype, localEnv); |
10 | 2128 |
owntype = elemtype; |
2129 |
for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2130 |
attribExpr(l.head, localEnv, syms.intType); |
10 | 2131 |
owntype = new ArrayType(owntype, syms.arrayClass); |
2132 |
} |
|
2133 |
} else { |
|
2134 |
// we are seeing an untyped aggregate { ... } |
|
2135 |
// this is allowed only if the prototype is an array |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2136 |
if (pt().hasTag(ARRAY)) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2137 |
elemtype = types.elemtype(pt()); |
10 | 2138 |
} else { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2139 |
if (!pt().hasTag(ERROR)) { |
10 | 2140 |
log.error(tree.pos(), "illegal.initializer.for.type", |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2141 |
pt()); |
10 | 2142 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2143 |
elemtype = types.createErrorType(pt()); |
10 | 2144 |
} |
2145 |
} |
|
2146 |
if (tree.elems != null) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2147 |
attribExprs(tree.elems, localEnv, elemtype); |
10 | 2148 |
owntype = new ArrayType(elemtype, syms.arrayClass); |
2149 |
} |
|
2150 |
if (!types.isReifiable(elemtype)) |
|
2151 |
log.error(tree.pos(), "generic.array.creation"); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2152 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2153 |
} |
2154 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2155 |
/* |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2156 |
* A lambda expression can only be attributed when a target-type is available. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2157 |
* In addition, if the target-type is that of a functional interface whose |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2158 |
* descriptor contains inference variables in argument position the lambda expression |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2159 |
* is 'stuck' (see DeferredAttr). |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2160 |
*/ |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
2161 |
@Override |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2162 |
public void visitLambda(final JCLambda that) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2163 |
if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2164 |
if (pt().hasTag(NONE)) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2165 |
//lambda only allowed in assignment or method invocation/cast context |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2166 |
log.error(that.pos(), "unexpected.lambda"); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2167 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2168 |
result = that.type = types.createErrorType(pt()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2169 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2170 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2171 |
//create an environment for attribution of the lambda expression |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2172 |
final Env<AttrContext> localEnv = lambdaEnv(that, env); |
14547 | 2173 |
boolean needsRecovery = |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2174 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2175 |
try { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2176 |
List<Type> explicitParamTypes = null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2177 |
if (TreeInfo.isExplicitLambda(that)) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2178 |
//attribute lambda parameters |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2179 |
attribStats(that.params, localEnv); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2180 |
explicitParamTypes = TreeInfo.types(that.params); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2181 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2182 |
|
14547 | 2183 |
Type target; |
2184 |
Type lambdaType; |
|
2185 |
if (pt() != Type.recoveryType) { |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2186 |
target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), explicitParamTypes, resultInfo.checkContext); |
14547 | 2187 |
lambdaType = types.findDescriptorType(target); |
2188 |
chk.checkFunctionalInterface(that, target); |
|
2189 |
} else { |
|
2190 |
target = Type.recoveryType; |
|
2191 |
lambdaType = fallbackDescriptorType(that); |
|
2192 |
} |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2193 |
|
14723
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2194 |
if (lambdaType.hasTag(FORALL)) { |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2195 |
//lambda expression target desc cannot be a generic method |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2196 |
resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target", |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2197 |
lambdaType, kindName(target.tsym), target.tsym)); |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2198 |
result = that.type = types.createErrorType(pt()); |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2199 |
return; |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2200 |
} |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2201 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2202 |
if (!TreeInfo.isExplicitLambda(that)) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2203 |
//add param type info in the AST |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2204 |
List<Type> actuals = lambdaType.getParameterTypes(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2205 |
List<JCVariableDecl> params = that.params; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2206 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2207 |
boolean arityMismatch = false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2208 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2209 |
while (params.nonEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2210 |
if (actuals.isEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2211 |
//not enough actuals to perform lambda parameter inference |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2212 |
arityMismatch = true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2213 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2214 |
//reset previously set info |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2215 |
Type argType = arityMismatch ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2216 |
syms.errType : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2217 |
actuals.head; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2218 |
params.head.vartype = make.Type(argType); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2219 |
params.head.sym = null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2220 |
actuals = actuals.isEmpty() ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2221 |
actuals : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2222 |
actuals.tail; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2223 |
params = params.tail; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2224 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2225 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2226 |
//attribute lambda parameters |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2227 |
attribStats(that.params, localEnv); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2228 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2229 |
if (arityMismatch) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2230 |
resultInfo.checkContext.report(that, diags.fragment("incompatible.arg.types.in.lambda")); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2231 |
result = that.type = types.createErrorType(target); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2232 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2233 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2234 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2235 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2236 |
//from this point on, no recovery is needed; if we are in assignment context |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2237 |
//we will be able to attribute the whole lambda body, regardless of errors; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2238 |
//if we are in a 'check' method context, and the lambda is not compatible |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2239 |
//with the target-type, it will be recovered anyway in Attr.checkId |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2240 |
needsRecovery = false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2241 |
|
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2242 |
FunctionalReturnContext funcContext = that.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2243 |
new ExpressionLambdaReturnContext((JCExpression)that.getBody(), resultInfo.checkContext) : |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2244 |
new FunctionalReturnContext(resultInfo.checkContext); |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2245 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2246 |
ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2247 |
recoveryInfo : |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2248 |
new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2249 |
localEnv.info.returnResult = bodyResultInfo; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2250 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2251 |
if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2252 |
attribTree(that.getBody(), localEnv, bodyResultInfo); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2253 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2254 |
JCBlock body = (JCBlock)that.body; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2255 |
attribStats(body.stats, localEnv); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2256 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2257 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2258 |
result = check(that, target, VAL, resultInfo); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2259 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2260 |
boolean isSpeculativeRound = |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2261 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2262 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2263 |
postAttr(that); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2264 |
flow.analyzeLambda(env, that, make, isSpeculativeRound); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2265 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2266 |
checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2267 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2268 |
if (!isSpeculativeRound) { |
14547 | 2269 |
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, target); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2270 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2271 |
result = check(that, target, VAL, resultInfo); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2272 |
} catch (Types.FunctionDescriptorLookupError ex) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2273 |
JCDiagnostic cause = ex.getDiagnostic(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2274 |
resultInfo.checkContext.report(that, cause); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2275 |
result = that.type = types.createErrorType(pt()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2276 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2277 |
} finally { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2278 |
localEnv.info.scope.leave(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2279 |
if (needsRecovery) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2280 |
attribTree(that, env, recoveryInfo); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2281 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2282 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
2283 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2284 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2285 |
private Type checkIntersectionTarget(DiagnosticPosition pos, ResultInfo resultInfo) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2286 |
Type pt = resultInfo.pt; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2287 |
if (pt != Type.recoveryType && pt.isCompound()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2288 |
IntersectionClassType ict = (IntersectionClassType)pt; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2289 |
List<Type> bounds = ict.allInterfaces ? |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2290 |
ict.getComponents().tail : |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2291 |
ict.getComponents(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2292 |
types.findDescriptorType(bounds.head); //propagate exception outwards! |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2293 |
for (Type bound : bounds.tail) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2294 |
if (!types.isMarkerInterface(bound)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2295 |
resultInfo.checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2296 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2297 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2298 |
//for now (translation doesn't support intersection types) |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2299 |
return bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2300 |
} else { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2301 |
return pt; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2302 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2303 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2304 |
//where |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2305 |
private Type fallbackDescriptorType(JCExpression tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2306 |
switch (tree.getTag()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2307 |
case LAMBDA: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2308 |
JCLambda lambda = (JCLambda)tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2309 |
List<Type> argtypes = List.nil(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2310 |
for (JCVariableDecl param : lambda.params) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2311 |
argtypes = param.vartype != null ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2312 |
argtypes.append(param.vartype.type) : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2313 |
argtypes.append(syms.errType); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2314 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2315 |
return new MethodType(argtypes, Type.recoveryType, List.<Type>nil(), syms.methodClass); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2316 |
case REFERENCE: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2317 |
return new MethodType(List.<Type>nil(), Type.recoveryType, List.<Type>nil(), syms.methodClass); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2318 |
default: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2319 |
Assert.error("Cannot get here!"); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2320 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2321 |
return null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2322 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2323 |
|
14547 | 2324 |
private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts) { |
2325 |
checkAccessibleTypes(pos, env, inferenceContext, List.from(ts)); |
|
2326 |
} |
|
2327 |
||
2328 |
private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts) { |
|
2329 |
if (inferenceContext.free(ts)) { |
|
2330 |
inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() { |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2331 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2332 |
public void typesInferred(InferenceContext inferenceContext) { |
14547 | 2333 |
checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts, types)); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2334 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2335 |
}); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2336 |
} else { |
14547 | 2337 |
for (Type t : ts) { |
2338 |
rs.checkAccessibleType(env, t); |
|
2339 |
} |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2340 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2341 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2342 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2343 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2344 |
* Lambda/method reference have a special check context that ensures |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2345 |
* that i.e. a lambda return type is compatible with the expected |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2346 |
* type according to both the inherited context and the assignment |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2347 |
* context. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2348 |
*/ |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2349 |
class FunctionalReturnContext extends Check.NestedCheckContext { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2350 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2351 |
FunctionalReturnContext(CheckContext enclosingContext) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2352 |
super(enclosingContext); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2353 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2354 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2355 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2356 |
public boolean compatible(Type found, Type req, Warner warn) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2357 |
//return type must be compatible in both current context and assignment context |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2358 |
return types.isAssignable(found, inferenceContext().asFree(req, types), warn) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2359 |
super.compatible(found, req, warn); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2360 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2361 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2362 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2363 |
enclosingContext.report(pos, diags.fragment("incompatible.ret.type.in.lambda", details)); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2364 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2365 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2366 |
|
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2367 |
class ExpressionLambdaReturnContext extends FunctionalReturnContext { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2368 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2369 |
JCExpression expr; |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2370 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2371 |
ExpressionLambdaReturnContext(JCExpression expr, CheckContext enclosingContext) { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2372 |
super(enclosingContext); |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2373 |
this.expr = expr; |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2374 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2375 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2376 |
@Override |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2377 |
public boolean compatible(Type found, Type req, Warner warn) { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2378 |
//a void return is compatible with an expression statement lambda |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2379 |
return TreeInfo.isExpressionStatement(expr) && req.hasTag(VOID) || |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2380 |
super.compatible(found, req, warn); |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2381 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2382 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2383 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2384 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2385 |
* Lambda compatibility. Check that given return types, thrown types, parameter types |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2386 |
* are compatible with the expected functional interface descriptor. This means that: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2387 |
* (i) parameter types must be identical to those of the target descriptor; (ii) return |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2388 |
* types must be compatible with the return type of the expected descriptor; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2389 |
* (iii) thrown types must be 'included' in the thrown types list of the expected |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2390 |
* descriptor. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2391 |
*/ |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2392 |
private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext, boolean speculativeAttr) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2393 |
Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType(), types); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2394 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2395 |
//return values have already been checked - but if lambda has no return |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2396 |
//values, we must ensure that void/value compatibility is correct; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2397 |
//this amounts at checking that, if a lambda body can complete normally, |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2398 |
//the descriptor's return type must be void |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2399 |
if (tree.getBodyKind() == JCLambda.BodyKind.STATEMENT && tree.canCompleteNormally && |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2400 |
!returnType.hasTag(VOID) && returnType != Type.recoveryType) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2401 |
checkContext.report(tree, diags.fragment("incompatible.ret.type.in.lambda", |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2402 |
diags.fragment("missing.ret.val", returnType))); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2403 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2404 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2405 |
List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes(), types); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2406 |
if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2407 |
checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2408 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2409 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2410 |
if (!speculativeAttr) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2411 |
List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes(), types); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2412 |
if (chk.unhandled(tree.inferredThrownTypes == null ? List.<Type>nil() : tree.inferredThrownTypes, thrownTypes).nonEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2413 |
log.error(tree, "incompatible.thrown.types.in.lambda", tree.inferredThrownTypes); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2414 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2415 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2416 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2417 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2418 |
private Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2419 |
Env<AttrContext> lambdaEnv; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2420 |
Symbol owner = env.info.scope.owner; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2421 |
if (owner.kind == VAR && owner.owner.kind == TYP) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2422 |
//field initializer |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2423 |
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dupUnshared())); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2424 |
lambdaEnv.info.scope.owner = |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2425 |
new MethodSymbol(0, names.empty, null, |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2426 |
env.info.scope.owner); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2427 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2428 |
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup())); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2429 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2430 |
return lambdaEnv; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2431 |
} |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
2432 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2433 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2434 |
public void visitReference(final JCMemberReference that) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2435 |
if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2436 |
if (pt().hasTag(NONE)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2437 |
//method reference only allowed in assignment or method invocation/cast context |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2438 |
log.error(that.pos(), "unexpected.mref"); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2439 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2440 |
result = that.type = types.createErrorType(pt()); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2441 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2442 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2443 |
final Env<AttrContext> localEnv = env.dup(that); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2444 |
try { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2445 |
//attribute member reference qualifier - if this is a constructor |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2446 |
//reference, the expected kind must be a type |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2447 |
Type exprType = attribTree(that.expr, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2448 |
env, new ResultInfo(that.getMode() == ReferenceMode.INVOKE ? VAL | TYP : TYP, Type.noType)); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2449 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2450 |
if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2451 |
exprType = chk.checkConstructorRefType(that.expr, exprType); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2452 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2453 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2454 |
if (exprType.isErroneous()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2455 |
//if the qualifier expression contains problems, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2456 |
//give up atttribution of method reference |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2457 |
result = that.type = exprType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2458 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2459 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2460 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2461 |
if (TreeInfo.isStaticSelector(that.expr, names) && |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2462 |
(that.getMode() != ReferenceMode.NEW || !that.expr.type.isRaw())) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2463 |
//if the qualifier is a type, validate it |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2464 |
chk.validate(that.expr, env); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2465 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2466 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2467 |
//attrib type-arguments |
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2468 |
List<Type> typeargtypes = List.nil(); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2469 |
if (that.typeargs != null) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2470 |
typeargtypes = attribTypes(that.typeargs, localEnv); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2471 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2472 |
|
14547 | 2473 |
Type target; |
2474 |
Type desc; |
|
2475 |
if (pt() != Type.recoveryType) { |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2476 |
target = infer.instantiateFunctionalInterface(that, checkIntersectionTarget(that, resultInfo), null, resultInfo.checkContext); |
14547 | 2477 |
desc = types.findDescriptorType(target); |
2478 |
chk.checkFunctionalInterface(that, target); |
|
2479 |
} else { |
|
2480 |
target = Type.recoveryType; |
|
2481 |
desc = fallbackDescriptorType(that); |
|
2482 |
} |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2483 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2484 |
List<Type> argtypes = desc.getParameterTypes(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2485 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2486 |
boolean allowBoxing = |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2487 |
resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2488 |
Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2489 |
that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2490 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2491 |
Symbol refSym = refResult.fst; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2492 |
Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2493 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2494 |
if (refSym.kind != MTH) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2495 |
boolean targetError; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2496 |
switch (refSym.kind) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2497 |
case ABSENT_MTH: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2498 |
targetError = false; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2499 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2500 |
case WRONG_MTH: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2501 |
case WRONG_MTHS: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2502 |
case AMBIGUOUS: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2503 |
case HIDDEN: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2504 |
case STATICERR: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2505 |
case MISSING_ENCL: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2506 |
targetError = true; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2507 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2508 |
default: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2509 |
Assert.error("unexpected result kind " + refSym.kind); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2510 |
targetError = false; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2511 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2512 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2513 |
JCDiagnostic detailsDiag = ((Resolve.ResolveError)refSym).getDiagnostic(JCDiagnostic.DiagnosticType.FRAGMENT, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2514 |
that, exprType.tsym, exprType, that.name, argtypes, typeargtypes); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2515 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2516 |
JCDiagnostic.DiagnosticType diagKind = targetError ? |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2517 |
JCDiagnostic.DiagnosticType.FRAGMENT : JCDiagnostic.DiagnosticType.ERROR; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2518 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2519 |
JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2520 |
"invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2521 |
|
14547 | 2522 |
if (targetError && target == Type.recoveryType) { |
2523 |
//a target error doesn't make sense during recovery stage |
|
2524 |
//as we don't know what actual parameter types are |
|
2525 |
result = that.type = target; |
|
2526 |
return; |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2527 |
} else { |
14547 | 2528 |
if (targetError) { |
2529 |
resultInfo.checkContext.report(that, diag); |
|
2530 |
} else { |
|
2531 |
log.report(diag); |
|
2532 |
} |
|
2533 |
result = that.type = types.createErrorType(target); |
|
2534 |
return; |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2535 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2536 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2537 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2538 |
if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2539 |
if (refSym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) && |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2540 |
exprType.getTypeArguments().nonEmpty()) { |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2541 |
//static ref with class type-args |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2542 |
log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2543 |
diags.fragment("static.mref.with.targs")); |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2544 |
result = that.type = types.createErrorType(target); |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2545 |
return; |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2546 |
} |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2547 |
|
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2548 |
if (refSym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) && |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2549 |
!lookupHelper.referenceKind(refSym).isUnbound()) { |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2550 |
//no static bound mrefs |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2551 |
log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2552 |
diags.fragment("static.bound.mref")); |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2553 |
result = that.type = types.createErrorType(target); |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2554 |
return; |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2555 |
} |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2556 |
} |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2557 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2558 |
if (desc.getReturnType() == Type.recoveryType) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2559 |
// stop here |
14547 | 2560 |
result = that.type = target; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2561 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2562 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2563 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2564 |
that.sym = refSym.baseSymbol(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2565 |
that.kind = lookupHelper.referenceKind(that.sym); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2566 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2567 |
ResultInfo checkInfo = |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2568 |
resultInfo.dup(newMethodTemplate( |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2569 |
desc.getReturnType().hasTag(VOID) ? Type.noType : desc.getReturnType(), |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2570 |
lookupHelper.argtypes, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2571 |
typeargtypes)); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2572 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2573 |
Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2574 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2575 |
if (!refType.isErroneous()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2576 |
refType = types.createMethodTypeWithReturn(refType, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2577 |
adjustMethodReturnType(lookupHelper.site, that.name, checkInfo.pt.getParameterTypes(), refType.getReturnType())); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2578 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2579 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2580 |
//go ahead with standard method reference compatibility check - note that param check |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2581 |
//is a no-op (as this has been taken care during method applicability) |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2582 |
boolean isSpeculativeRound = |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2583 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2584 |
checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2585 |
if (!isSpeculativeRound) { |
14547 | 2586 |
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, target); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2587 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2588 |
result = check(that, target, VAL, resultInfo); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2589 |
} catch (Types.FunctionDescriptorLookupError ex) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2590 |
JCDiagnostic cause = ex.getDiagnostic(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2591 |
resultInfo.checkContext.report(that, cause); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2592 |
result = that.type = types.createErrorType(pt()); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2593 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2594 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2595 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2596 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2597 |
@SuppressWarnings("fallthrough") |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2598 |
void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2599 |
Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType(), types); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2600 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2601 |
Type resType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2602 |
switch (tree.getMode()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2603 |
case NEW: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2604 |
if (!tree.expr.type.isRaw()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2605 |
resType = tree.expr.type; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2606 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2607 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2608 |
default: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2609 |
resType = refType.getReturnType(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2610 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2611 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2612 |
Type incompatibleReturnType = resType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2613 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2614 |
if (returnType.hasTag(VOID)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2615 |
incompatibleReturnType = null; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2616 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2617 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2618 |
if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2619 |
if (resType.isErroneous() || |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2620 |
new FunctionalReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2621 |
incompatibleReturnType = null; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2622 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2623 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2624 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2625 |
if (incompatibleReturnType != null) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2626 |
checkContext.report(tree, diags.fragment("incompatible.ret.type.in.mref", |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2627 |
diags.fragment("inconvertible.types", resType, descriptor.getReturnType()))); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2628 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2629 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2630 |
if (!speculativeAttr) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2631 |
List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes(), types); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2632 |
if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2633 |
log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes()); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2634 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2635 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2636 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2637 |
|
10 | 2638 |
public void visitParens(JCParens tree) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2639 |
Type owntype = attribTree(tree.expr, env, resultInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2640 |
result = check(tree, owntype, pkind(), resultInfo); |
10 | 2641 |
Symbol sym = TreeInfo.symbol(tree); |
2642 |
if (sym != null && (sym.kind&(TYP|PCK)) != 0) |
|
2643 |
log.error(tree.pos(), "illegal.start.of.type"); |
|
2644 |
} |
|
2645 |
||
2646 |
public void visitAssign(JCAssign tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2647 |
Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo); |
10 | 2648 |
Type capturedType = capture(owntype); |
2649 |
attribExpr(tree.rhs, env, owntype); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2650 |
result = check(tree, capturedType, VAL, resultInfo); |
10 | 2651 |
} |
2652 |
||
2653 |
public void visitAssignop(JCAssignOp tree) { |
|
2654 |
// Attribute arguments. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2655 |
Type owntype = attribTree(tree.lhs, env, varInfo); |
10 | 2656 |
Type operand = attribExpr(tree.rhs, env); |
2657 |
// Find operator. |
|
2658 |
Symbol operator = tree.operator = rs.resolveBinaryOperator( |
|
10950 | 2659 |
tree.pos(), tree.getTag().noAssignOp(), env, |
10 | 2660 |
owntype, operand); |
2661 |
||
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2662 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2663 |
!owntype.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2664 |
!operand.isErroneous()) { |
10 | 2665 |
chk.checkOperator(tree.pos(), |
2666 |
(OperatorSymbol)operator, |
|
10950 | 2667 |
tree.getTag().noAssignOp(), |
10 | 2668 |
owntype, |
2669 |
operand); |
|
166 | 2670 |
chk.checkDivZero(tree.rhs.pos(), operator, operand); |
2671 |
chk.checkCastable(tree.rhs.pos(), |
|
2672 |
operator.type.getReturnType(), |
|
2673 |
owntype); |
|
10 | 2674 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2675 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2676 |
} |
2677 |
||
2678 |
public void visitUnary(JCUnary tree) { |
|
2679 |
// Attribute arguments. |
|
10950 | 2680 |
Type argtype = (tree.getTag().isIncOrDecUnaryOp()) |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2681 |
? attribTree(tree.arg, env, varInfo) |
10 | 2682 |
: chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env)); |
2683 |
||
2684 |
// Find operator. |
|
2685 |
Symbol operator = tree.operator = |
|
2686 |
rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype); |
|
2687 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2688 |
Type owntype = types.createErrorType(tree.type); |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2689 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2690 |
!argtype.isErroneous()) { |
10950 | 2691 |
owntype = (tree.getTag().isIncOrDecUnaryOp()) |
10 | 2692 |
? tree.arg.type |
2693 |
: operator.type.getReturnType(); |
|
2694 |
int opc = ((OperatorSymbol)operator).opcode; |
|
2695 |
||
2696 |
// If the argument is constant, fold it. |
|
2697 |
if (argtype.constValue() != null) { |
|
2698 |
Type ctype = cfolder.fold1(opc, argtype); |
|
2699 |
if (ctype != null) { |
|
2700 |
owntype = cfolder.coerce(ctype, owntype); |
|
2701 |
||
2702 |
// Remove constant types from arguments to |
|
2703 |
// conserve space. The parser will fold concatenations |
|
2704 |
// of string literals; the code here also |
|
2705 |
// gets rid of intermediate results when some of the |
|
2706 |
// operands are constant identifiers. |
|
2707 |
if (tree.arg.type.tsym == syms.stringType.tsym) { |
|
2708 |
tree.arg.type = syms.stringType; |
|
2709 |
} |
|
2710 |
} |
|
2711 |
} |
|
2712 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2713 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2714 |
} |
2715 |
||
2716 |
public void visitBinary(JCBinary tree) { |
|
2717 |
// Attribute arguments. |
|
2718 |
Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env)); |
|
2719 |
Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env)); |
|
2720 |
||
2721 |
// Find operator. |
|
2722 |
Symbol operator = tree.operator = |
|
2723 |
rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right); |
|
2724 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2725 |
Type owntype = types.createErrorType(tree.type); |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2726 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2727 |
!left.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2728 |
!right.isErroneous()) { |
10 | 2729 |
owntype = operator.type.getReturnType(); |
2730 |
int opc = chk.checkOperator(tree.lhs.pos(), |
|
2731 |
(OperatorSymbol)operator, |
|
2732 |
tree.getTag(), |
|
2733 |
left, |
|
2734 |
right); |
|
2735 |
||
2736 |
// If both arguments are constants, fold them. |
|
2737 |
if (left.constValue() != null && right.constValue() != null) { |
|
2738 |
Type ctype = cfolder.fold2(opc, left, right); |
|
2739 |
if (ctype != null) { |
|
2740 |
owntype = cfolder.coerce(ctype, owntype); |
|
2741 |
||
2742 |
// Remove constant types from arguments to |
|
2743 |
// conserve space. The parser will fold concatenations |
|
2744 |
// of string literals; the code here also |
|
2745 |
// gets rid of intermediate results when some of the |
|
2746 |
// operands are constant identifiers. |
|
2747 |
if (tree.lhs.type.tsym == syms.stringType.tsym) { |
|
2748 |
tree.lhs.type = syms.stringType; |
|
2749 |
} |
|
2750 |
if (tree.rhs.type.tsym == syms.stringType.tsym) { |
|
2751 |
tree.rhs.type = syms.stringType; |
|
2752 |
} |
|
2753 |
} |
|
2754 |
} |
|
2755 |
||
2756 |
// Check that argument types of a reference ==, != are |
|
2757 |
// castable to each other, (JLS???). |
|
2758 |
if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) { |
|
2759 |
if (!types.isCastable(left, right, new Warner(tree.pos()))) { |
|
2760 |
log.error(tree.pos(), "incomparable.types", left, right); |
|
2761 |
} |
|
2762 |
} |
|
2763 |
||
2764 |
chk.checkDivZero(tree.rhs.pos(), operator, right); |
|
2765 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2766 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2767 |
} |
2768 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2769 |
public void visitTypeCast(final JCTypeCast tree) { |
10 | 2770 |
Type clazztype = attribType(tree.clazz, env); |
6351 | 2771 |
chk.validate(tree.clazz, env, false); |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2772 |
//a fresh environment is required for 292 inference to work properly --- |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2773 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2774 |
Env<AttrContext> localEnv = env.dup(tree); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2775 |
//should we propagate the target type? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2776 |
final ResultInfo castInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2777 |
final boolean isPoly = TreeInfo.isPoly(tree.expr, tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2778 |
if (isPoly) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2779 |
//expression is a poly - we need to propagate target type info |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2780 |
castInfo = new ResultInfo(VAL, clazztype, new Check.NestedCheckContext(resultInfo.checkContext) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2781 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2782 |
public boolean compatible(Type found, Type req, Warner warn) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2783 |
return types.isCastable(found, req, warn); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2784 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2785 |
}); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2786 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2787 |
//standalone cast - target-type info is not propagated |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2788 |
castInfo = unknownExprInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2789 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2790 |
Type exprtype = attribTree(tree.expr, localEnv, castInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2791 |
Type owntype = isPoly ? clazztype : chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
10 | 2792 |
if (exprtype.constValue() != null) |
2793 |
owntype = cfolder.coerce(exprtype, owntype); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2794 |
result = check(tree, capture(owntype), VAL, resultInfo); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2795 |
if (!isPoly) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2796 |
chk.checkRedundantCast(localEnv, tree); |
10 | 2797 |
} |
2798 |
||
2799 |
public void visitTypeTest(JCInstanceOf tree) { |
|
2800 |
Type exprtype = chk.checkNullOrRefType( |
|
2801 |
tree.expr.pos(), attribExpr(tree.expr, env)); |
|
2802 |
Type clazztype = chk.checkReifiableReferenceType( |
|
2803 |
tree.clazz.pos(), attribType(tree.clazz, env)); |
|
6351 | 2804 |
chk.validate(tree.clazz, env, false); |
10 | 2805 |
chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2806 |
result = check(tree, syms.booleanType, VAL, resultInfo); |
10 | 2807 |
} |
2808 |
||
2809 |
public void visitIndexed(JCArrayAccess tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2810 |
Type owntype = types.createErrorType(tree.type); |
10 | 2811 |
Type atype = attribExpr(tree.indexed, env); |
2812 |
attribExpr(tree.index, env, syms.intType); |
|
2813 |
if (types.isArray(atype)) |
|
2814 |
owntype = types.elemtype(atype); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2815 |
else if (!atype.hasTag(ERROR)) |
10 | 2816 |
log.error(tree.pos(), "array.req.but.found", atype); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2817 |
if ((pkind() & VAR) == 0) owntype = capture(owntype); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2818 |
result = check(tree, owntype, VAR, resultInfo); |
10 | 2819 |
} |
2820 |
||
2821 |
public void visitIdent(JCIdent tree) { |
|
2822 |
Symbol sym; |
|
2823 |
||
2824 |
// Find symbol |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2825 |
if (pt().hasTag(METHOD) || pt().hasTag(FORALL)) { |
10 | 2826 |
// If we are looking for a method, the prototype `pt' will be a |
2827 |
// method type with the type of the call's arguments as parameters. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2828 |
env.info.pendingResolutionPhase = null; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2829 |
sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments()); |
10 | 2830 |
} else if (tree.sym != null && tree.sym.kind != VAR) { |
2831 |
sym = tree.sym; |
|
2832 |
} else { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2833 |
sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind()); |
10 | 2834 |
} |
2835 |
tree.sym = sym; |
|
2836 |
||
2837 |
// (1) Also find the environment current for the class where |
|
2838 |
// sym is defined (`symEnv'). |
|
2839 |
// Only for pre-tiger versions (1.4 and earlier): |
|
2840 |
// (2) Also determine whether we access symbol out of an anonymous |
|
2841 |
// class in a this or super call. This is illegal for instance |
|
2842 |
// members since such classes don't carry a this$n link. |
|
2843 |
// (`noOuterThisPath'). |
|
2844 |
Env<AttrContext> symEnv = env; |
|
2845 |
boolean noOuterThisPath = false; |
|
2846 |
if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class |
|
2847 |
(sym.kind & (VAR | MTH | TYP)) != 0 && |
|
2848 |
sym.owner.kind == TYP && |
|
2849 |
tree.name != names._this && tree.name != names._super) { |
|
2850 |
||
2851 |
// Find environment in which identifier is defined. |
|
2852 |
while (symEnv.outer != null && |
|
2853 |
!sym.isMemberOf(symEnv.enclClass.sym, types)) { |
|
2854 |
if ((symEnv.enclClass.sym.flags() & NOOUTERTHIS) != 0) |
|
2855 |
noOuterThisPath = !allowAnonOuterThis; |
|
2856 |
symEnv = symEnv.outer; |
|
2857 |
} |
|
2858 |
} |
|
2859 |
||
2860 |
// If symbol is a variable, ... |
|
2861 |
if (sym.kind == VAR) { |
|
2862 |
VarSymbol v = (VarSymbol)sym; |
|
2863 |
||
2864 |
// ..., evaluate its initializer, if it has one, and check for |
|
2865 |
// illegal forward reference. |
|
2866 |
checkInit(tree, env, v, false); |
|
2867 |
||
2868 |
// If we are expecting a variable (as opposed to a value), check |
|
2869 |
// that the variable is assignable in the current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2870 |
if (pkind() == VAR) |
10 | 2871 |
checkAssignable(tree.pos(), v, null, env); |
2872 |
} |
|
2873 |
||
2874 |
// In a constructor body, |
|
2875 |
// if symbol is a field or instance method, check that it is |
|
2876 |
// not accessed before the supertype constructor is called. |
|
2877 |
if ((symEnv.info.isSelfCall || noOuterThisPath) && |
|
2878 |
(sym.kind & (VAR | MTH)) != 0 && |
|
2879 |
sym.owner.kind == TYP && |
|
2880 |
(sym.flags() & STATIC) == 0) { |
|
2881 |
chk.earlyRefError(tree.pos(), sym.kind == VAR ? sym : thisSym(tree.pos(), env)); |
|
2882 |
} |
|
2883 |
Env<AttrContext> env1 = env; |
|
512
53e498fa5c0e
6657499: javac 1.6.0 fails to compile class with inner class
mcimadamore
parents:
511
diff
changeset
|
2884 |
if (sym.kind != ERR && sym.kind != TYP && sym.owner != null && sym.owner != env1.enclClass.sym) { |
10 | 2885 |
// If the found symbol is inaccessible, then it is |
2886 |
// accessed through an enclosing instance. Locate this |
|
2887 |
// enclosing instance: |
|
2888 |
while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) |
|
2889 |
env1 = env1.outer; |
|
2890 |
} |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2891 |
result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); |
10 | 2892 |
} |
2893 |
||
2894 |
public void visitSelect(JCFieldAccess tree) { |
|
2895 |
// Determine the expected kind of the qualifier expression. |
|
2896 |
int skind = 0; |
|
2897 |
if (tree.name == names._this || tree.name == names._super || |
|
2898 |
tree.name == names._class) |
|
2899 |
{ |
|
2900 |
skind = TYP; |
|
2901 |
} else { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2902 |
if ((pkind() & PCK) != 0) skind = skind | PCK; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2903 |
if ((pkind() & TYP) != 0) skind = skind | TYP | PCK; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2904 |
if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP; |
10 | 2905 |
} |
2906 |
||
2907 |
// Attribute the qualifier expression, and determine its symbol (if any). |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2908 |
Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly)); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2909 |
if ((pkind() & (PCK | TYP)) == 0) |
10 | 2910 |
site = capture(site); // Capture field access |
2911 |
||
2912 |
// don't allow T.class T[].class, etc |
|
2913 |
if (skind == TYP) { |
|
2914 |
Type elt = site; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2915 |
while (elt.hasTag(ARRAY)) |
10 | 2916 |
elt = ((ArrayType)elt).elemtype; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2917 |
if (elt.hasTag(TYPEVAR)) { |
10 | 2918 |
log.error(tree.pos(), "type.var.cant.be.deref"); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2919 |
result = types.createErrorType(tree.type); |
10 | 2920 |
return; |
2921 |
} |
|
2922 |
} |
|
2923 |
||
2924 |
// If qualifier symbol is a type or `super', assert `selectSuper' |
|
2925 |
// for the selection. This is relevant for determining whether |
|
2926 |
// protected symbols are accessible. |
|
2927 |
Symbol sitesym = TreeInfo.symbol(tree.selected); |
|
2928 |
boolean selectSuperPrev = env.info.selectSuper; |
|
2929 |
env.info.selectSuper = |
|
2930 |
sitesym != null && |
|
2931 |
sitesym.name == names._super; |
|
2932 |
||
2933 |
// Determine the symbol represented by the selection. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2934 |
env.info.pendingResolutionPhase = null; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2935 |
Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2936 |
if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) { |
10 | 2937 |
site = capture(site); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2938 |
sym = selectSym(tree, sitesym, site, env, resultInfo); |
10 | 2939 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2940 |
boolean varArgs = env.info.lastResolveVarargs(); |
10 | 2941 |
tree.sym = sym; |
2942 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2943 |
if (site.hasTag(TYPEVAR) && !isType(sym) && sym.kind != ERR) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2944 |
while (site.hasTag(TYPEVAR)) site = site.getUpperBound(); |
511
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2945 |
site = capture(site); |
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2946 |
} |
10 | 2947 |
|
2948 |
// If that symbol is a variable, ... |
|
2949 |
if (sym.kind == VAR) { |
|
2950 |
VarSymbol v = (VarSymbol)sym; |
|
2951 |
||
2952 |
// ..., evaluate its initializer, if it has one, and check for |
|
2953 |
// illegal forward reference. |
|
2954 |
checkInit(tree, env, v, true); |
|
2955 |
||
2956 |
// If we are expecting a variable (as opposed to a value), check |
|
2957 |
// that the variable is assignable in the current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2958 |
if (pkind() == VAR) |
10 | 2959 |
checkAssignable(tree.pos(), v, tree.selected, env); |
2960 |
} |
|
2961 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2962 |
if (sitesym != null && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2963 |
sitesym.kind == VAR && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2964 |
((VarSymbol)sitesym).isResourceVariable() && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2965 |
sym.kind == MTH && |
9079
e512a7712be3
7032633: javac -Xlint:all warns about flush() within try on an auto-closeable resource
mcimadamore
parents:
9076
diff
changeset
|
2966 |
sym.name.equals(names.close) && |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2967 |
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2968 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2969 |
log.warning(LintCategory.TRY, tree, "try.explicit.close.call"); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2970 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2971 |
|
10 | 2972 |
// Disallow selecting a type from an expression |
2973 |
if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2974 |
tree.type = check(tree.selected, pt(), |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2975 |
sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt())); |
10 | 2976 |
} |
2977 |
||
2978 |
if (isType(sitesym)) { |
|
2979 |
if (sym.name == names._this) { |
|
2980 |
// If `C' is the currently compiled class, check that |
|
2981 |
// C.this' does not appear in a call to a super(...) |
|
2982 |
if (env.info.isSelfCall && |
|
2983 |
site.tsym == env.enclClass.sym) { |
|
2984 |
chk.earlyRefError(tree.pos(), sym); |
|
2985 |
} |
|
2986 |
} else { |
|
2987 |
// Check if type-qualified fields or methods are static (JLS) |
|
2988 |
if ((sym.flags() & STATIC) == 0 && |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2989 |
!env.next.tree.hasTag(REFERENCE) && |
10 | 2990 |
sym.name != names._super && |
2991 |
(sym.kind == VAR || sym.kind == MTH)) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2992 |
rs.accessBase(rs.new StaticError(sym), |
10 | 2993 |
tree.pos(), site, sym.name, true); |
2994 |
} |
|
2995 |
} |
|
5002
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2996 |
} else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) { |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2997 |
// If the qualified item is not a type and the selected item is static, report |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2998 |
// a warning. Make allowance for the class of an array type e.g. Object[].class) |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2999 |
chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner); |
10 | 3000 |
} |
3001 |
||
3002 |
// If we are selecting an instance member via a `super', ... |
|
3003 |
if (env.info.selectSuper && (sym.flags() & STATIC) == 0) { |
|
3004 |
||
3005 |
// Check that super-qualified symbols are not abstract (JLS) |
|
3006 |
rs.checkNonAbstract(tree.pos(), sym); |
|
3007 |
||
3008 |
if (site.isRaw()) { |
|
3009 |
// Determine argument types for site. |
|
3010 |
Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym); |
|
3011 |
if (site1 != null) site = site1; |
|
3012 |
} |
|
3013 |
} |
|
3014 |
||
3015 |
env.info.selectSuper = selectSuperPrev; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3016 |
result = checkId(tree, site, sym, env, resultInfo); |
10 | 3017 |
} |
3018 |
//where |
|
3019 |
/** Determine symbol referenced by a Select expression, |
|
3020 |
* |
|
3021 |
* @param tree The select tree. |
|
3022 |
* @param site The type of the selected expression, |
|
3023 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3024 |
* @param resultInfo The current result. |
10 | 3025 |
*/ |
3026 |
private Symbol selectSym(JCFieldAccess tree, |
|
8045 | 3027 |
Symbol location, |
10 | 3028 |
Type site, |
3029 |
Env<AttrContext> env, |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3030 |
ResultInfo resultInfo) { |
10 | 3031 |
DiagnosticPosition pos = tree.pos(); |
3032 |
Name name = tree.name; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3033 |
switch (site.getTag()) { |
10 | 3034 |
case PACKAGE: |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3035 |
return rs.accessBase( |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3036 |
rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), |
8045 | 3037 |
pos, location, site, name, true); |
10 | 3038 |
case ARRAY: |
3039 |
case CLASS: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3040 |
if (resultInfo.pt.hasTag(METHOD) || resultInfo.pt.hasTag(FORALL)) { |
10 | 3041 |
return rs.resolveQualifiedMethod( |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3042 |
pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments()); |
10 | 3043 |
} else if (name == names._this || name == names._super) { |
3044 |
return rs.resolveSelf(pos, env, site.tsym, name); |
|
3045 |
} else if (name == names._class) { |
|
3046 |
// In this case, we have already made sure in |
|
3047 |
// visitSelect that qualifier expression is a type. |
|
3048 |
Type t = syms.classType; |
|
3049 |
List<Type> typeargs = allowGenerics |
|
3050 |
? List.of(types.erasure(site)) |
|
3051 |
: List.<Type>nil(); |
|
3052 |
t = new ClassType(t.getEnclosingType(), typeargs, t.tsym); |
|
3053 |
return new VarSymbol( |
|
3054 |
STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
|
3055 |
} else { |
|
3056 |
// We are seeing a plain identifier as selector. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3057 |
Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3058 |
if ((resultInfo.pkind & ERRONEOUS) == 0) |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3059 |
sym = rs.accessBase(sym, pos, location, site, name, true); |
10 | 3060 |
return sym; |
3061 |
} |
|
3062 |
case WILDCARD: |
|
3063 |
throw new AssertionError(tree); |
|
3064 |
case TYPEVAR: |
|
3065 |
// Normally, site.getUpperBound() shouldn't be null. |
|
3066 |
// It should only happen during memberEnter/attribBase |
|
8045 | 3067 |
// when determining the super type which *must* beac |
10 | 3068 |
// done before attributing the type variables. In |
3069 |
// other words, we are seeing this illegal program: |
|
3070 |
// class B<T> extends A<T.foo> {} |
|
3071 |
Symbol sym = (site.getUpperBound() != null) |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3072 |
? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo) |
10 | 3073 |
: null; |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
3074 |
if (sym == null) { |
10 | 3075 |
log.error(pos, "type.var.cant.be.deref"); |
3076 |
return syms.errSymbol; |
|
3077 |
} else { |
|
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
3078 |
Symbol sym2 = (sym.flags() & Flags.PRIVATE) != 0 ? |
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
3079 |
rs.new AccessError(env, site, sym) : |
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
3080 |
sym; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3081 |
rs.accessBase(sym2, pos, location, site, name, true); |
10 | 3082 |
return sym; |
3083 |
} |
|
3084 |
case ERROR: |
|
3085 |
// preserve identifier names through errors |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
3086 |
return types.createErrorType(name, site.tsym, site).tsym; |
10 | 3087 |
default: |
3088 |
// The qualifier expression is of a primitive type -- only |
|
3089 |
// .class is allowed for these. |
|
3090 |
if (name == names._class) { |
|
3091 |
// In this case, we have already made sure in Select that |
|
3092 |
// qualifier expression is a type. |
|
3093 |
Type t = syms.classType; |
|
3094 |
Type arg = types.boxedClass(site).type; |
|
3095 |
t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym); |
|
3096 |
return new VarSymbol( |
|
3097 |
STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
|
3098 |
} else { |
|
3099 |
log.error(pos, "cant.deref", site); |
|
3100 |
return syms.errSymbol; |
|
3101 |
} |
|
3102 |
} |
|
3103 |
} |
|
3104 |
||
3105 |
/** Determine type of identifier or select expression and check that |
|
3106 |
* (1) the referenced symbol is not deprecated |
|
3107 |
* (2) the symbol's type is safe (@see checkSafe) |
|
3108 |
* (3) if symbol is a variable, check that its type and kind are |
|
3109 |
* compatible with the prototype and protokind. |
|
3110 |
* (4) if symbol is an instance field of a raw type, |
|
3111 |
* which is being assigned to, issue an unchecked warning if its |
|
3112 |
* type changes under erasure. |
|
3113 |
* (5) if symbol is an instance method of a raw type, issue an |
|
3114 |
* unchecked warning if its argument types change under erasure. |
|
3115 |
* If checks succeed: |
|
3116 |
* If symbol is a constant, return its constant type |
|
3117 |
* else if symbol is a method, return its result type |
|
3118 |
* otherwise return its type. |
|
3119 |
* Otherwise return errType. |
|
3120 |
* |
|
3121 |
* @param tree The syntax tree representing the identifier |
|
3122 |
* @param site If this is a select, the type of the selected |
|
3123 |
* expression, otherwise the type of the current class. |
|
3124 |
* @param sym The symbol representing the identifier. |
|
3125 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3126 |
* @param resultInfo The expected result |
10 | 3127 |
*/ |
3128 |
Type checkId(JCTree tree, |
|
3129 |
Type site, |
|
3130 |
Symbol sym, |
|
3131 |
Env<AttrContext> env, |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3132 |
ResultInfo resultInfo) { |
14547 | 3133 |
return (resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD)) ? |
3134 |
checkMethodId(tree, site, sym, env, resultInfo) : |
|
3135 |
checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo); |
|
3136 |
} |
|
3137 |
||
3138 |
Type checkMethodId(JCTree tree, |
|
3139 |
Type site, |
|
3140 |
Symbol sym, |
|
3141 |
Env<AttrContext> env, |
|
3142 |
ResultInfo resultInfo) { |
|
3143 |
boolean isPolymorhicSignature = |
|
3144 |
sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types); |
|
3145 |
return isPolymorhicSignature ? |
|
3146 |
checkSigPolyMethodId(tree, site, sym, env, resultInfo) : |
|
3147 |
checkMethodIdInternal(tree, site, sym, env, resultInfo); |
|
3148 |
} |
|
3149 |
||
3150 |
Type checkSigPolyMethodId(JCTree tree, |
|
3151 |
Type site, |
|
3152 |
Symbol sym, |
|
3153 |
Env<AttrContext> env, |
|
3154 |
ResultInfo resultInfo) { |
|
3155 |
//recover original symbol for signature polymorphic methods |
|
3156 |
checkMethodIdInternal(tree, site, sym.baseSymbol(), env, resultInfo); |
|
3157 |
env.info.pendingResolutionPhase = Resolve.MethodResolutionPhase.BASIC; |
|
3158 |
return sym.type; |
|
3159 |
} |
|
3160 |
||
3161 |
Type checkMethodIdInternal(JCTree tree, |
|
3162 |
Type site, |
|
3163 |
Symbol sym, |
|
3164 |
Env<AttrContext> env, |
|
3165 |
ResultInfo resultInfo) { |
|
3166 |
Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)); |
|
3167 |
Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo); |
|
3168 |
resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); |
|
3169 |
return owntype; |
|
3170 |
} |
|
3171 |
||
3172 |
Type checkIdInternal(JCTree tree, |
|
3173 |
Type site, |
|
3174 |
Symbol sym, |
|
3175 |
Type pt, |
|
3176 |
Env<AttrContext> env, |
|
3177 |
ResultInfo resultInfo) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3178 |
if (pt.isErroneous()) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3179 |
return types.createErrorType(site); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3180 |
} |
10 | 3181 |
Type owntype; // The computed type of this identifier occurrence. |
3182 |
switch (sym.kind) { |
|
3183 |
case TYP: |
|
3184 |
// For types, the computed type equals the symbol's type, |
|
3185 |
// except for two situations: |
|
3186 |
owntype = sym.type; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3187 |
if (owntype.hasTag(CLASS)) { |
14369
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14366
diff
changeset
|
3188 |
chk.checkForBadAuxiliaryClassAccess(tree.pos(), env, (ClassSymbol)sym); |
10 | 3189 |
Type ownOuter = owntype.getEnclosingType(); |
3190 |
||
3191 |
// (a) If the symbol's type is parameterized, erase it |
|
3192 |
// because no type parameters were given. |
|
3193 |
// We recover generic outer type later in visitTypeApply. |
|
3194 |
if (owntype.tsym.type.getTypeArguments().nonEmpty()) { |
|
3195 |
owntype = types.erasure(owntype); |
|
3196 |
} |
|
3197 |
||
3198 |
// (b) If the symbol's type is an inner class, then |
|
3199 |
// we have to interpret its outer type as a superclass |
|
3200 |
// of the site type. Example: |
|
3201 |
// |
|
3202 |
// class Tree<A> { class Visitor { ... } } |
|
3203 |
// class PointTree extends Tree<Point> { ... } |
|
3204 |
// ...PointTree.Visitor... |
|
3205 |
// |
|
3206 |
// Then the type of the last expression above is |
|
3207 |
// Tree<Point>.Visitor. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3208 |
else if (ownOuter.hasTag(CLASS) && site != ownOuter) { |
10 | 3209 |
Type normOuter = site; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3210 |
if (normOuter.hasTag(CLASS)) |
10 | 3211 |
normOuter = types.asEnclosingSuper(site, ownOuter.tsym); |
3212 |
if (normOuter == null) // perhaps from an import |
|
3213 |
normOuter = types.erasure(ownOuter); |
|
3214 |
if (normOuter != ownOuter) |
|
3215 |
owntype = new ClassType( |
|
3216 |
normOuter, List.<Type>nil(), owntype.tsym); |
|
3217 |
} |
|
3218 |
} |
|
3219 |
break; |
|
3220 |
case VAR: |
|
3221 |
VarSymbol v = (VarSymbol)sym; |
|
3222 |
// Test (4): if symbol is an instance field of a raw type, |
|
3223 |
// which is being assigned to, issue an unchecked warning if |
|
3224 |
// its type changes under erasure. |
|
3225 |
if (allowGenerics && |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3226 |
resultInfo.pkind == VAR && |
10 | 3227 |
v.owner.kind == TYP && |
3228 |
(v.flags() & STATIC) == 0 && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3229 |
(site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
10 | 3230 |
Type s = types.asOuterSuper(site, v.owner); |
3231 |
if (s != null && |
|
3232 |
s.isRaw() && |
|
3233 |
!types.isSameType(v.type, v.erasure(types))) { |
|
3234 |
chk.warnUnchecked(tree.pos(), |
|
3235 |
"unchecked.assign.to.var", |
|
3236 |
v, s); |
|
3237 |
} |
|
3238 |
} |
|
3239 |
// The computed type of a variable is the type of the |
|
3240 |
// variable symbol, taken as a member of the site type. |
|
3241 |
owntype = (sym.owner.kind == TYP && |
|
3242 |
sym.name != names._this && sym.name != names._super) |
|
3243 |
? types.memberType(site, sym) |
|
3244 |
: sym.type; |
|
3245 |
||
3246 |
// If the variable is a constant, record constant value in |
|
3247 |
// computed type. |
|
3248 |
if (v.getConstValue() != null && isStaticReference(tree)) |
|
3249 |
owntype = owntype.constType(v.getConstValue()); |
|
3250 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3251 |
if (resultInfo.pkind == VAL) { |
10 | 3252 |
owntype = capture(owntype); // capture "names as expressions" |
3253 |
} |
|
3254 |
break; |
|
3255 |
case MTH: { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3256 |
owntype = checkMethod(site, sym, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3257 |
new ResultInfo(VAL, resultInfo.pt.getReturnType(), resultInfo.checkContext), |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
3258 |
env, TreeInfo.args(env.tree), resultInfo.pt.getParameterTypes(), |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3259 |
resultInfo.pt.getTypeArguments()); |
10 | 3260 |
break; |
3261 |
} |
|
3262 |
case PCK: case ERR: |
|
3263 |
owntype = sym.type; |
|
3264 |
break; |
|
3265 |
default: |
|
3266 |
throw new AssertionError("unexpected kind: " + sym.kind + |
|
3267 |
" in tree " + tree); |
|
3268 |
} |
|
3269 |
||
3270 |
// Test (1): emit a `deprecation' warning if symbol is deprecated. |
|
3271 |
// (for constructors, the error was given when the constructor was |
|
3272 |
// resolved) |
|
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
3273 |
|
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
3274 |
if (sym.name != names.init) { |
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
3275 |
chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym); |
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
3276 |
chk.checkSunAPI(tree.pos(), sym); |
15724 | 3277 |
chk.checkProfile(tree.pos(), sym); |
3661 | 3278 |
} |
10 | 3279 |
|
3280 |
// Test (3): if symbol is a variable, check that its type and |
|
3281 |
// kind are compatible with the prototype and protokind. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3282 |
return check(tree, owntype, sym.kind, resultInfo); |
10 | 3283 |
} |
3284 |
||
3285 |
/** Check that variable is initialized and evaluate the variable's |
|
3286 |
* initializer, if not yet done. Also check that variable is not |
|
3287 |
* referenced before it is defined. |
|
3288 |
* @param tree The tree making up the variable reference. |
|
3289 |
* @param env The current environment. |
|
3290 |
* @param v The variable's symbol. |
|
3291 |
*/ |
|
3292 |
private void checkInit(JCTree tree, |
|
3293 |
Env<AttrContext> env, |
|
3294 |
VarSymbol v, |
|
3295 |
boolean onlyWarning) { |
|
3296 |
// System.err.println(v + " " + ((v.flags() & STATIC) != 0) + " " + |
|
3297 |
// tree.pos + " " + v.pos + " " + |
|
3298 |
// Resolve.isStatic(env));//DEBUG |
|
3299 |
||
3300 |
// A forward reference is diagnosed if the declaration position |
|
3301 |
// of the variable is greater than the current tree position |
|
3302 |
// and the tree and variable definition occur in the same class |
|
3303 |
// definition. Note that writes don't count as references. |
|
3304 |
// This check applies only to class and instance |
|
3305 |
// variables. Local variables follow different scope rules, |
|
3306 |
// and are subject to definite assignment checking. |
|
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
3307 |
if ((env.info.enclVar == v || v.pos > tree.pos) && |
10 | 3308 |
v.owner.kind == TYP && |
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
13438
diff
changeset
|
3309 |
canOwnInitializer(owner(env)) && |
10 | 3310 |
v.owner == env.info.scope.owner.enclClass() && |
3311 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && |
|
10950 | 3312 |
(!env.tree.hasTag(ASSIGN) || |
10 | 3313 |
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
3314 |
String suffix = (env.info.enclVar == v) ? |
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
3315 |
"self.ref" : "forward.ref"; |
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3316 |
if (!onlyWarning || isStaticEnumField(v)) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
3317 |
log.error(tree.pos(), "illegal." + suffix); |
10 | 3318 |
} else if (useBeforeDeclarationWarning) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
3319 |
log.warning(tree.pos(), suffix, v); |
10 | 3320 |
} |
3321 |
} |
|
3322 |
||
3323 |
v.getConstValue(); // ensure initializer is evaluated |
|
3324 |
||
3325 |
checkEnumInitializer(tree, env, v); |
|
3326 |
} |
|
3327 |
||
3328 |
/** |
|
3329 |
* Check for illegal references to static members of enum. In |
|
3330 |
* an enum type, constructors and initializers may not |
|
3331 |
* reference its static members unless they are constant. |
|
3332 |
* |
|
3333 |
* @param tree The tree making up the variable reference. |
|
3334 |
* @param env The current environment. |
|
3335 |
* @param v The variable's symbol. |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9300
diff
changeset
|
3336 |
* @jls section 8.9 Enums |
10 | 3337 |
*/ |
3338 |
private void checkEnumInitializer(JCTree tree, Env<AttrContext> env, VarSymbol v) { |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9300
diff
changeset
|
3339 |
// JLS: |
10 | 3340 |
// |
3341 |
// "It is a compile-time error to reference a static field |
|
3342 |
// of an enum type that is not a compile-time constant |
|
3343 |
// (15.28) from constructors, instance initializer blocks, |
|
3344 |
// or instance variable initializer expressions of that |
|
3345 |
// type. It is a compile-time error for the constructors, |
|
3346 |
// instance initializer blocks, or instance variable |
|
3347 |
// initializer expressions of an enum constant e to refer |
|
3348 |
// to itself or to an enum constant of the same type that |
|
3349 |
// is declared to the right of e." |
|
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3350 |
if (isStaticEnumField(v)) { |
10 | 3351 |
ClassSymbol enclClass = env.info.scope.owner.enclClass(); |
3352 |
||
3353 |
if (enclClass == null || enclClass.owner == null) |
|
3354 |
return; |
|
3355 |
||
3356 |
// See if the enclosing class is the enum (or a |
|
3357 |
// subclass thereof) declaring v. If not, this |
|
3358 |
// reference is OK. |
|
3359 |
if (v.owner != enclClass && !types.isSubtype(enclClass.type, v.owner.type)) |
|
3360 |
return; |
|
3361 |
||
3362 |
// If the reference isn't from an initializer, then |
|
3363 |
// the reference is OK. |
|
3364 |
if (!Resolve.isInitializer(env)) |
|
3365 |
return; |
|
3366 |
||
3367 |
log.error(tree.pos(), "illegal.enum.static.ref"); |
|
3368 |
} |
|
3369 |
} |
|
3370 |
||
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3371 |
/** Is the given symbol a static, non-constant field of an Enum? |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3372 |
* Note: enum literals should not be regarded as such |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3373 |
*/ |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3374 |
private boolean isStaticEnumField(VarSymbol v) { |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3375 |
return Flags.isEnum(v.owner) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3376 |
Flags.isStatic(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3377 |
!Flags.isConstant(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
3378 |
v.name != names._class; |
10 | 3379 |
} |
3380 |
||
3381 |
/** Can the given symbol be the owner of code which forms part |
|
3382 |
* if class initialization? This is the case if the symbol is |
|
3383 |
* a type or field, or if the symbol is the synthetic method. |
|
3384 |
* owning a block. |
|
3385 |
*/ |
|
3386 |
private boolean canOwnInitializer(Symbol sym) { |
|
3387 |
return |
|
3388 |
(sym.kind & (VAR | TYP)) != 0 || |
|
3389 |
(sym.kind == MTH && (sym.flags() & BLOCK) != 0); |
|
3390 |
} |
|
3391 |
||
3392 |
Warner noteWarner = new Warner(); |
|
3393 |
||
3394 |
/** |
|
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
3395 |
* Check that method arguments conform to its instantiation. |
10 | 3396 |
**/ |
3397 |
public Type checkMethod(Type site, |
|
3398 |
Symbol sym, |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3399 |
ResultInfo resultInfo, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3400 |
Env<AttrContext> env, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3401 |
final List<JCExpression> argtrees, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3402 |
List<Type> argtypes, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3403 |
List<Type> typeargtypes) { |
10 | 3404 |
// Test (5): if symbol is an instance method of a raw type, issue |
3405 |
// an unchecked warning if its argument types change under erasure. |
|
3406 |
if (allowGenerics && |
|
3407 |
(sym.flags() & STATIC) == 0 && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3408 |
(site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
10 | 3409 |
Type s = types.asOuterSuper(site, sym.owner); |
3410 |
if (s != null && s.isRaw() && |
|
3411 |
!types.isSameTypes(sym.type.getParameterTypes(), |
|
3412 |
sym.erasure(types).getParameterTypes())) { |
|
3413 |
chk.warnUnchecked(env.tree.pos(), |
|
3414 |
"unchecked.call.mbr.of.raw.type", |
|
3415 |
sym, s); |
|
3416 |
} |
|
3417 |
} |
|
3418 |
||
14547 | 3419 |
if (env.info.defaultSuperCallSite != null) { |
3420 |
for (Type sup : types.interfaces(env.enclClass.type).prepend(types.supertype((env.enclClass.type)))) { |
|
3421 |
if (!sup.tsym.isSubClass(sym.enclClass(), types) || |
|
3422 |
types.isSameType(sup, env.info.defaultSuperCallSite)) continue; |
|
3423 |
List<MethodSymbol> icand_sup = |
|
3424 |
types.interfaceCandidates(sup, (MethodSymbol)sym); |
|
3425 |
if (icand_sup.nonEmpty() && |
|
3426 |
icand_sup.head != sym && |
|
3427 |
icand_sup.head.overrides(sym, icand_sup.head.enclClass(), types, true)) { |
|
3428 |
log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite, |
|
3429 |
diags.fragment("overridden.default", sym, sup)); |
|
3430 |
break; |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3431 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3432 |
} |
14547 | 3433 |
env.info.defaultSuperCallSite = null; |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3434 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3435 |
|
10 | 3436 |
// Compute the identifier's instantiated type. |
3437 |
// For methods, we need to compute the instance type by |
|
3438 |
// Resolve.instantiate from the symbol's type as well as |
|
3439 |
// any type arguments and value arguments. |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3440 |
noteWarner.clear(); |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3441 |
try { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3442 |
Type owntype = rs.checkMethod( |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3443 |
env, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3444 |
site, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3445 |
sym, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3446 |
resultInfo, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3447 |
argtypes, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3448 |
typeargtypes, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3449 |
noteWarner); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3450 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3451 |
return chk.checkMethod(owntype, sym, env, argtrees, argtypes, env.info.lastResolveVarargs(), |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3452 |
noteWarner.hasNonSilentLint(LintCategory.UNCHECKED)); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3453 |
} catch (Infer.InferenceException ex) { |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3454 |
//invalid target type - propagate exception outwards or report error |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3455 |
//depending on the current check context |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3456 |
resultInfo.checkContext.report(env.tree.pos(), ex.getDiagnostic()); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3457 |
return types.createErrorType(site); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3458 |
} catch (Resolve.InapplicableMethodException ex) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3459 |
Assert.error(ex.getDiagnostic().getMessage(Locale.getDefault())); |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3460 |
return null; |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
3461 |
} |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
3462 |
} |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
3463 |
|
10 | 3464 |
public void visitLiteral(JCLiteral tree) { |
3465 |
result = check( |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3466 |
tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo); |
10 | 3467 |
} |
3468 |
//where |
|
3469 |
/** Return the type of a literal with given type tag. |
|
3470 |
*/ |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3471 |
Type litType(TypeTag tag) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3472 |
return (tag == CLASS) ? syms.stringType : syms.typeOfTag[tag.ordinal()]; |
10 | 3473 |
} |
3474 |
||
3475 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3476 |
result = check(tree, syms.typeOfTag[tree.typetag.ordinal()], TYP, resultInfo); |
10 | 3477 |
} |
3478 |
||
3479 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
3480 |
Type etype = attribType(tree.elemtype, env); |
|
3481 |
Type type = new ArrayType(etype, syms.arrayClass); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3482 |
result = check(tree, type, TYP, resultInfo); |
10 | 3483 |
} |
3484 |
||
3485 |
/** Visitor method for parameterized types. |
|
3486 |
* Bound checking is left until later, since types are attributed |
|
3487 |
* before supertype structure is completely known |
|
3488 |
*/ |
|
3489 |
public void visitTypeApply(JCTypeApply tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
3490 |
Type owntype = types.createErrorType(tree.type); |
10 | 3491 |
|
3492 |
// Attribute functor part of application and make sure it's a class. |
|
3493 |
Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env)); |
|
3494 |
||
3495 |
// Attribute type parameters |
|
3496 |
List<Type> actuals = attribTypes(tree.arguments, env); |
|
3497 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3498 |
if (clazztype.hasTag(CLASS)) { |
10 | 3499 |
List<Type> formals = clazztype.tsym.type.getTypeArguments(); |
10198
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
3500 |
if (actuals.isEmpty()) //diamond |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
3501 |
actuals = formals; |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
3502 |
|
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
3503 |
if (actuals.length() == formals.length()) { |
10 | 3504 |
List<Type> a = actuals; |
3505 |
List<Type> f = formals; |
|
3506 |
while (a.nonEmpty()) { |
|
3507 |
a.head = a.head.withTypeVar(f.head); |
|
3508 |
a = a.tail; |
|
3509 |
f = f.tail; |
|
3510 |
} |
|
3511 |
// Compute the proper generic outer |
|
3512 |
Type clazzOuter = clazztype.getEnclosingType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3513 |
if (clazzOuter.hasTag(CLASS)) { |
10 | 3514 |
Type site; |
3149 | 3515 |
JCExpression clazz = TreeInfo.typeIn(tree.clazz); |
10950 | 3516 |
if (clazz.hasTag(IDENT)) { |
10 | 3517 |
site = env.enclClass.sym.type; |
10950 | 3518 |
} else if (clazz.hasTag(SELECT)) { |
3149 | 3519 |
site = ((JCFieldAccess) clazz).selected.type; |
10 | 3520 |
} else throw new AssertionError(""+tree); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3521 |
if (clazzOuter.hasTag(CLASS) && site != clazzOuter) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3522 |
if (site.hasTag(CLASS)) |
10 | 3523 |
site = types.asOuterSuper(site, clazzOuter.tsym); |
3524 |
if (site == null) |
|
3525 |
site = types.erasure(clazzOuter); |
|
3526 |
clazzOuter = site; |
|
3527 |
} |
|
3528 |
} |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
3529 |
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym); |
10 | 3530 |
} else { |
3531 |
if (formals.length() != 0) { |
|
3532 |
log.error(tree.pos(), "wrong.number.type.args", |
|
3533 |
Integer.toString(formals.length())); |
|
3534 |
} else { |
|
3535 |
log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym); |
|
3536 |
} |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
3537 |
owntype = types.createErrorType(tree.type); |
10 | 3538 |
} |
3539 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3540 |
result = check(tree, owntype, TYP, resultInfo); |
10 | 3541 |
} |
3542 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
3543 |
public void visitTypeUnion(JCTypeUnion tree) { |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3544 |
ListBuffer<Type> multicatchTypes = ListBuffer.lb(); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3545 |
ListBuffer<Type> all_multicatchTypes = null; // lazy, only if needed |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3546 |
for (JCExpression typeTree : tree.alternatives) { |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3547 |
Type ctype = attribType(typeTree, env); |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3548 |
ctype = chk.checkType(typeTree.pos(), |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3549 |
chk.checkClassType(typeTree.pos(), ctype), |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3550 |
syms.throwableType); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3551 |
if (!ctype.isErroneous()) { |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
3552 |
//check that alternatives of a union type are pairwise |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3553 |
//unrelated w.r.t. subtyping |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3554 |
if (chk.intersects(ctype, multicatchTypes.toList())) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3555 |
for (Type t : multicatchTypes) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3556 |
boolean sub = types.isSubtype(ctype, t); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3557 |
boolean sup = types.isSubtype(t, ctype); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3558 |
if (sub || sup) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3559 |
//assume 'a' <: 'b' |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3560 |
Type a = sub ? ctype : t; |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3561 |
Type b = sub ? t : ctype; |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3562 |
log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3563 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3564 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3565 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3566 |
multicatchTypes.append(ctype); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3567 |
if (all_multicatchTypes != null) |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3568 |
all_multicatchTypes.append(ctype); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3569 |
} else { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3570 |
if (all_multicatchTypes == null) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3571 |
all_multicatchTypes = ListBuffer.lb(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3572 |
all_multicatchTypes.appendList(multicatchTypes); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3573 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3574 |
all_multicatchTypes.append(ctype); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
3575 |
} |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
3576 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3577 |
Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3578 |
if (t.hasTag(CLASS)) { |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3579 |
List<Type> alternatives = |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3580 |
((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3581 |
t = new UnionClassType((ClassType) t, alternatives); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3582 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
3583 |
tree.type = result = t; |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
3584 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
3585 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3586 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3587 |
attribTypes(tree.bounds, env); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3588 |
tree.type = result = checkIntersection(tree, tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3589 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3590 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3591 |
public void visitTypeParameter(JCTypeParameter tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3592 |
TypeVar typeVar = (TypeVar)tree.type; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3593 |
if (!typeVar.bound.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3594 |
//fixup type-parameter bound computed in 'attribTypeVariables' |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3595 |
typeVar.bound = checkIntersection(tree, tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3596 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3597 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3598 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3599 |
Type checkIntersection(JCTree tree, List<JCExpression> bounds) { |
10 | 3600 |
Set<Type> boundSet = new HashSet<Type>(); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3601 |
if (bounds.nonEmpty()) { |
10 | 3602 |
// accept class or interface or typevar as first bound. |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3603 |
bounds.head.type = checkBase(bounds.head.type, bounds.head, env, false, false, false); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3604 |
boundSet.add(types.erasure(bounds.head.type)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3605 |
if (bounds.head.type.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3606 |
return bounds.head.type; |
1532
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
3607 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3608 |
else if (bounds.head.type.hasTag(TYPEVAR)) { |
10 | 3609 |
// if first bound was a typevar, do not accept further bounds. |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3610 |
if (bounds.tail.nonEmpty()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3611 |
log.error(bounds.tail.head.pos(), |
10 | 3612 |
"type.var.may.not.be.followed.by.other.bounds"); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3613 |
return bounds.head.type; |
10 | 3614 |
} |
3615 |
} else { |
|
3616 |
// if first bound was a class or interface, accept only interfaces |
|
3617 |
// as further bounds. |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3618 |
for (JCExpression bound : bounds.tail) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3619 |
bound.type = checkBase(bound.type, bound, env, false, true, false); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3620 |
if (bound.type.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3621 |
bounds = List.of(bound); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3622 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3623 |
else if (bound.type.hasTag(CLASS)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3624 |
chk.checkNotRepeated(bound.pos(), types.erasure(bound.type), boundSet); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3625 |
} |
10 | 3626 |
} |
3627 |
} |
|
3628 |
} |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3629 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3630 |
if (bounds.length() == 0) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3631 |
return syms.objectType; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3632 |
} else if (bounds.length() == 1) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3633 |
return bounds.head.type; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3634 |
} else { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3635 |
Type owntype = types.makeCompoundType(TreeInfo.types(bounds)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3636 |
if (tree.hasTag(TYPEINTERSECTION)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3637 |
((IntersectionClassType)owntype).intersectionKind = |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3638 |
IntersectionClassType.IntersectionKind.EXPLICIT; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3639 |
} |
10 | 3640 |
// ... the variable's bound is a class type flagged COMPOUND |
3641 |
// (see comment for TypeVar.bound). |
|
3642 |
// In this case, generate a class tree that represents the |
|
3643 |
// bound class, ... |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8622
diff
changeset
|
3644 |
JCExpression extending; |
10 | 3645 |
List<JCExpression> implementing; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3646 |
if (!bounds.head.type.isInterface()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3647 |
extending = bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3648 |
implementing = bounds.tail; |
10 | 3649 |
} else { |
3650 |
extending = null; |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3651 |
implementing = bounds; |
10 | 3652 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3653 |
JCClassDecl cd = make.at(tree).ClassDef( |
10 | 3654 |
make.Modifiers(PUBLIC | ABSTRACT), |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3655 |
names.empty, List.<JCTypeParameter>nil(), |
10 | 3656 |
extending, implementing, List.<JCTree>nil()); |
3657 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3658 |
ClassSymbol c = (ClassSymbol)owntype.tsym; |
8032 | 3659 |
Assert.check((c.flags() & COMPOUND) != 0); |
10 | 3660 |
cd.sym = c; |
3661 |
c.sourcefile = env.toplevel.sourcefile; |
|
3662 |
||
3663 |
// ... and attribute the bound class |
|
3664 |
c.flags_field |= UNATTRIBUTED; |
|
3665 |
Env<AttrContext> cenv = enter.classEnv(cd, env); |
|
3666 |
enter.typeEnvs.put(c, cenv); |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3667 |
attribClass(c); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3668 |
return owntype; |
10 | 3669 |
} |
3670 |
} |
|
3671 |
||
3672 |
public void visitWildcard(JCWildcard tree) { |
|
3673 |
//- System.err.println("visitWildcard("+tree+");");//DEBUG |
|
3674 |
Type type = (tree.kind.kind == BoundKind.UNBOUND) |
|
3675 |
? syms.objectType |
|
3676 |
: attribType(tree.inner, env); |
|
3677 |
result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type), |
|
3678 |
tree.kind.kind, |
|
3679 |
syms.boundClass), |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3680 |
TYP, resultInfo); |
10 | 3681 |
} |
3682 |
||
3683 |
public void visitAnnotation(JCAnnotation tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3684 |
log.error(tree.pos(), "annotation.not.valid.for.type", pt()); |
10 | 3685 |
result = tree.type = syms.errType; |
3686 |
} |
|
3687 |
||
3688 |
public void visitErroneous(JCErroneous tree) { |
|
3689 |
if (tree.errs != null) |
|
3690 |
for (JCTree err : tree.errs) |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3691 |
attribTree(err, env, new ResultInfo(ERR, pt())); |
10 | 3692 |
result = tree.type = syms.errType; |
3693 |
} |
|
3694 |
||
3695 |
/** Default visitor method for all other trees. |
|
3696 |
*/ |
|
3697 |
public void visitTree(JCTree tree) { |
|
3698 |
throw new AssertionError(); |
|
3699 |
} |
|
3700 |
||
8845 | 3701 |
/** |
3702 |
* Attribute an env for either a top level tree or class declaration. |
|
3703 |
*/ |
|
3704 |
public void attrib(Env<AttrContext> env) { |
|
10950 | 3705 |
if (env.tree.hasTag(TOPLEVEL)) |
8845 | 3706 |
attribTopLevel(env); |
3707 |
else |
|
3708 |
attribClass(env.tree.pos(), env.enclClass.sym); |
|
3709 |
} |
|
3710 |
||
3711 |
/** |
|
3712 |
* Attribute a top level tree. These trees are encountered when the |
|
3713 |
* package declaration has annotations. |
|
3714 |
*/ |
|
3715 |
public void attribTopLevel(Env<AttrContext> env) { |
|
3716 |
JCCompilationUnit toplevel = env.toplevel; |
|
3717 |
try { |
|
3718 |
annotate.flush(); |
|
3719 |
chk.validateAnnotations(toplevel.packageAnnotations, toplevel.packge); |
|
3720 |
} catch (CompletionFailure ex) { |
|
3721 |
chk.completionError(toplevel.pos(), ex); |
|
3722 |
} |
|
3723 |
} |
|
3724 |
||
10 | 3725 |
/** Main method: attribute class definition associated with given class symbol. |
3726 |
* reporting completion failures at the given position. |
|
3727 |
* @param pos The source position at which completion errors are to be |
|
3728 |
* reported. |
|
3729 |
* @param c The class symbol whose definition will be attributed. |
|
3730 |
*/ |
|
3731 |
public void attribClass(DiagnosticPosition pos, ClassSymbol c) { |
|
3732 |
try { |
|
3733 |
annotate.flush(); |
|
3734 |
attribClass(c); |
|
3735 |
} catch (CompletionFailure ex) { |
|
3736 |
chk.completionError(pos, ex); |
|
3737 |
} |
|
3738 |
} |
|
3739 |
||
3740 |
/** Attribute class definition associated with given class symbol. |
|
3741 |
* @param c The class symbol whose definition will be attributed. |
|
3742 |
*/ |
|
3743 |
void attribClass(ClassSymbol c) throws CompletionFailure { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3744 |
if (c.type.hasTag(ERROR)) return; |
10 | 3745 |
|
3746 |
// Check for cycles in the inheritance graph, which can arise from |
|
3747 |
// ill-formed class files. |
|
3748 |
chk.checkNonCyclic(null, c.type); |
|
3749 |
||
3750 |
Type st = types.supertype(c.type); |
|
3751 |
if ((c.flags_field & Flags.COMPOUND) == 0) { |
|
3752 |
// First, attribute superclass. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3753 |
if (st.hasTag(CLASS)) |
10 | 3754 |
attribClass((ClassSymbol)st.tsym); |
3755 |
||
3756 |
// Next attribute owner, if it is a class. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3757 |
if (c.owner.kind == TYP && c.owner.type.hasTag(CLASS)) |
10 | 3758 |
attribClass((ClassSymbol)c.owner); |
3759 |
} |
|
3760 |
||
3761 |
// The previous operations might have attributed the current class |
|
3762 |
// if there was a cycle. So we test first whether the class is still |
|
3763 |
// UNATTRIBUTED. |
|
3764 |
if ((c.flags_field & UNATTRIBUTED) != 0) { |
|
3765 |
c.flags_field &= ~UNATTRIBUTED; |
|
3766 |
||
3767 |
// Get environment current at the point of class definition. |
|
3768 |
Env<AttrContext> env = enter.typeEnvs.get(c); |
|
3769 |
||
3770 |
// The info.lint field in the envs stored in enter.typeEnvs is deliberately uninitialized, |
|
3771 |
// because the annotations were not available at the time the env was created. Therefore, |
|
3772 |
// we look up the environment chain for the first enclosing environment for which the |
|
3773 |
// lint value is set. Typically, this is the parent env, but might be further if there |
|
3774 |
// are any envs created as a result of TypeParameter nodes. |
|
3775 |
Env<AttrContext> lintEnv = env; |
|
3776 |
while (lintEnv.info.lint == null) |
|
3777 |
lintEnv = lintEnv.next; |
|
3778 |
||
3779 |
// Having found the enclosing lint value, we can initialize the lint value for this class |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3780 |
env.info.lint = lintEnv.info.lint.augment(c.annotations, c.flags()); |
10 | 3781 |
|
3782 |
Lint prevLint = chk.setLint(env.info.lint); |
|
3783 |
JavaFileObject prev = log.useSource(c.sourcefile); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3784 |
ResultInfo prevReturnRes = env.info.returnResult; |
10 | 3785 |
|
3786 |
try { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3787 |
env.info.returnResult = null; |
10 | 3788 |
// java.lang.Enum may not be subclassed by a non-enum |
3789 |
if (st.tsym == syms.enumSym && |
|
3790 |
((c.flags_field & (Flags.ENUM|Flags.COMPOUND)) == 0)) |
|
3791 |
log.error(env.tree.pos(), "enum.no.subclassing"); |
|
3792 |
||
3793 |
// Enums may not be extended by source-level classes |
|
3794 |
if (st.tsym != null && |
|
3795 |
((st.tsym.flags_field & Flags.ENUM) != 0) && |
|
941
2589047a9c5d
6675483: Javac rejects multiple type-variable bound declarations starting with an enum type
mcimadamore
parents:
939
diff
changeset
|
3796 |
((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0) && |
10 | 3797 |
!target.compilerBootstrap(c)) { |
3798 |
log.error(env.tree.pos(), "enum.types.not.extensible"); |
|
3799 |
} |
|
3800 |
attribClassBody(env, c); |
|
3801 |
||
3802 |
chk.checkDeprecatedAnnotation(env.tree.pos(), c); |
|
3803 |
} finally { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3804 |
env.info.returnResult = prevReturnRes; |
10 | 3805 |
log.useSource(prev); |
3806 |
chk.setLint(prevLint); |
|
3807 |
} |
|
3808 |
||
3809 |
} |
|
3810 |
} |
|
3811 |
||
3812 |
public void visitImport(JCImport tree) { |
|
3813 |
// nothing to do |
|
3814 |
} |
|
3815 |
||
3816 |
/** Finish the attribution of a class. */ |
|
3817 |
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) { |
|
3818 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
8032 | 3819 |
Assert.check(c == tree.sym); |
10 | 3820 |
|
3821 |
// Validate annotations |
|
3822 |
chk.validateAnnotations(tree.mods.annotations, c); |
|
3823 |
||
3824 |
// Validate type parameters, supertype and interfaces. |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
3825 |
attribStats(tree.typarams, env); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3826 |
if (!c.isAnonymous()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3827 |
//already checked if anonymous |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3828 |
chk.validate(tree.typarams, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3829 |
chk.validate(tree.extending, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3830 |
chk.validate(tree.implementing, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3831 |
} |
10 | 3832 |
|
3833 |
// If this is a non-abstract class, check that it has no abstract |
|
3834 |
// methods or unimplemented methods of an implemented interface. |
|
3835 |
if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) { |
|
3836 |
if (!relax) |
|
3837 |
chk.checkAllDefined(tree.pos(), c); |
|
3838 |
} |
|
3839 |
||
3840 |
if ((c.flags() & ANNOTATION) != 0) { |
|
3841 |
if (tree.implementing.nonEmpty()) |
|
3842 |
log.error(tree.implementing.head.pos(), |
|
3843 |
"cant.extend.intf.annotation"); |
|
3844 |
if (tree.typarams.nonEmpty()) |
|
3845 |
log.error(tree.typarams.head.pos(), |
|
3846 |
"intf.annotation.cant.have.type.params"); |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3847 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3848 |
// If this annotation has a @ContainedBy, validate |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3849 |
Attribute.Compound containedBy = c.attribute(syms.containedByType.tsym); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3850 |
if (containedBy != null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3851 |
// get diagnositc position for error reporting |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3852 |
DiagnosticPosition cbPos = getDiagnosticPosition(tree, containedBy.type); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3853 |
Assert.checkNonNull(cbPos); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3854 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3855 |
chk.validateContainedBy(c, containedBy, cbPos); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3856 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3857 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3858 |
// If this annotation has a @ContainerFor, validate |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3859 |
Attribute.Compound containerFor = c.attribute(syms.containerForType.tsym); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3860 |
if (containerFor != null) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3861 |
// get diagnositc position for error reporting |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3862 |
DiagnosticPosition cfPos = getDiagnosticPosition(tree, containerFor.type); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3863 |
Assert.checkNonNull(cfPos); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3864 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3865 |
chk.validateContainerFor(c, containerFor, cfPos); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3866 |
} |
10 | 3867 |
} else { |
3868 |
// Check that all extended classes and interfaces |
|
3869 |
// are compatible (i.e. no two define methods with same arguments |
|
3870 |
// yet different return types). (JLS 8.4.6.3) |
|
3871 |
chk.checkCompatibleSupertypes(tree.pos(), c.type); |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3872 |
if (allowDefaultMethods) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3873 |
chk.checkDefaultMethodClashes(tree.pos(), c.type); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
3874 |
} |
10 | 3875 |
} |
3876 |
||
3877 |
// Check that class does not import the same parameterized interface |
|
3878 |
// with two different argument lists. |
|
3879 |
chk.checkClassBounds(tree.pos(), c.type); |
|
3880 |
||
3881 |
tree.type = c.type; |
|
3882 |
||
8032 | 3883 |
for (List<JCTypeParameter> l = tree.typarams; |
3884 |
l.nonEmpty(); l = l.tail) { |
|
3885 |
Assert.checkNonNull(env.info.scope.lookup(l.head.name).scope); |
|
10 | 3886 |
} |
3887 |
||
3888 |
// Check that a generic class doesn't extend Throwable |
|
3889 |
if (!c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType)) |
|
3890 |
log.error(tree.extending.pos(), "generic.throwable"); |
|
3891 |
||
3892 |
// Check that all methods which implement some |
|
3893 |
// method conform to the method they implement. |
|
3894 |
chk.checkImplementations(tree); |
|
3895 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3896 |
//check that a resource implementing AutoCloseable cannot throw InterruptedException |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3897 |
checkAutoCloseable(tree.pos(), env, c.type); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3898 |
|
10 | 3899 |
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
3900 |
// Attribute declaration |
|
3901 |
attribStat(l.head, env); |
|
3902 |
// Check that declarations in inner classes are not static (JLS 8.1.2) |
|
3903 |
// Make an exception for static constants. |
|
3904 |
if (c.owner.kind != PCK && |
|
3905 |
((c.flags() & STATIC) == 0 || c.name == names.empty) && |
|
3906 |
(TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) { |
|
3907 |
Symbol sym = null; |
|
10950 | 3908 |
if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym; |
10 | 3909 |
if (sym == null || |
3910 |
sym.kind != VAR || |
|
3911 |
((VarSymbol) sym).getConstValue() == null) |
|
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3912 |
log.error(l.head.pos(), "icls.cant.have.static.decl", c); |
10 | 3913 |
} |
3914 |
} |
|
3915 |
||
3916 |
// Check for cycles among non-initial constructors. |
|
3917 |
chk.checkCyclicConstructors(tree); |
|
3918 |
||
3919 |
// Check for cycles among annotation elements. |
|
3920 |
chk.checkNonCyclicElements(tree); |
|
3921 |
||
3922 |
// Check for proper use of serialVersionUID |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3923 |
if (env.info.lint.isEnabled(LintCategory.SERIAL) && |
10 | 3924 |
isSerializable(c) && |
3925 |
(c.flags() & Flags.ENUM) == 0 && |
|
3926 |
(c.flags() & ABSTRACT) == 0) { |
|
3927 |
checkSerialVersionUID(tree, c); |
|
3928 |
} |
|
3929 |
} |
|
3930 |
// where |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3931 |
/** get a diagnostic position for an attribute of Type t, or null if attribute missing */ |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3932 |
private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3933 |
for(List<JCAnnotation> al = tree.mods.annotations; !al.isEmpty(); al = al.tail) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3934 |
if (types.isSameType(al.head.annotationType.type, t)) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3935 |
return al.head.pos(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3936 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3937 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3938 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3939 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
3940 |
|
10 | 3941 |
/** check if a class is a subtype of Serializable, if that is available. */ |
3942 |
private boolean isSerializable(ClassSymbol c) { |
|
3943 |
try { |
|
3944 |
syms.serializableType.complete(); |
|
3945 |
} |
|
3946 |
catch (CompletionFailure e) { |
|
3947 |
return false; |
|
3948 |
} |
|
3949 |
return types.isSubtype(c.type, syms.serializableType); |
|
3950 |
} |
|
3951 |
||
3952 |
/** Check that an appropriate serialVersionUID member is defined. */ |
|
3953 |
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { |
|
3954 |
||
3955 |
// check for presence of serialVersionUID |
|
3956 |
Scope.Entry e = c.members().lookup(names.serialVersionUID); |
|
3957 |
while (e.scope != null && e.sym.kind != VAR) e = e.next(); |
|
3958 |
if (e.scope == null) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3959 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3960 |
tree.pos(), "missing.SVUID", c); |
10 | 3961 |
return; |
3962 |
} |
|
3963 |
||
3964 |
// check that it is static final |
|
3965 |
VarSymbol svuid = (VarSymbol)e.sym; |
|
3966 |
if ((svuid.flags() & (STATIC | FINAL)) != |
|
3967 |
(STATIC | FINAL)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3968 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3969 |
TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); |
10 | 3970 |
|
3971 |
// check that it is long |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3972 |
else if (!svuid.type.hasTag(LONG)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3973 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3974 |
TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); |
10 | 3975 |
|
3976 |
// check constant |
|
3977 |
else if (svuid.getConstValue() == null) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3978 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3979 |
TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); |
10 | 3980 |
} |
3981 |
||
3982 |
private Type capture(Type type) { |
|
3983 |
return types.capture(type); |
|
3984 |
} |
|
3149 | 3985 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3986 |
// <editor-fold desc="post-attribution visitor"> |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3987 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3988 |
/** |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3989 |
* Handle missing types/symbols in an AST. This routine is useful when |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3990 |
* the compiler has encountered some errors (which might have ended up |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3991 |
* terminating attribution abruptly); if the compiler is used in fail-over |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3992 |
* mode (e.g. by an IDE) and the AST contains semantic errors, this routine |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3993 |
* prevents NPE to be progagated during subsequent compilation steps. |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3994 |
*/ |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3995 |
public void postAttr(JCTree tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3996 |
new PostAttrAnalyzer().scan(tree); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3997 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3998 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3999 |
class PostAttrAnalyzer extends TreeScanner { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4000 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4001 |
private void initTypeIfNeeded(JCTree that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4002 |
if (that.type == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4003 |
that.type = syms.unknownType; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4004 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4005 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4006 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4007 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4008 |
public void scan(JCTree tree) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4009 |
if (tree == null) return; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4010 |
if (tree instanceof JCExpression) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4011 |
initTypeIfNeeded(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4012 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4013 |
super.scan(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4014 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4015 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4016 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4017 |
public void visitIdent(JCIdent that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4018 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4019 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4020 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4021 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4022 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4023 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4024 |
public void visitSelect(JCFieldAccess that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4025 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4026 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4027 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4028 |
super.visitSelect(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4029 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4030 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4031 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4032 |
public void visitClassDef(JCClassDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4033 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4034 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4035 |
that.sym = new ClassSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4036 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4037 |
super.visitClassDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4038 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4039 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4040 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4041 |
public void visitMethodDef(JCMethodDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4042 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4043 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4044 |
that.sym = new MethodSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4045 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4046 |
super.visitMethodDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4047 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4048 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4049 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4050 |
public void visitVarDef(JCVariableDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4051 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4052 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4053 |
that.sym = new VarSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4054 |
that.sym.adr = 0; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4055 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4056 |
super.visitVarDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4057 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4058 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4059 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4060 |
public void visitNewClass(JCNewClass that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4061 |
if (that.constructor == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4062 |
that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4063 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4064 |
if (that.constructorType == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4065 |
that.constructorType = syms.unknownType; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4066 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4067 |
super.visitNewClass(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4068 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4069 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4070 |
@Override |
10187 | 4071 |
public void visitAssignop(JCAssignOp that) { |
4072 |
if (that.operator == null) |
|
4073 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
|
4074 |
super.visitAssignop(that); |
|
4075 |
} |
|
4076 |
||
4077 |
@Override |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4078 |
public void visitBinary(JCBinary that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4079 |
if (that.operator == null) |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4080 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4081 |
super.visitBinary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4082 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4083 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4084 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4085 |
public void visitUnary(JCUnary that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4086 |
if (that.operator == null) |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4087 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4088 |
super.visitUnary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4089 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4090 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4091 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4092 |
public void visitReference(JCMemberReference that) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4093 |
super.visitReference(that); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4094 |
if (that.sym == null) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4095 |
that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4096 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4097 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4098 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
4099 |
// </editor-fold> |
10 | 4100 |
} |