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