author | vromero |
Tue, 08 May 2018 17:12:54 -0700 | |
changeset 50061 | 20520a835f48 |
parent 49887 | 39446351e625 |
child 50086 | 66b0f0134aad |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48449
e2b8009bf42c
8191637: Interface with defaults invalid compiler warning for Serializable
jjg
parents:
48246
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, 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; |
|
31 |
import javax.tools.JavaFileObject; |
|
10 | 32 |
|
33 |
import com.sun.source.tree.IdentifierTree; |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
34 |
import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
10 | 35 |
import com.sun.source.tree.MemberSelectTree; |
36 |
import com.sun.source.tree.TreeVisitor; |
|
37 |
import com.sun.source.util.SimpleTreeVisitor; |
|
14258 | 38 |
import com.sun.tools.javac.code.*; |
39 |
import com.sun.tools.javac.code.Lint.LintCategory; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
40 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
41 |
import com.sun.tools.javac.code.Source.Feature; |
14258 | 42 |
import com.sun.tools.javac.code.Symbol.*; |
43 |
import com.sun.tools.javac.code.Type.*; |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
44 |
import com.sun.tools.javac.code.TypeMetadata.Annotations; |
29553
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
45 |
import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError; |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
46 |
import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext; |
14258 | 47 |
import com.sun.tools.javac.comp.Check.CheckContext; |
48 |
import com.sun.tools.javac.comp.DeferredAttr.AttrMode; |
|
49 |
import com.sun.tools.javac.jvm.*; |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
50 |
import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
51 |
import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
52 |
import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArgs; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
53 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
29553
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
54 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
55 |
import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
14258 | 56 |
import com.sun.tools.javac.tree.*; |
57 |
import com.sun.tools.javac.tree.JCTree.*; |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
58 |
import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; |
14258 | 59 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26107
diff
changeset
|
60 |
import com.sun.tools.javac.util.DefinedBy.Api; |
14258 | 61 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
62 |
import com.sun.tools.javac.util.JCDiagnostic.Error; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
63 |
import com.sun.tools.javac.util.JCDiagnostic.Fragment; |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
64 |
import com.sun.tools.javac.util.JCDiagnostic.Warning; |
14258 | 65 |
import com.sun.tools.javac.util.List; |
36526 | 66 |
|
10 | 67 |
import static com.sun.tools.javac.code.Flags.*; |
10950 | 68 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
69 |
import static com.sun.tools.javac.code.Flags.BLOCK; |
|
10 | 70 |
import static com.sun.tools.javac.code.Kinds.*; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
71 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
72 |
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
|
73 |
import static com.sun.tools.javac.code.TypeTag.WILDCARD; |
10950 | 74 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40313
diff
changeset
|
75 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
10 | 76 |
|
77 |
/** This is the main context-dependent analysis phase in GJC. It |
|
78 |
* encompasses name resolution, type checking and constant folding as |
|
79 |
* subtasks. Some subtasks involve auxiliary classes. |
|
80 |
* @see Check |
|
81 |
* @see Resolve |
|
82 |
* @see ConstFold |
|
83 |
* @see Infer |
|
84 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
85 |
* <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
|
86 |
* If you write code that depends on this, you do so at your own risk. |
10 | 87 |
* This code and its internal interfaces are subject to change or |
88 |
* deletion without notice.</b> |
|
89 |
*/ |
|
90 |
public class Attr extends JCTree.Visitor { |
|
22163 | 91 |
protected static final Context.Key<Attr> attrKey = new Context.Key<>(); |
10 | 92 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
93 |
final Names names; |
10 | 94 |
final Log log; |
95 |
final Symtab syms; |
|
96 |
final Resolve rs; |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
97 |
final Operators operators; |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
98 |
final Infer infer; |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
99 |
final Analyzer analyzer; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
100 |
final DeferredAttr deferredAttr; |
10 | 101 |
final Check chk; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
102 |
final Flow flow; |
10 | 103 |
final MemberEnter memberEnter; |
27857 | 104 |
final TypeEnter typeEnter; |
10 | 105 |
final TreeMaker make; |
106 |
final ConstFold cfolder; |
|
107 |
final Enter enter; |
|
108 |
final Target target; |
|
109 |
final Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
110 |
final JCDiagnostic.Factory diags; |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
111 |
final TypeAnnotations typeAnnotations; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
112 |
final DeferredLintHandler deferredLintHandler; |
25007 | 113 |
final TypeEnvs typeEnvs; |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25445
diff
changeset
|
114 |
final Dependencies dependencies; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
115 |
final Annotate annotate; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
116 |
final ArgumentAttr argumentAttr; |
10 | 117 |
|
118 |
public static Attr instance(Context context) { |
|
119 |
Attr instance = context.get(attrKey); |
|
120 |
if (instance == null) |
|
121 |
instance = new Attr(context); |
|
122 |
return instance; |
|
123 |
} |
|
124 |
||
125 |
protected Attr(Context context) { |
|
126 |
context.put(attrKey, this); |
|
127 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
128 |
names = Names.instance(context); |
10 | 129 |
log = Log.instance(context); |
130 |
syms = Symtab.instance(context); |
|
131 |
rs = Resolve.instance(context); |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
132 |
operators = Operators.instance(context); |
10 | 133 |
chk = Check.instance(context); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
134 |
flow = Flow.instance(context); |
10 | 135 |
memberEnter = MemberEnter.instance(context); |
27857 | 136 |
typeEnter = TypeEnter.instance(context); |
10 | 137 |
make = TreeMaker.instance(context); |
138 |
enter = Enter.instance(context); |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
139 |
infer = Infer.instance(context); |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
140 |
analyzer = Analyzer.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
141 |
deferredAttr = DeferredAttr.instance(context); |
10 | 142 |
cfolder = ConstFold.instance(context); |
143 |
target = Target.instance(context); |
|
144 |
types = Types.instance(context); |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
145 |
diags = JCDiagnostic.Factory.instance(context); |
10 | 146 |
annotate = Annotate.instance(context); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
147 |
typeAnnotations = TypeAnnotations.instance(context); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
148 |
deferredLintHandler = DeferredLintHandler.instance(context); |
25007 | 149 |
typeEnvs = TypeEnvs.instance(context); |
25844
48eab270456c
8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents:
25445
diff
changeset
|
150 |
dependencies = Dependencies.instance(context); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
151 |
argumentAttr = ArgumentAttr.instance(context); |
10 | 152 |
|
153 |
Options options = Options.instance(context); |
|
154 |
||
155 |
Source source = Source.instance(context); |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
156 |
allowStringsInSwitch = Feature.STRINGS_IN_SWITCH.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
157 |
allowPoly = Feature.POLY.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
158 |
allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
159 |
allowLambda = Feature.LAMBDA.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
160 |
allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
161 |
allowStaticInterfaceMethods = Feature.STATIC_INTERFACE_METHODS.allowedInSource(source); |
4142 | 162 |
sourceName = source.name; |
6721 | 163 |
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
164 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
165 |
statInfo = new ResultInfo(KindSelector.NIL, Type.noType); |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
166 |
varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
167 |
unknownExprInfo = new ResultInfo(KindSelector.VAL, Type.noType); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
168 |
methodAttrInfo = new MethodAttrInfo(); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
169 |
unknownTypeInfo = new ResultInfo(KindSelector.TYP, Type.noType); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
170 |
unknownTypeExprInfo = new ResultInfo(KindSelector.VAL_TYP, Type.noType); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
171 |
recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); |
10 | 172 |
} |
173 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
174 |
/** Switch: support target-typing inference |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
175 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
176 |
boolean allowPoly; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
177 |
|
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
178 |
/** Switch: support type annotations. |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
179 |
*/ |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
180 |
boolean allowTypeAnnos; |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
181 |
|
14547 | 182 |
/** Switch: support lambda expressions ? |
183 |
*/ |
|
184 |
boolean allowLambda; |
|
185 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
186 |
/** Switch: support default methods ? |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
187 |
*/ |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
188 |
boolean allowDefaultMethods; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
189 |
|
24901
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
190 |
/** Switch: static interface methods enabled? |
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
191 |
*/ |
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
192 |
boolean allowStaticInterfaceMethods; |
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
193 |
|
10 | 194 |
/** |
195 |
* Switch: warn about use of variable before declaration? |
|
196 |
* RFE: 6425594 |
|
197 |
*/ |
|
198 |
boolean useBeforeDeclarationWarning; |
|
199 |
||
3661 | 200 |
/** |
4142 | 201 |
* Switch: allow strings in switch? |
202 |
*/ |
|
203 |
boolean allowStringsInSwitch; |
|
204 |
||
205 |
/** |
|
206 |
* Switch: name of source level; used for error reporting. |
|
207 |
*/ |
|
208 |
String sourceName; |
|
209 |
||
10 | 210 |
/** Check kind and type of given tree against protokind and prototype. |
211 |
* If check succeeds, store type in tree and return it. |
|
212 |
* If check fails, store errType in tree and return it. |
|
213 |
* 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
|
214 |
* It is not necessary in this case since we know that kind and type |
10 | 215 |
* are correct. |
216 |
* |
|
217 |
* @param tree The tree whose kind and type is checked |
|
28336
9a6ae3c3efb5
8066871: java.lang.VerifyError: Bad local variable type - local final String
mcimadamore
parents:
28148
diff
changeset
|
218 |
* @param found The computed type of the tree |
10 | 219 |
* @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
|
220 |
* @param resultInfo The expected result of the tree |
10 | 221 |
*/ |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
222 |
Type check(final JCTree tree, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
223 |
final Type found, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
224 |
final KindSelector ownkind, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
225 |
final ResultInfo resultInfo) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
226 |
InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
25279 | 227 |
Type owntype; |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
228 |
boolean shouldCheck = !found.hasTag(ERROR) && |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
229 |
!resultInfo.pt.hasTag(METHOD) && |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
230 |
!resultInfo.pt.hasTag(FORALL); |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
231 |
if (shouldCheck && !ownkind.subset(resultInfo.pkind)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
232 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
233 |
Errors.UnexpectedType(resultInfo.pkind.kindNames(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
234 |
ownkind.kindNames())); |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
235 |
owntype = types.createErrorType(found); |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
236 |
} else if (allowPoly && inferenceContext.free(found)) { |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
237 |
//delay the check if there are inference variables in the found type |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
238 |
//this means we are dealing with a partially inferred poly expression |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
239 |
owntype = shouldCheck ? resultInfo.pt : found; |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
240 |
if (resultInfo.checkMode.installPostInferenceHook()) { |
35423
36c7b4ec7a8b
8148213: Regression: nested unchecked call does not trigger erasure of return type
mcimadamore
parents:
35350
diff
changeset
|
241 |
inferenceContext.addFreeTypeListener(List.of(found), |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
242 |
instantiatedContext -> { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
243 |
ResultInfo pendingResult = |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
244 |
resultInfo.dup(inferenceContext.asInstType(resultInfo.pt)); |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
245 |
check(tree, inferenceContext.asInstType(found), ownkind, pendingResult); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
246 |
}); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
247 |
} |
25279 | 248 |
} else { |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
249 |
owntype = shouldCheck ? |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
250 |
resultInfo.check(tree, found) : |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
251 |
found; |
10 | 252 |
} |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
253 |
if (resultInfo.checkMode.updateTreeType()) { |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
254 |
tree.type = owntype; |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
255 |
} |
10 | 256 |
return owntype; |
257 |
} |
|
258 |
||
259 |
/** Is given blank final variable assignable, i.e. in a scope where it |
|
260 |
* may be assigned to even though it is final? |
|
261 |
* @param v The blank final variable. |
|
262 |
* @param env The current environment. |
|
263 |
*/ |
|
264 |
boolean isAssignableAsBlankFinal(VarSymbol v, Env<AttrContext> env) { |
|
25846
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
265 |
Symbol owner = env.info.scope.owner; |
10 | 266 |
// owner refers to the innermost variable, method or |
267 |
// initializer block declaration at this point. |
|
268 |
return |
|
269 |
v.owner == owner |
|
270 |
|| |
|
271 |
((owner.name == names.init || // i.e. we are in a constructor |
|
272 |
owner.kind == VAR || // i.e. we are in a variable initializer |
|
273 |
(owner.flags() & BLOCK) != 0) // i.e. we are in an initializer block |
|
274 |
&& |
|
275 |
v.owner == owner.owner |
|
276 |
&& |
|
277 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env)); |
|
278 |
} |
|
279 |
||
280 |
/** Check that variable can be assigned to. |
|
281 |
* @param pos The current source code position. |
|
31751 | 282 |
* @param v The assigned variable |
10 | 283 |
* @param base If the variable is referred to in a Select, the part |
284 |
* to the left of the `.', null otherwise. |
|
285 |
* @param env The current environment. |
|
286 |
*/ |
|
287 |
void checkAssignable(DiagnosticPosition pos, VarSymbol v, JCTree base, Env<AttrContext> env) { |
|
36713
592302b6161b
8027999: Poorly worded error message when attempting to assign to this
alundblad
parents:
36526
diff
changeset
|
288 |
if (v.name == names._this) { |
592302b6161b
8027999: Poorly worded error message when attempting to assign to this
alundblad
parents:
36526
diff
changeset
|
289 |
log.error(pos, Errors.CantAssignValToThis); |
592302b6161b
8027999: Poorly worded error message when attempting to assign to this
alundblad
parents:
36526
diff
changeset
|
290 |
} else if ((v.flags() & FINAL) != 0 && |
10 | 291 |
((v.flags() & HASINIT) != 0 |
292 |
|| |
|
293 |
!((base == null || |
|
10950 | 294 |
(base.hasTag(IDENT) && TreeInfo.name(base) == names._this)) && |
10 | 295 |
isAssignableAsBlankFinal(v, env)))) { |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
296 |
if (v.isResourceVariable()) { //TWR resource |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
297 |
log.error(pos, Errors.TryResourceMayNotBeAssigned(v)); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
298 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
299 |
log.error(pos, Errors.CantAssignValToFinalVar(v)); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
300 |
} |
10 | 301 |
} |
302 |
} |
|
303 |
||
304 |
/** Does tree represent a static reference to an identifier? |
|
305 |
* It is assumed that tree is either a SELECT or an IDENT. |
|
306 |
* We have to weed out selects from non-type names here. |
|
307 |
* @param tree The candidate tree. |
|
308 |
*/ |
|
309 |
boolean isStaticReference(JCTree tree) { |
|
10950 | 310 |
if (tree.hasTag(SELECT)) { |
10 | 311 |
Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected); |
312 |
if (lsym == null || lsym.kind != TYP) { |
|
313 |
return false; |
|
314 |
} |
|
315 |
} |
|
316 |
return true; |
|
317 |
} |
|
318 |
||
319 |
/** Is this symbol a type? |
|
320 |
*/ |
|
321 |
static boolean isType(Symbol sym) { |
|
322 |
return sym != null && sym.kind == TYP; |
|
323 |
} |
|
324 |
||
325 |
/** The current `this' symbol. |
|
326 |
* @param env The current environment. |
|
327 |
*/ |
|
328 |
Symbol thisSym(DiagnosticPosition pos, Env<AttrContext> env) { |
|
329 |
return rs.resolveSelf(pos, env, env.enclClass.sym, names._this); |
|
330 |
} |
|
331 |
||
332 |
/** Attribute a parsed identifier. |
|
333 |
* @param tree Parsed identifier name |
|
334 |
* @param topLevel The toplevel to use |
|
335 |
*/ |
|
336 |
public Symbol attribIdent(JCTree tree, JCCompilationUnit topLevel) { |
|
337 |
Env<AttrContext> localEnv = enter.topLevelEnv(topLevel); |
|
338 |
localEnv.enclClass = make.ClassDef(make.Modifiers(0), |
|
339 |
syms.errSymbol.name, |
|
340 |
null, null, null, null); |
|
341 |
localEnv.enclClass.sym = syms.errSymbol; |
|
36526 | 342 |
return attribIdent(tree, localEnv); |
343 |
} |
|
344 |
||
345 |
/** Attribute a parsed identifier. |
|
346 |
* @param tree Parsed identifier name |
|
347 |
* @param env The env to use |
|
348 |
*/ |
|
349 |
public Symbol attribIdent(JCTree tree, Env<AttrContext> env) { |
|
350 |
return tree.accept(identAttributer, env); |
|
10 | 351 |
} |
352 |
// where |
|
353 |
private TreeVisitor<Symbol,Env<AttrContext>> identAttributer = new IdentAttributer(); |
|
354 |
private class IdentAttributer extends SimpleTreeVisitor<Symbol,Env<AttrContext>> { |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26107
diff
changeset
|
355 |
@Override @DefinedBy(Api.COMPILER_TREE) |
10 | 356 |
public Symbol visitMemberSelect(MemberSelectTree node, Env<AttrContext> env) { |
357 |
Symbol site = visit(node.getExpression(), env); |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42828
diff
changeset
|
358 |
if (site.kind == ERR || site.kind == ABSENT_TYP || site.kind == HIDDEN) |
10 | 359 |
return site; |
360 |
Name name = (Name)node.getIdentifier(); |
|
361 |
if (site.kind == PCK) { |
|
362 |
env.toplevel.packge = (PackageSymbol)site; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
363 |
return rs.findIdentInPackage(env, (TypeSymbol)site, name, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
364 |
KindSelector.TYP_PCK); |
10 | 365 |
} else { |
366 |
env.enclClass.sym = (ClassSymbol)site; |
|
367 |
return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); |
|
368 |
} |
|
369 |
} |
|
370 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26107
diff
changeset
|
371 |
@Override @DefinedBy(Api.COMPILER_TREE) |
10 | 372 |
public Symbol visitIdentifier(IdentifierTree node, Env<AttrContext> env) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
373 |
return rs.findIdent(env, (Name)node.getName(), KindSelector.TYP_PCK); |
10 | 374 |
} |
375 |
} |
|
376 |
||
377 |
public Type coerce(Type etype, Type ttype) { |
|
378 |
return cfolder.coerce(etype, ttype); |
|
379 |
} |
|
380 |
||
381 |
public Type attribType(JCTree node, TypeSymbol sym) { |
|
25007 | 382 |
Env<AttrContext> env = typeEnvs.get(sym); |
10 | 383 |
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
|
384 |
return attribTree(node, localEnv, unknownTypeInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
385 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
386 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
387 |
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
|
388 |
// Attribute qualifying package or class. |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
389 |
JCFieldAccess s = (JCFieldAccess)tree.qualid; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
390 |
return attribTree(s.selected, env, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
391 |
new ResultInfo(tree.staticImport ? |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
392 |
KindSelector.TYP : KindSelector.TYP_PCK, |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
393 |
Type.noType)); |
10 | 394 |
} |
395 |
||
396 |
public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) { |
|
397 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
398 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 399 |
try { |
400 |
attribExpr(expr, env); |
|
401 |
} catch (BreakAttr b) { |
|
402 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
403 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
404 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
405 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
406 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
407 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
408 |
} |
10 | 409 |
} finally { |
410 |
breakTree = null; |
|
411 |
log.useSource(prev); |
|
412 |
} |
|
413 |
return env; |
|
414 |
} |
|
415 |
||
416 |
public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) { |
|
417 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
418 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 419 |
try { |
420 |
attribStat(stmt, env); |
|
421 |
} catch (BreakAttr b) { |
|
422 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
423 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
424 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
425 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
426 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
427 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
428 |
} |
10 | 429 |
} finally { |
430 |
breakTree = null; |
|
431 |
log.useSource(prev); |
|
432 |
} |
|
433 |
return env; |
|
434 |
} |
|
435 |
||
436 |
private JCTree breakTree = null; |
|
437 |
||
438 |
private static class BreakAttr extends RuntimeException { |
|
439 |
static final long serialVersionUID = -6924771130405446405L; |
|
440 |
private Env<AttrContext> env; |
|
441 |
private BreakAttr(Env<AttrContext> env) { |
|
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
442 |
this.env = env; |
10 | 443 |
} |
444 |
} |
|
445 |
||
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
446 |
/** |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
447 |
* Mode controlling behavior of Attr.Check |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
448 |
*/ |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
449 |
enum CheckMode { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
450 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
451 |
NORMAL, |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
452 |
|
44392
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
453 |
/** |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
454 |
* Mode signalling 'fake check' - skip tree update. A side-effect of this mode is |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
455 |
* that the captured var cache in {@code InferenceContext} will be used in read-only |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
456 |
* mode when performing inference checks. |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
457 |
*/ |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
458 |
NO_TREE_UPDATE { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
459 |
@Override |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
460 |
public boolean updateTreeType() { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
461 |
return false; |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
462 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
463 |
}, |
44392
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
464 |
/** |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
465 |
* Mode signalling that caller will manage free types in tree decorations. |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
466 |
*/ |
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
467 |
NO_INFERENCE_HOOK { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
468 |
@Override |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
469 |
public boolean installPostInferenceHook() { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
470 |
return false; |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
471 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
472 |
}; |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
473 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
474 |
public boolean updateTreeType() { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
475 |
return true; |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
476 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
477 |
public boolean installPostInferenceHook() { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
478 |
return true; |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
479 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
480 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
481 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
482 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
483 |
class ResultInfo { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
484 |
final KindSelector pkind; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
485 |
final Type pt; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
486 |
final CheckContext checkContext; |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
487 |
final CheckMode checkMode; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
488 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
489 |
ResultInfo(KindSelector pkind, Type pt) { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
490 |
this(pkind, pt, chk.basicHandler, CheckMode.NORMAL); |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
491 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
492 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
493 |
ResultInfo(KindSelector pkind, Type pt, CheckMode checkMode) { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
494 |
this(pkind, pt, chk.basicHandler, checkMode); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
495 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
496 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
497 |
protected ResultInfo(KindSelector pkind, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
498 |
Type pt, CheckContext checkContext) { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
499 |
this(pkind, pt, checkContext, CheckMode.NORMAL); |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
500 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
501 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
502 |
protected ResultInfo(KindSelector pkind, |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
503 |
Type pt, CheckContext checkContext, CheckMode checkMode) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
504 |
this.pkind = pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
505 |
this.pt = pt; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
506 |
this.checkContext = checkContext; |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
507 |
this.checkMode = checkMode; |
12334
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 |
|
44571
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
510 |
/** |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
511 |
* Should {@link Attr#attribTree} use the {@ArgumentAttr} visitor instead of this one? |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
512 |
* @param tree The tree to be type-checked. |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
513 |
* @return true if {@ArgumentAttr} should be used. |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
514 |
*/ |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
515 |
protected boolean needsArgumentAttr(JCTree tree) { return false; } |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
516 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
517 |
protected Type check(final DiagnosticPosition pos, final Type found) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
518 |
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
|
519 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
520 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
521 |
protected ResultInfo dup(Type newPt) { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
522 |
return new ResultInfo(pkind, newPt, checkContext, checkMode); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
523 |
} |
14547 | 524 |
|
525 |
protected ResultInfo dup(CheckContext newContext) { |
|
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
526 |
return new ResultInfo(pkind, pt, newContext, checkMode); |
14547 | 527 |
} |
21488
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
528 |
|
24401
0d793293862a
8028503: javac, for method references a primitive type can be added as a bound
vromero
parents:
24400
diff
changeset
|
529 |
protected ResultInfo dup(Type newPt, CheckContext newContext) { |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
530 |
return new ResultInfo(pkind, newPt, newContext, checkMode); |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
531 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
532 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
533 |
protected ResultInfo dup(Type newPt, CheckContext newContext, CheckMode newMode) { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
534 |
return new ResultInfo(pkind, newPt, newContext, newMode); |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
535 |
} |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
536 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
537 |
protected ResultInfo dup(CheckMode newMode) { |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
538 |
return new ResultInfo(pkind, pt, checkContext, newMode); |
24401
0d793293862a
8028503: javac, for method references a primitive type can be added as a bound
vromero
parents:
24400
diff
changeset
|
539 |
} |
0d793293862a
8028503: javac, for method references a primitive type can be added as a bound
vromero
parents:
24400
diff
changeset
|
540 |
|
21488
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
541 |
@Override |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
542 |
public String toString() { |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
543 |
if (pt != null) { |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
544 |
return pt.toString(); |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
545 |
} else { |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
546 |
return ""; |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
547 |
} |
4a69e26aa999
8025290: javac implicit versus explicit lambda compilation error
vromero
parents:
21480
diff
changeset
|
548 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
549 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
550 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
551 |
class MethodAttrInfo extends ResultInfo { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
552 |
public MethodAttrInfo() { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
553 |
this(chk.basicHandler); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
554 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
555 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
556 |
public MethodAttrInfo(CheckContext checkContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
557 |
super(KindSelector.VAL, Infer.anyPoly, checkContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
558 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
559 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
560 |
@Override |
44571
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
561 |
protected boolean needsArgumentAttr(JCTree tree) { |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
562 |
return true; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
563 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
564 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
565 |
protected ResultInfo dup(Type newPt) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
566 |
throw new IllegalStateException(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
567 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
568 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
569 |
protected ResultInfo dup(CheckContext newContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
570 |
return new MethodAttrInfo(newContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
571 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
572 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
573 |
protected ResultInfo dup(Type newPt, CheckContext newContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
574 |
throw new IllegalStateException(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
575 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
576 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
577 |
protected ResultInfo dup(Type newPt, CheckContext newContext, CheckMode newMode) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
578 |
throw new IllegalStateException(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
579 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
580 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
581 |
protected ResultInfo dup(CheckMode newMode) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
582 |
throw new IllegalStateException(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
583 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
584 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
585 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
586 |
class RecoveryInfo extends ResultInfo { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
587 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
588 |
public RecoveryInfo(final DeferredAttr.DeferredAttrContext deferredAttrContext) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
589 |
super(KindSelector.VAL, Type.recoveryType, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
590 |
new Check.NestedCheckContext(chk.basicHandler) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
591 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
592 |
public DeferredAttr.DeferredAttrContext deferredAttrContext() { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
593 |
return deferredAttrContext; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
594 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
595 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
596 |
public boolean compatible(Type found, Type req, Warner warn) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
597 |
return true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
598 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
599 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
600 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
14547 | 601 |
chk.basicHandler.report(pos, details); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
602 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
603 |
}); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
604 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
605 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
606 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
607 |
final ResultInfo statInfo; |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
608 |
final ResultInfo varAssignmentInfo; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
609 |
final ResultInfo methodAttrInfo; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
610 |
final ResultInfo unknownExprInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
611 |
final ResultInfo unknownTypeInfo; |
16975
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16972
diff
changeset
|
612 |
final ResultInfo unknownTypeExprInfo; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
613 |
final ResultInfo recoveryInfo; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
614 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
615 |
Type pt() { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
616 |
return resultInfo.pt; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
617 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
618 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
619 |
KindSelector pkind() { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
620 |
return resultInfo.pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
621 |
} |
10 | 622 |
|
623 |
/* ************************************************************************ |
|
624 |
* Visitor methods |
|
625 |
*************************************************************************/ |
|
626 |
||
627 |
/** Visitor argument: the current environment. |
|
628 |
*/ |
|
629 |
Env<AttrContext> env; |
|
630 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
631 |
/** Visitor argument: the currently expected attribution result. |
10 | 632 |
*/ |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
633 |
ResultInfo resultInfo; |
10 | 634 |
|
635 |
/** Visitor result: the computed type. |
|
636 |
*/ |
|
637 |
Type result; |
|
638 |
||
639 |
/** Visitor method: attribute a tree, catching any completion failure |
|
640 |
* exceptions. Return the tree's type. |
|
641 |
* |
|
642 |
* @param tree The tree to be visited. |
|
643 |
* @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
|
644 |
* @param resultInfo The result info visitor argument. |
10 | 645 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
646 |
Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
10 | 647 |
Env<AttrContext> prevEnv = this.env; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
648 |
ResultInfo prevResult = this.resultInfo; |
10 | 649 |
try { |
650 |
this.env = env; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
651 |
this.resultInfo = resultInfo; |
44571
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
652 |
if (resultInfo.needsArgumentAttr(tree)) { |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
653 |
result = argumentAttr.attribArg(tree, env); |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
654 |
} else { |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
655 |
tree.accept(this); |
1140b8dad6bb
8177933: Stackoverflow during compilation, starting jdk-9+163
mcimadamore
parents:
44393
diff
changeset
|
656 |
} |
14547 | 657 |
if (tree == breakTree && |
658 |
resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { |
|
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
659 |
throw new BreakAttr(copyEnv(env)); |
14547 | 660 |
} |
10 | 661 |
return result; |
662 |
} catch (CompletionFailure ex) { |
|
663 |
tree.type = syms.errType; |
|
664 |
return chk.completionError(tree.pos(), ex); |
|
665 |
} finally { |
|
666 |
this.env = prevEnv; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
667 |
this.resultInfo = prevResult; |
10 | 668 |
} |
669 |
} |
|
670 |
||
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
671 |
Env<AttrContext> copyEnv(Env<AttrContext> env) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
672 |
Env<AttrContext> newEnv = |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
673 |
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
|
674 |
if (newEnv.outer != null) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
675 |
newEnv.outer = copyEnv(newEnv.outer); |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
676 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
677 |
return newEnv; |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
678 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
679 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
680 |
WriteableScope copyScope(WriteableScope sc) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
681 |
WriteableScope newScope = WriteableScope.create(sc.owner); |
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
682 |
List<Symbol> elemsList = List.nil(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
683 |
for (Symbol sym : sc.getSymbols()) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
684 |
elemsList = elemsList.prepend(sym); |
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
685 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
686 |
for (Symbol s : elemsList) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
687 |
newScope.enter(s); |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
688 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
689 |
return newScope; |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
690 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
691 |
|
10 | 692 |
/** Derived visitor method: attribute an expression tree. |
693 |
*/ |
|
694 |
public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) { |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
695 |
return attribTree(tree, env, new ResultInfo(KindSelector.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
|
696 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
697 |
|
10 | 698 |
/** Derived visitor method: attribute an expression tree with |
699 |
* no constraints on the computed type. |
|
700 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14538
diff
changeset
|
701 |
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
|
702 |
return attribTree(tree, env, unknownExprInfo); |
10 | 703 |
} |
704 |
||
705 |
/** Derived visitor method: attribute a type tree. |
|
706 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14538
diff
changeset
|
707 |
public Type attribType(JCTree tree, Env<AttrContext> env) { |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
708 |
Type result = attribType(tree, env, Type.noType); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
709 |
return result; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
710 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
711 |
|
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
712 |
/** Derived visitor method: attribute a type tree. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
713 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
714 |
Type attribType(JCTree tree, Env<AttrContext> env, Type pt) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
715 |
Type result = attribTree(tree, env, new ResultInfo(KindSelector.TYP, pt)); |
10 | 716 |
return result; |
717 |
} |
|
718 |
||
719 |
/** Derived visitor method: attribute a statement or definition tree. |
|
720 |
*/ |
|
721 |
public Type attribStat(JCTree tree, Env<AttrContext> env) { |
|
45605
8d019eee3515
8181911: Lambda Analyzer causes compile-time error
jlahoda
parents:
45504
diff
changeset
|
722 |
Env<AttrContext> analyzeEnv = analyzer.copyEnvIfNeeded(tree, env); |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
723 |
try { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
724 |
return attribTree(tree, env, statInfo); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
725 |
} finally { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
726 |
analyzer.analyzeIfNeeded(tree, analyzeEnv); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
727 |
} |
10 | 728 |
} |
729 |
||
730 |
/** Attribute a list of expressions, returning a list of types. |
|
731 |
*/ |
|
732 |
List<Type> attribExprs(List<JCExpression> trees, Env<AttrContext> env, Type pt) { |
|
22163 | 733 |
ListBuffer<Type> ts = new ListBuffer<>(); |
10 | 734 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
735 |
ts.append(attribExpr(l.head, env, pt)); |
|
736 |
return ts.toList(); |
|
737 |
} |
|
738 |
||
739 |
/** Attribute a list of statements, returning nothing. |
|
740 |
*/ |
|
741 |
<T extends JCTree> void attribStats(List<T> trees, Env<AttrContext> env) { |
|
742 |
for (List<T> l = trees; l.nonEmpty(); l = l.tail) |
|
743 |
attribStat(l.head, env); |
|
744 |
} |
|
745 |
||
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
746 |
/** Attribute the arguments in a method call, returning the method kind. |
10 | 747 |
*/ |
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
748 |
KindSelector attribArgs(KindSelector initialKind, List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { |
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
749 |
KindSelector kind = initialKind; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
750 |
for (JCExpression arg : trees) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
751 |
Type argtype = chk.checkNonVoid(arg, attribTree(arg, env, allowPoly ? methodAttrInfo : unknownExprInfo)); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
752 |
if (argtype.hasTag(DEFERRED)) { |
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
753 |
kind = KindSelector.of(KindSelector.POLY, kind); |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
754 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
755 |
argtypes.append(argtype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
756 |
} |
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
757 |
return kind; |
10 | 758 |
} |
759 |
||
760 |
/** 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
|
761 |
* Caller is responsible for calling checkRefTypes. |
10 | 762 |
*/ |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
763 |
List<Type> attribAnyTypes(List<JCExpression> trees, Env<AttrContext> env) { |
22163 | 764 |
ListBuffer<Type> argtypes = new ListBuffer<>(); |
10 | 765 |
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
|
766 |
argtypes.append(attribType(l.head, env)); |
10 | 767 |
return argtypes.toList(); |
768 |
} |
|
769 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
770 |
/** 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
|
771 |
* Check that all the types are references. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
772 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
773 |
List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
774 |
List<Type> types = attribAnyTypes(trees, env); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
775 |
return chk.checkRefTypes(trees, types); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
776 |
} |
10 | 777 |
|
778 |
/** |
|
779 |
* Attribute type variables (of generic classes or methods). |
|
780 |
* Compound types are attributed later in attribBounds. |
|
781 |
* @param typarams the type variables to enter |
|
782 |
* @param env the current environment |
|
783 |
*/ |
|
784 |
void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env) { |
|
785 |
for (JCTypeParameter tvar : typarams) { |
|
786 |
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
|
787 |
a.tsym.flags_field |= UNATTRIBUTED; |
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
788 |
a.bound = Type.noType; |
10 | 789 |
if (!tvar.bounds.isEmpty()) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
790 |
List<Type> bounds = List.of(attribType(tvar.bounds.head, env)); |
10 | 791 |
for (JCExpression bound : tvar.bounds.tail) |
792 |
bounds = bounds.prepend(attribType(bound, env)); |
|
793 |
types.setBounds(a, bounds.reverse()); |
|
794 |
} else { |
|
795 |
// if no bounds are given, assume a single bound of |
|
796 |
// java.lang.Object. |
|
797 |
types.setBounds(a, List.of(syms.objectType)); |
|
798 |
} |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
799 |
a.tsym.flags_field &= ~UNATTRIBUTED; |
10 | 800 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
801 |
for (JCTypeParameter tvar : typarams) { |
10 | 802 |
chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type); |
803 |
} |
|
804 |
} |
|
805 |
||
806 |
/** |
|
807 |
* Attribute the type references in a list of annotations. |
|
808 |
*/ |
|
809 |
void attribAnnotationTypes(List<JCAnnotation> annotations, |
|
810 |
Env<AttrContext> env) { |
|
811 |
for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) { |
|
812 |
JCAnnotation a = al.head; |
|
813 |
attribType(a.annotationType, env); |
|
814 |
} |
|
815 |
} |
|
816 |
||
8225 | 817 |
/** |
818 |
* Attribute a "lazy constant value". |
|
819 |
* @param env The env for the const value |
|
31751 | 820 |
* @param variable The initializer for the const value |
8225 | 821 |
* @param type The expected type, or null |
14259 | 822 |
* @see VarSymbol#setLazyConstValue |
8225 | 823 |
*/ |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
824 |
public Object attribLazyConstantValue(Env<AttrContext> env, |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
825 |
JCVariableDecl variable, |
8225 | 826 |
Type type) { |
827 |
||
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
828 |
DiagnosticPosition prevLintPos |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
829 |
= deferredLintHandler.setPos(variable.pos()); |
8225 | 830 |
|
38607
eb4a0b7e67a1
8154052: Java compiler error displays line from the wrong file
sadayapalam
parents:
38538
diff
changeset
|
831 |
final JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); |
8225 | 832 |
try { |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
833 |
Type itype = attribExpr(variable.init, env, type); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
834 |
if (variable.isImplicitlyTyped()) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
835 |
//fixup local variable type |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
836 |
type = variable.type = variable.sym.type = chk.checkLocalVarType(variable, itype.baseType(), variable.name); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
837 |
} |
18657
2bd14bebdf57
8016099: Some @SuppressWarnings annotations ignored ( unchecked, rawtypes )
vromero
parents:
18644
diff
changeset
|
838 |
if (itype.constValue() != null) { |
8225 | 839 |
return coerce(itype, type).constValue(); |
18657
2bd14bebdf57
8016099: Some @SuppressWarnings annotations ignored ( unchecked, rawtypes )
vromero
parents:
18644
diff
changeset
|
840 |
} else { |
8225 | 841 |
return null; |
18657
2bd14bebdf57
8016099: Some @SuppressWarnings annotations ignored ( unchecked, rawtypes )
vromero
parents:
18644
diff
changeset
|
842 |
} |
8225 | 843 |
} finally { |
38607
eb4a0b7e67a1
8154052: Java compiler error displays line from the wrong file
sadayapalam
parents:
38538
diff
changeset
|
844 |
log.useSource(prevSource); |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
845 |
deferredLintHandler.setPos(prevLintPos); |
8225 | 846 |
} |
847 |
} |
|
848 |
||
10 | 849 |
/** Attribute type reference in an `extends' or `implements' clause. |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
850 |
* Supertypes of anonymous inner classes are usually already attributed. |
10 | 851 |
* |
852 |
* @param tree The tree making up the type reference. |
|
853 |
* @param env The environment current at the reference. |
|
854 |
* @param classExpected true if only a class is expected here. |
|
855 |
* @param interfaceExpected true if only an interface is expected here. |
|
856 |
*/ |
|
857 |
Type attribBase(JCTree tree, |
|
858 |
Env<AttrContext> env, |
|
859 |
boolean classExpected, |
|
860 |
boolean interfaceExpected, |
|
861 |
boolean checkExtensible) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
862 |
Type t = tree.type != null ? |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
863 |
tree.type : |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
864 |
attribType(tree, env); |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
865 |
return checkBase(t, tree, env, classExpected, interfaceExpected, checkExtensible); |
10 | 866 |
} |
867 |
Type checkBase(Type t, |
|
868 |
JCTree tree, |
|
869 |
Env<AttrContext> env, |
|
870 |
boolean classExpected, |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
871 |
boolean interfaceExpected, |
10 | 872 |
boolean checkExtensible) { |
33907
9ee2b1641949
8073616: Duplicate error message: cannot inherit from final (class) F
sadayapalam
parents:
33708
diff
changeset
|
873 |
final DiagnosticPosition pos = tree.hasTag(TYPEAPPLY) ? |
9ee2b1641949
8073616: Duplicate error message: cannot inherit from final (class) F
sadayapalam
parents:
33708
diff
changeset
|
874 |
(((JCTypeApply) tree).clazz).pos() : tree.pos(); |
23809
9405883da95f
8023945: javac wrongly allows a subclass of an anonymous class
pgovereau
parents:
23803
diff
changeset
|
875 |
if (t.tsym.isAnonymous()) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
876 |
log.error(pos, Errors.CantInheritFromAnon); |
23809
9405883da95f
8023945: javac wrongly allows a subclass of an anonymous class
pgovereau
parents:
23803
diff
changeset
|
877 |
return types.createErrorType(t); |
9405883da95f
8023945: javac wrongly allows a subclass of an anonymous class
pgovereau
parents:
23803
diff
changeset
|
878 |
} |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
879 |
if (t.isErroneous()) |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
880 |
return t; |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
881 |
if (t.hasTag(TYPEVAR) && !classExpected && !interfaceExpected) { |
10 | 882 |
// check that type variable is already visible |
883 |
if (t.getUpperBound() == null) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
884 |
log.error(pos, Errors.IllegalForwardRef); |
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
|
885 |
return types.createErrorType(t); |
10 | 886 |
} |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
887 |
} else { |
33907
9ee2b1641949
8073616: Duplicate error message: cannot inherit from final (class) F
sadayapalam
parents:
33708
diff
changeset
|
888 |
t = chk.checkClassType(pos, t, checkExtensible); |
10 | 889 |
} |
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
890 |
if (interfaceExpected && (t.tsym.flags() & INTERFACE) == 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
891 |
log.error(pos, Errors.IntfExpectedHere); |
21009 | 892 |
// return errType is necessary since otherwise there might |
893 |
// be undetected cycles which cause attribution to loop |
|
894 |
return types.createErrorType(t); |
|
10 | 895 |
} else if (checkExtensible && |
896 |
classExpected && |
|
21712
d363f367d4c0
8027439: Compile-time error in the case of ((Integer[] & Serializable)new Integer[1]).getClass()
emc
parents:
21704
diff
changeset
|
897 |
(t.tsym.flags() & INTERFACE) != 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
898 |
log.error(pos, Errors.NoIntfExpectedHere); |
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
|
899 |
return types.createErrorType(t); |
10 | 900 |
} |
901 |
if (checkExtensible && |
|
902 |
((t.tsym.flags() & FINAL) != 0)) { |
|
33907
9ee2b1641949
8073616: Duplicate error message: cannot inherit from final (class) F
sadayapalam
parents:
33708
diff
changeset
|
903 |
log.error(pos, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
904 |
Errors.CantInheritFromFinal(t.tsym)); |
10 | 905 |
} |
33907
9ee2b1641949
8073616: Duplicate error message: cannot inherit from final (class) F
sadayapalam
parents:
33708
diff
changeset
|
906 |
chk.checkNonCyclic(pos, t); |
10 | 907 |
return t; |
908 |
} |
|
909 |
||
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
910 |
Type attribIdentAsEnumType(Env<AttrContext> env, JCIdent id) { |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
911 |
Assert.check((env.enclClass.sym.flags() & ENUM) != 0); |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
912 |
id.type = env.info.scope.owner.enclClass().type; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27857
diff
changeset
|
913 |
id.sym = env.info.scope.owner.enclClass(); |
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
914 |
return id.type; |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
915 |
} |
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
916 |
|
10 | 917 |
public void visitClassDef(JCClassDecl tree) { |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
918 |
Optional<ArgumentAttr.LocalCacheContext> localCacheContext = |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
919 |
Optional.ofNullable(env.info.isSpeculative ? |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
920 |
argumentAttr.withLocalCacheContext() : null); |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
921 |
try { |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
922 |
// Local and anonymous classes have not been entered yet, so we need to |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
923 |
// do it now. |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
924 |
if (env.info.scope.owner.kind.matches(KindSelector.VAL_MTH)) { |
22440
d40c30326317
8028389: NullPointerException compiling annotation values that have bodies
alundblad
parents:
22163
diff
changeset
|
925 |
enter.classEnter(tree, env); |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
926 |
} else { |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
927 |
// If this class declaration is part of a class level annotation, |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
928 |
// as in @MyAnno(new Object() {}) class MyClass {}, enter it in |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
929 |
// order to simplify later steps and allow for sensible error |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
930 |
// messages. |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
931 |
if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree)) |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
932 |
enter.classEnter(tree, env); |
10 | 933 |
} |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
934 |
|
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
935 |
ClassSymbol c = tree.sym; |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
936 |
if (c == null) { |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
937 |
// exit in case something drastic went wrong during enter. |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
938 |
result = null; |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
939 |
} else { |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
940 |
// make sure class has been completed: |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
941 |
c.complete(); |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
942 |
|
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
943 |
// If this class appears as an anonymous class |
41154
ed8625a2f0f1
8166108: VerifyError passing anonymous inner class to supertype constructor
sadayapalam
parents:
40504
diff
changeset
|
944 |
// in a superclass constructor call |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
945 |
// disable implicit outer instance from being passed. |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
946 |
// (This would be an illegal access to "this before super"). |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
947 |
if (env.info.isSelfCall && |
41154
ed8625a2f0f1
8166108: VerifyError passing anonymous inner class to supertype constructor
sadayapalam
parents:
40504
diff
changeset
|
948 |
env.tree.hasTag(NEWCLASS)) { |
35350
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
949 |
c.flags_field |= NOOUTERTHIS; |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
950 |
} |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
951 |
attribClass(tree.pos(), c); |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
952 |
result = tree.type = c.type; |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
953 |
} |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
954 |
} finally { |
5ec1564e7b1f
8147546: regression when type-checking generic calls inside nested declarations occurring in method context
mcimadamore
parents:
35349
diff
changeset
|
955 |
localCacheContext.ifPresent(LocalCacheContext::leave); |
10 | 956 |
} |
957 |
} |
|
958 |
||
959 |
public void visitMethodDef(JCMethodDecl tree) { |
|
960 |
MethodSymbol m = tree.sym; |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14259
diff
changeset
|
961 |
boolean isDefaultMethod = (m.flags() & DEFAULT) != 0; |
10 | 962 |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17805
diff
changeset
|
963 |
Lint lint = env.info.lint.augment(m); |
10 | 964 |
Lint prevLint = chk.setLint(lint); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
965 |
MethodSymbol prevMethod = chk.setMethod(m); |
10 | 966 |
try { |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
967 |
deferredLintHandler.flush(tree.pos()); |
10 | 968 |
chk.checkDeprecatedAnnotation(tree.pos(), m); |
969 |
||
15385 | 970 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
971 |
// Create a new environment with local scope |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
972 |
// for attributing the method. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
973 |
Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
974 |
localEnv.info.lint = lint; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
975 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
976 |
attribStats(tree.typarams, localEnv); |
10 | 977 |
|
978 |
// If we override any other methods, check that we do so properly. |
|
979 |
// JLS ??? |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
980 |
if (m.isStatic()) { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
981 |
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
|
982 |
} else { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
983 |
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
|
984 |
} |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
985 |
chk.checkOverride(env, tree, m); |
10 | 986 |
|
14547 | 987 |
if (isDefaultMethod && types.overridesObjectMethod(m.enclClass(), m)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
988 |
log.error(tree, Errors.DefaultOverridesObjectMember(m.name, Kinds.kindName(m.location()), m.location())); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
989 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
990 |
|
10 | 991 |
// Enter all type parameters into the local method scope. |
992 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
|
993 |
localEnv.info.scope.enterIfAbsent(l.head.type.tsym); |
|
994 |
||
995 |
ClassSymbol owner = env.enclClass.sym; |
|
996 |
if ((owner.flags() & ANNOTATION) != 0 && |
|
44194
c868c8c24e18
8175198: Javac incorrectly allows receiver parameters in annotation methods
vromero
parents:
44184
diff
changeset
|
997 |
(tree.params.nonEmpty() || |
c868c8c24e18
8175198: Javac incorrectly allows receiver parameters in annotation methods
vromero
parents:
44184
diff
changeset
|
998 |
tree.recvparam != null)) |
c868c8c24e18
8175198: Javac incorrectly allows receiver parameters in annotation methods
vromero
parents:
44184
diff
changeset
|
999 |
log.error(tree.params.nonEmpty() ? |
c868c8c24e18
8175198: Javac incorrectly allows receiver parameters in annotation methods
vromero
parents:
44184
diff
changeset
|
1000 |
tree.params.head.pos() : |
c868c8c24e18
8175198: Javac incorrectly allows receiver parameters in annotation methods
vromero
parents:
44184
diff
changeset
|
1001 |
tree.recvparam.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1002 |
Errors.IntfAnnotationMembersCantHaveParams); |
10 | 1003 |
|
1004 |
// Attribute all value parameters. |
|
1005 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
|
1006 |
attribStat(l.head, localEnv); |
|
1007 |
} |
|
1008 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1009 |
chk.checkVarargsMethodDecl(localEnv, tree); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5654
diff
changeset
|
1010 |
|
10 | 1011 |
// Check that type parameters are well-formed. |
1358 | 1012 |
chk.validate(tree.typarams, localEnv); |
10 | 1013 |
|
1014 |
// Check that result type is well-formed. |
|
21896
f39003ba351f
8026374: javac accepts void as a method parameter
jlahoda
parents:
21890
diff
changeset
|
1015 |
if (tree.restype != null && !tree.restype.type.hasTag(VOID)) |
f39003ba351f
8026374: javac accepts void as a method parameter
jlahoda
parents:
21890
diff
changeset
|
1016 |
chk.validate(tree.restype, localEnv); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1017 |
|
15385 | 1018 |
// Check that receiver type is well-formed. |
1019 |
if (tree.recvparam != null) { |
|
1020 |
// Use a new environment to check the receiver parameter. |
|
1021 |
// Otherwise I get "might not have been initialized" errors. |
|
1022 |
// Is there a better way? |
|
1023 |
Env<AttrContext> newEnv = memberEnter.methodEnv(tree, env); |
|
1024 |
attribType(tree.recvparam, newEnv); |
|
1025 |
chk.validate(tree.recvparam, newEnv); |
|
1026 |
} |
|
1027 |
||
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1028 |
// annotation method checks |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1029 |
if ((owner.flags() & ANNOTATION) != 0) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1030 |
// annotation method cannot have throws clause |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1031 |
if (tree.thrown.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1032 |
log.error(tree.thrown.head.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1033 |
Errors.ThrowsNotAllowedInIntfAnnotation); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1034 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1035 |
// annotation method cannot declare type-parameters |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1036 |
if (tree.typarams.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1037 |
log.error(tree.typarams.head.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1038 |
Errors.IntfAnnotationMembersCantHaveTypeParams); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1039 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1040 |
// validate annotation method's return type (could be an annotation type) |
10 | 1041 |
chk.validateAnnotationType(tree.restype); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1042 |
// ensure that annotation method does not clash with members of Object/Annotation |
10 | 1043 |
chk.validateAnnotationMethod(tree.pos(), m); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1044 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
1045 |
|
10 | 1046 |
for (List<JCExpression> l = tree.thrown; l.nonEmpty(); l = l.tail) |
1047 |
chk.checkType(l.head.pos(), l.head.type, syms.throwableType); |
|
1048 |
||
1049 |
if (tree.body == null) { |
|
1050 |
// Empty bodies are only allowed for |
|
1051 |
// abstract, native, or interface methods, or for methods |
|
1052 |
// in a retrofit signature class. |
|
1053 |
if (tree.defaultValue != null) { |
|
1054 |
if ((owner.flags() & ANNOTATION) == 0) |
|
1055 |
log.error(tree.pos(), |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1056 |
Errors.DefaultAllowedInIntfAnnotationMember); |
10 | 1057 |
} |
36153 | 1058 |
if (isDefaultMethod || (tree.sym.flags() & (ABSTRACT | NATIVE)) == 0) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1059 |
log.error(tree.pos(), Errors.MissingMethBodyOrDeclAbstract); |
30845
43ddd58a5a56
8080726: Redundant error message on private abstract interface method with body.
sadayapalam
parents:
30405
diff
changeset
|
1060 |
} else if ((tree.sym.flags() & (ABSTRACT|DEFAULT|PRIVATE)) == ABSTRACT) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1061 |
if ((owner.flags() & INTERFACE) != 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1062 |
log.error(tree.body.pos(), Errors.IntfMethCantHaveBody); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1063 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1064 |
log.error(tree.pos(), Errors.AbstractMethCantHaveBody); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
1065 |
} |
10 | 1066 |
} else if ((tree.mods.flags & NATIVE) != 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1067 |
log.error(tree.pos(), Errors.NativeMethCantHaveBody); |
10 | 1068 |
} else { |
1069 |
// Add an implicit super() call unless an explicit call to |
|
1070 |
// super(...) or this(...) is given |
|
1071 |
// or we are compiling class java.lang.Object. |
|
1072 |
if (tree.name == names.init && owner.type != syms.objectType) { |
|
1073 |
JCBlock body = tree.body; |
|
1074 |
if (body.stats.isEmpty() || |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1075 |
!TreeInfo.isSelfCall(body.stats.head)) { |
10 | 1076 |
body.stats = body.stats. |
27857 | 1077 |
prepend(typeEnter.SuperCall(make.at(body.pos), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1078 |
List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1079 |
List.nil(), |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1080 |
false)); |
10 | 1081 |
} else if ((env.enclClass.sym.flags() & ENUM) != 0 && |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1082 |
(tree.mods.flags & GENERATEDCONSTR) == 0 && |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1083 |
TreeInfo.isSuperCall(body.stats.head)) { |
10 | 1084 |
// enum constructors are not allowed to call super |
1085 |
// directly, so make sure there aren't any super calls |
|
1086 |
// in enum constructors, except in the compiler |
|
1087 |
// generated one. |
|
1088 |
log.error(tree.body.stats.head.pos(), |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1089 |
Errors.CallToSuperNotAllowedInEnumCtor(env.enclClass.sym)); |
10 | 1090 |
} |
1091 |
} |
|
1092 |
||
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1093 |
// Attribute all type annotations in the body |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
1094 |
annotate.queueScanTreeAndTypeAnnotate(tree.body, localEnv, m, null); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1095 |
annotate.flush(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1096 |
|
10 | 1097 |
// Attribute method body. |
1098 |
attribStat(tree.body, localEnv); |
|
1099 |
} |
|
15385 | 1100 |
|
10 | 1101 |
localEnv.info.scope.leave(); |
1102 |
result = tree.type = m.type; |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1103 |
} finally { |
10 | 1104 |
chk.setLint(prevLint); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1105 |
chk.setMethod(prevMethod); |
10 | 1106 |
} |
1107 |
} |
|
1108 |
||
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1109 |
public void visitVarDef(JCVariableDecl tree) { |
10 | 1110 |
// Local variables have not been entered yet, so we need to do it now: |
1111 |
if (env.info.scope.owner.kind == MTH) { |
|
1112 |
if (tree.sym != null) { |
|
1113 |
// parameters have already been entered |
|
1114 |
env.info.scope.enter(tree.sym); |
|
1115 |
} else { |
|
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1116 |
if (tree.isImplicitlyTyped() && (tree.getModifiers().flags & PARAMETER) == 0) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1117 |
if (tree.init == null) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1118 |
//cannot use 'var' without initializer |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1119 |
log.error(tree, Errors.CantInferLocalVarType(tree.name, Fragments.LocalMissingInit)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1120 |
tree.vartype = make.Erroneous(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1121 |
} else { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1122 |
Fragment msg = canInferLocalVarType(tree); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1123 |
if (msg != null) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1124 |
//cannot use 'var' with initializer which require an explicit target |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1125 |
//(e.g. lambda, method reference, array initializer). |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1126 |
log.error(tree, Errors.CantInferLocalVarType(tree.name, msg)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1127 |
tree.vartype = make.Erroneous(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1128 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1129 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1130 |
} |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
1131 |
try { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
1132 |
annotate.blockAnnotations(); |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
1133 |
memberEnter.memberEnter(tree, env); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
1134 |
} finally { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
1135 |
annotate.unblockAnnotations(); |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
1136 |
} |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1137 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1138 |
} else { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1139 |
if (tree.init != null) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1140 |
// Field initializer expression need to be entered. |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
1141 |
annotate.queueScanTreeAndTypeAnnotate(tree.init, env, tree.sym, tree.pos()); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1142 |
annotate.flush(); |
15385 | 1143 |
} |
10 | 1144 |
} |
1145 |
||
1146 |
VarSymbol v = tree.sym; |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17805
diff
changeset
|
1147 |
Lint lint = env.info.lint.augment(v); |
10 | 1148 |
Lint prevLint = chk.setLint(lint); |
1149 |
||
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
1150 |
// 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
|
1151 |
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
|
1152 |
((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
|
1153 |
(tree.sym.flags() & PARAMETER) != 0; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1154 |
chk.validate(tree.vartype, env, !isImplicitLambdaParameter && !tree.isImplicitlyTyped()); |
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
1155 |
|
10 | 1156 |
try { |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
1157 |
v.getConstValue(); // ensure compile-time constant initializer is evaluated |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
1158 |
deferredLintHandler.flush(tree.pos()); |
10 | 1159 |
chk.checkDeprecatedAnnotation(tree.pos(), v); |
1160 |
||
1161 |
if (tree.init != null) { |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
1162 |
if ((v.flags_field & FINAL) == 0 || |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
1163 |
!memberEnter.needsLazyConstValue(tree.init)) { |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
1164 |
// Not a compile-time constant |
10 | 1165 |
// Attribute initializer in a new environment |
1166 |
// with the declared variable as owner. |
|
1167 |
// Check that initializer conforms to variable's declared type. |
|
1168 |
Env<AttrContext> initEnv = memberEnter.initEnv(tree, env); |
|
1169 |
initEnv.info.lint = lint; |
|
1170 |
// In order to catch self-references, we set the variable's |
|
1171 |
// declaration position to maximal possible value, effectively |
|
1172 |
// marking the variable as undefined. |
|
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
1173 |
initEnv.info.enclVar = v; |
10 | 1174 |
attribExpr(tree.init, initEnv, v.type); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1175 |
if (tree.isImplicitlyTyped()) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1176 |
//fixup local variable type |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1177 |
v.type = chk.checkLocalVarType(tree, tree.init.type.baseType(), tree.name); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1178 |
} |
10 | 1179 |
} |
47318
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
1180 |
if (tree.isImplicitlyTyped()) { |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
1181 |
setSyntheticVariableType(tree, v.type); |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
1182 |
} |
10 | 1183 |
} |
1184 |
result = tree.type = v.type; |
|
1185 |
} |
|
1186 |
finally { |
|
1187 |
chk.setLint(prevLint); |
|
1188 |
} |
|
1189 |
} |
|
1190 |
||
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1191 |
Fragment canInferLocalVarType(JCVariableDecl tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1192 |
LocalInitScanner lis = new LocalInitScanner(); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1193 |
lis.scan(tree.init); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1194 |
return lis.badInferenceMsg; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1195 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1196 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1197 |
static class LocalInitScanner extends TreeScanner { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1198 |
Fragment badInferenceMsg = null; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1199 |
boolean needsTarget = true; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1200 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1201 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1202 |
public void visitNewArray(JCNewArray tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1203 |
if (tree.elemtype == null && needsTarget) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1204 |
badInferenceMsg = Fragments.LocalArrayMissingTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1205 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1206 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1207 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1208 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1209 |
public void visitLambda(JCLambda tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1210 |
if (needsTarget) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1211 |
badInferenceMsg = Fragments.LocalLambdaMissingTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1212 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1213 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1214 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1215 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1216 |
public void visitTypeCast(JCTypeCast tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1217 |
boolean prevNeedsTarget = needsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1218 |
try { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1219 |
needsTarget = false; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1220 |
super.visitTypeCast(tree); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1221 |
} finally { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1222 |
needsTarget = prevNeedsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1223 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1224 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1225 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1226 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1227 |
public void visitReference(JCMemberReference tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1228 |
if (needsTarget) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1229 |
badInferenceMsg = Fragments.LocalMrefMissingTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1230 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1231 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1232 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1233 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1234 |
public void visitNewClass(JCNewClass tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1235 |
boolean prevNeedsTarget = needsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1236 |
try { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1237 |
needsTarget = false; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1238 |
super.visitNewClass(tree); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1239 |
} finally { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1240 |
needsTarget = prevNeedsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1241 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1242 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1243 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1244 |
@Override |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1245 |
public void visitApply(JCMethodInvocation tree) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1246 |
boolean prevNeedsTarget = needsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1247 |
try { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1248 |
needsTarget = false; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1249 |
super.visitApply(tree); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1250 |
} finally { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1251 |
needsTarget = prevNeedsTarget; |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1252 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1253 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1254 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1255 |
|
10 | 1256 |
public void visitSkip(JCSkip tree) { |
1257 |
result = null; |
|
1258 |
} |
|
1259 |
||
1260 |
public void visitBlock(JCBlock tree) { |
|
1261 |
if (env.info.scope.owner.kind == TYP) { |
|
1262 |
// Block is a static or instance initializer; |
|
1263 |
// let the owner of the environment be a freshly |
|
1264 |
// created BLOCK-method. |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
1265 |
Symbol fakeOwner = |
15710
5792a085da41
7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents:
15705
diff
changeset
|
1266 |
new MethodSymbol(tree.flags | BLOCK | |
5792a085da41
7166455: javac doesn't set ACC_STRICT bit on <clinit> for strictfp class
vromero
parents:
15705
diff
changeset
|
1267 |
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
|
1268 |
env.info.scope.owner); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
1269 |
final Env<AttrContext> localEnv = |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
1270 |
env.dup(tree, env.info.dup(env.info.scope.dupUnshared(fakeOwner))); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24794
diff
changeset
|
1271 |
|
10 | 1272 |
if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1273 |
// Attribute all type annotations in the block |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
1274 |
annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, localEnv.info.scope.owner, null); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1275 |
annotate.flush(); |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24794
diff
changeset
|
1276 |
attribStats(tree.stats, localEnv); |
15385 | 1277 |
|
17578 | 1278 |
{ |
1279 |
// Store init and clinit type annotations with the ClassSymbol |
|
1280 |
// to allow output in Gen.normalizeDefs. |
|
1281 |
ClassSymbol cs = (ClassSymbol)env.info.scope.owner; |
|
1282 |
List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes(); |
|
1283 |
if ((tree.flags & STATIC) != 0) { |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17805
diff
changeset
|
1284 |
cs.appendClassInitTypeAttributes(tas); |
17578 | 1285 |
} else { |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17805
diff
changeset
|
1286 |
cs.appendInitTypeAttributes(tas); |
17578 | 1287 |
} |
1288 |
} |
|
10 | 1289 |
} else { |
1290 |
// Create a new local environment with a local scope. |
|
1291 |
Env<AttrContext> localEnv = |
|
1292 |
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
|
1293 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1294 |
attribStats(tree.stats, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1295 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1296 |
localEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1297 |
} |
10 | 1298 |
} |
1299 |
result = null; |
|
1300 |
} |
|
1301 |
||
1302 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
1303 |
attribStat(tree.body, env.dup(tree)); |
|
1304 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1305 |
result = null; |
|
1306 |
} |
|
1307 |
||
1308 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
1309 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1310 |
attribStat(tree.body, env.dup(tree)); |
|
1311 |
result = null; |
|
1312 |
} |
|
1313 |
||
1314 |
public void visitForLoop(JCForLoop tree) { |
|
1315 |
Env<AttrContext> loopEnv = |
|
1316 |
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
|
1317 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1318 |
attribStats(tree.init, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1319 |
if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1320 |
loopEnv.tree = tree; // before, we were not in loop! |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1321 |
attribStats(tree.step, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1322 |
attribStat(tree.body, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1323 |
result = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1324 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1325 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1326 |
loopEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1327 |
} |
10 | 1328 |
} |
1329 |
||
1330 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
1331 |
Env<AttrContext> loopEnv = |
|
1332 |
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
|
1333 |
try { |
18379
8dd20756448c
7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
18010
diff
changeset
|
1334 |
//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
|
1335 |
//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
|
1336 |
//the for-each expression first (against original scope). |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24609
diff
changeset
|
1337 |
Type exprType = types.cvarUpperBound(attribExpr(tree.expr, loopEnv)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1338 |
chk.checkNonVoid(tree.pos(), exprType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1339 |
Type elemtype = types.elemtype(exprType); // perhaps expr is an array? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1340 |
if (elemtype == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1341 |
// or perhaps expr implements Iterable<T>? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1342 |
Type base = types.asSuper(exprType, syms.iterableType.tsym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1343 |
if (base == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1344 |
log.error(tree.expr.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1345 |
Errors.ForeachNotApplicableToType(exprType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1346 |
Fragments.TypeReqArrayOrIterable)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1347 |
elemtype = types.createErrorType(exprType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1348 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1349 |
List<Type> iterableParams = base.allparams(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1350 |
elemtype = iterableParams.isEmpty() |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1351 |
? syms.objectType |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24609
diff
changeset
|
1352 |
: types.wildUpperBound(iterableParams.head); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1353 |
} |
10 | 1354 |
} |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1355 |
if (tree.var.isImplicitlyTyped()) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1356 |
Type inferredType = chk.checkLocalVarType(tree.var, elemtype, tree.var.name); |
47318
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
1357 |
setSyntheticVariableType(tree.var, inferredType); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1358 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
1359 |
attribStat(tree.var, loopEnv); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1360 |
chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1361 |
loopEnv.tree = tree; // before, we were not in loop! |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1362 |
attribStat(tree.body, loopEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1363 |
result = null; |
10 | 1364 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1365 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1366 |
loopEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1367 |
} |
10 | 1368 |
} |
1369 |
||
1370 |
public void visitLabelled(JCLabeledStatement tree) { |
|
1371 |
// Check that label is not used in an enclosing statement |
|
1372 |
Env<AttrContext> env1 = env; |
|
10950 | 1373 |
while (env1 != null && !env1.tree.hasTag(CLASSDEF)) { |
1374 |
if (env1.tree.hasTag(LABELLED) && |
|
10 | 1375 |
((JCLabeledStatement) env1.tree).label == tree.label) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1376 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1377 |
Errors.LabelAlreadyInUse(tree.label)); |
10 | 1378 |
break; |
1379 |
} |
|
1380 |
env1 = env1.next; |
|
1381 |
} |
|
1382 |
||
1383 |
attribStat(tree.body, env.dup(tree)); |
|
1384 |
result = null; |
|
1385 |
} |
|
1386 |
||
1387 |
public void visitSwitch(JCSwitch tree) { |
|
1388 |
Type seltype = attribExpr(tree.selector, env); |
|
1389 |
||
1390 |
Env<AttrContext> switchEnv = |
|
1391 |
env.dup(tree, env.info.dup(env.info.scope.dup())); |
|
1392 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1393 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1394 |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1395 |
boolean enumSwitch = (seltype.tsym.flags() & Flags.ENUM) != 0; |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40313
diff
changeset
|
1396 |
boolean stringSwitch = types.isSameType(seltype, syms.stringType); |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40313
diff
changeset
|
1397 |
if (stringSwitch && !allowStringsInSwitch) { |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
1398 |
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.selector.pos(), Feature.STRINGS_IN_SWITCH.error(sourceName)); |
4142 | 1399 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1400 |
if (!enumSwitch && !stringSwitch) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1401 |
seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1402 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1403 |
// Attribute all cases and |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1404 |
// check that there are no duplicate case labels or default clauses. |
22163 | 1405 |
Set<Object> labels = new HashSet<>(); // The set of case labels. |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1406 |
boolean hasDefault = false; // Is there a default label? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1407 |
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
|
1408 |
JCCase c = l.head; |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1409 |
if (c.pat != null) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1410 |
if (enumSwitch) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1411 |
Symbol sym = enumConstant(c.pat, seltype); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1412 |
if (sym == null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1413 |
log.error(c.pat.pos(), Errors.EnumLabelMustBeUnqualifiedEnum); |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1414 |
} else if (!labels.add(sym)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1415 |
log.error(c.pos(), Errors.DuplicateCaseLabel); |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1416 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1417 |
} else { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1418 |
Type pattype = attribExpr(c.pat, switchEnv, seltype); |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1419 |
if (!pattype.hasTag(ERROR)) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1420 |
if (pattype.constValue() == null) { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1421 |
log.error(c.pat.pos(), |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
1422 |
(stringSwitch ? Errors.StringConstReq : Errors.ConstExprReq)); |
29430
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1423 |
} else if (!labels.add(pattype.constValue())) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1424 |
log.error(c.pos(), Errors.DuplicateCaseLabel); |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1425 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1426 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1427 |
} |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1428 |
} else if (hasDefault) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1429 |
log.error(c.pos(), Errors.DuplicateDefaultLabel); |
27553
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1430 |
} else { |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1431 |
hasDefault = true; |
75321debd020
8064362: WriteableScope.dupUnshared misbehaves on shared Scopes
jlahoda
parents:
27551
diff
changeset
|
1432 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1433 |
Env<AttrContext> caseEnv = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1434 |
switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1435 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1436 |
attribStats(c.stats, caseEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1437 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1438 |
caseEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1439 |
addVars(c.stats, switchEnv.info.scope); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1440 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1441 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1442 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1443 |
result = null; |
4142 | 1444 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1445 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1446 |
switchEnv.info.scope.leave(); |
10 | 1447 |
} |
1448 |
} |
|
1449 |
// where |
|
1450 |
/** Add any variables defined in stats to the switch scope. */ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
1451 |
private static void addVars(List<JCStatement> stats, WriteableScope switchScope) { |
10 | 1452 |
for (;stats.nonEmpty(); stats = stats.tail) { |
1453 |
JCTree stat = stats.head; |
|
10950 | 1454 |
if (stat.hasTag(VARDEF)) |
10 | 1455 |
switchScope.enter(((JCVariableDecl) stat).sym); |
1456 |
} |
|
1457 |
} |
|
1458 |
// where |
|
1459 |
/** Return the selected enumeration constant symbol, or null. */ |
|
1460 |
private Symbol enumConstant(JCTree tree, Type enumType) { |
|
29430
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1461 |
if (tree.hasTag(IDENT)) { |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1462 |
JCIdent ident = (JCIdent)tree; |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1463 |
Name name = ident.name; |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1464 |
for (Symbol sym : enumType.tsym.members().getSymbolsByName(name)) { |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1465 |
if (sym.kind == VAR) { |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1466 |
Symbol s = ident.sym = sym; |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1467 |
((VarSymbol)s).getConstValue(); // ensure initializer is evaluated |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1468 |
ident.type = s.type; |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1469 |
return ((s.flags_field & Flags.ENUM) == 0) |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1470 |
? null : s; |
0fc887a8c519
8050021: Improper "duplicate case label" error
sadayapalam
parents:
29292
diff
changeset
|
1471 |
} |
10 | 1472 |
} |
1473 |
} |
|
1474 |
return null; |
|
1475 |
} |
|
1476 |
||
1477 |
public void visitSynchronized(JCSynchronized tree) { |
|
1478 |
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); |
|
1479 |
attribStat(tree.body, env); |
|
1480 |
result = null; |
|
1481 |
} |
|
1482 |
||
1483 |
public void visitTry(JCTry tree) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1484 |
// 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
|
1485 |
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
|
1486 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1487 |
boolean isTryWithResource = tree.resources.nonEmpty(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1488 |
// 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
|
1489 |
Env<AttrContext> tryEnv = isTryWithResource ? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1490 |
env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1491 |
localEnv; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1492 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1493 |
// Attribute resource declarations |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1494 |
for (JCTree resource : tree.resources) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1495 |
CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1496 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1497 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1498 |
chk.basicHandler.report(pos, diags.fragment(Fragments.TryNotApplicableToType(details))); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1499 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1500 |
}; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1501 |
ResultInfo twrResult = |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
1502 |
new ResultInfo(KindSelector.VAR, |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1503 |
syms.autoCloseableType, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1504 |
twrContext); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1505 |
if (resource.hasTag(VARDEF)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1506 |
attribStat(resource, tryEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1507 |
twrResult.check(resource, resource.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1508 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1509 |
//check that resource type cannot throw InterruptedException |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1510 |
checkAutoCloseable(resource.pos(), localEnv, resource.type); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1511 |
|
17557
9c6ace1881fe
8012929: Trees.getElement should work not only for declaration trees, but also for use-trees
jlahoda
parents:
16975
diff
changeset
|
1512 |
VarSymbol var = ((JCVariableDecl) resource).sym; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1513 |
var.setData(ElementKind.RESOURCE_VARIABLE); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1514 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1515 |
attribTree(resource, tryEnv, twrResult); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1516 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1517 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1518 |
// Attribute body |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1519 |
attribStat(tree.body, tryEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1520 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1521 |
if (isTryWithResource) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1522 |
tryEnv.info.scope.leave(); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1523 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1524 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1525 |
// Attribute catch clauses |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1526 |
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
|
1527 |
JCCatch c = l.head; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1528 |
Env<AttrContext> catchEnv = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1529 |
localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1530 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1531 |
Type ctype = attribStat(c.param, catchEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1532 |
if (TreeInfo.isMultiCatch(c)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1533 |
//multi-catch parameter is implicitly marked as final |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1534 |
c.param.sym.flags_field |= FINAL | UNION; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1535 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1536 |
if (c.param.sym.kind == VAR) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1537 |
c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1538 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1539 |
chk.checkType(c.param.vartype.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1540 |
chk.checkClassType(c.param.vartype.pos(), ctype), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1541 |
syms.throwableType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1542 |
attribStat(c.body, catchEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1543 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1544 |
catchEnv.info.scope.leave(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1545 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1546 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1547 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1548 |
// Attribute finalizer |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1549 |
if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1550 |
result = null; |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1551 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1552 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1553 |
localEnv.info.scope.leave(); |
10 | 1554 |
} |
1555 |
} |
|
1556 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1557 |
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
|
1558 |
if (!resource.isErroneous() && |
12013
fdcc73079b81
7148025: javac should not warn about InterrupttedException on the declaration of AutoCloseable itself
darcy
parents:
11144
diff
changeset
|
1559 |
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
|
1560 |
!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
|
1561 |
Symbol close = syms.noSymbol; |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14443
diff
changeset
|
1562 |
Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1563 |
try { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1564 |
close = rs.resolveQualifiedMethod(pos, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1565 |
env, |
41156
251471aec877
8163027: AssertionError while compiling a program that uses try with resources.
sadayapalam
parents:
41154
diff
changeset
|
1566 |
types.skipTypeVars(resource, false), |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1567 |
names.close, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1568 |
List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
1569 |
List.nil()); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1570 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1571 |
finally { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14443
diff
changeset
|
1572 |
log.popDiagnosticHandler(discardHandler); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1573 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1574 |
if (close.kind == MTH && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1575 |
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1576 |
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
|
1577 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1578 |
log.warning(LintCategory.TRY, pos, Warnings.TryResourceThrowsInterruptedExc(resource)); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1579 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1580 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1581 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1582 |
|
10 | 1583 |
public void visitConditional(JCConditional tree) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1584 |
Type condtype = attribExpr(tree.cond, env, syms.booleanType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1585 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1586 |
tree.polyKind = (!allowPoly || |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1587 |
pt().hasTag(NONE) && pt() != Type.recoveryType && pt() != Infer.anyPoly || |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1588 |
isBooleanOrNumeric(env, tree)) ? |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1589 |
PolyKind.STANDALONE : PolyKind.POLY; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1590 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1591 |
if (tree.polyKind == PolyKind.POLY && resultInfo.pt.hasTag(VOID)) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1592 |
//this means we are returning a poly conditional from void-compatible lambda expression |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1593 |
resultInfo.checkContext.report(tree, diags.fragment(Fragments.ConditionalTargetCantBeVoid)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1594 |
result = tree.type = types.createErrorType(resultInfo.pt); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1595 |
return; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1596 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1597 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1598 |
ResultInfo condInfo = tree.polyKind == PolyKind.STANDALONE ? |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1599 |
unknownExprInfo : |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1600 |
resultInfo.dup(conditionalContext(resultInfo.checkContext)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1601 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1602 |
Type truetype = attribTree(tree.truepart, env, condInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1603 |
Type falsetype = attribTree(tree.falsepart, env, condInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1604 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1605 |
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
|
1606 |
if (condtype.constValue() != null && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1607 |
truetype.constValue() != null && |
14953
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14725
diff
changeset
|
1608 |
falsetype.constValue() != null && |
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14725
diff
changeset
|
1609 |
!owntype.hasTag(NONE)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1610 |
//constant folding |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1611 |
owntype = cfolder.coerce(condtype.isTrue() ? truetype : falsetype, owntype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1612 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1613 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
10 | 1614 |
} |
1615 |
//where |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1616 |
private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1617 |
switch (tree.getTag()) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1618 |
case LITERAL: return ((JCLiteral)tree).typetag.isSubRangeOf(DOUBLE) || |
14547 | 1619 |
((JCLiteral)tree).typetag == BOOLEAN || |
1620 |
((JCLiteral)tree).typetag == BOT; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1621 |
case LAMBDA: case REFERENCE: return false; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1622 |
case PARENS: return isBooleanOrNumeric(env, ((JCParens)tree).expr); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1623 |
case CONDEXPR: |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1624 |
JCConditional condTree = (JCConditional)tree; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1625 |
return isBooleanOrNumeric(env, condTree.truepart) && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1626 |
isBooleanOrNumeric(env, condTree.falsepart); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1627 |
case APPLY: |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1628 |
JCMethodInvocation speculativeMethodTree = |
44393
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1629 |
(JCMethodInvocation)deferredAttr.attribSpeculative( |
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1630 |
tree, env, unknownExprInfo, |
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1631 |
argumentAttr.withLocalCacheContext()); |
27551
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1632 |
Symbol msym = TreeInfo.symbol(speculativeMethodTree.meth); |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1633 |
Type receiverType = speculativeMethodTree.meth.hasTag(IDENT) ? |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1634 |
env.enclClass.type : |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1635 |
((JCFieldAccess)speculativeMethodTree.meth).selected.type; |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1636 |
Type owntype = types.memberType(receiverType, msym).getReturnType(); |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1637 |
return primitiveOrBoxed(owntype); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1638 |
case NEWCLASS: |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1639 |
JCExpression className = |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1640 |
removeClassParams.translate(((JCNewClass)tree).clazz); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1641 |
JCExpression speculativeNewClassTree = |
44393
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1642 |
(JCExpression)deferredAttr.attribSpeculative( |
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1643 |
className, env, unknownTypeInfo, |
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1644 |
argumentAttr.withLocalCacheContext()); |
27551
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1645 |
return primitiveOrBoxed(speculativeNewClassTree.type); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1646 |
default: |
44393
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1647 |
Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo, |
ce94820fa9d1
8176714: javac is wrongly assuming that field JCMemberReference.overloadKind has been assigned to
vromero
parents:
44392
diff
changeset
|
1648 |
argumentAttr.withLocalCacheContext()).type; |
27551
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1649 |
return primitiveOrBoxed(speculativeType); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1650 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1651 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1652 |
//where |
27551
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1653 |
boolean primitiveOrBoxed(Type t) { |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1654 |
return (!t.hasTag(TYPEVAR) && types.unboxedTypeOrType(t).isPrimitive()); |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1655 |
} |
14a74a56c4a0
8064464: regression with type inference of conditional expression
mcimadamore
parents:
27231
diff
changeset
|
1656 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1657 |
TreeTranslator removeClassParams = new TreeTranslator() { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1658 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1659 |
public void visitTypeApply(JCTypeApply tree) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1660 |
result = translate(tree.clazz); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1661 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
1662 |
}; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1663 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1664 |
CheckContext conditionalContext(CheckContext checkContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1665 |
return new Check.NestedCheckContext(checkContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1666 |
//this will use enclosing check context to check compatibility of |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1667 |
//subexpression against target type; if we are in a method check context, |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1668 |
//depending on whether boxing is allowed, we could have incompatibilities |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1669 |
@Override |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1670 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1671 |
enclosingContext.report(pos, diags.fragment(Fragments.IncompatibleTypeInConditional(details))); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1672 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1673 |
}; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1674 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
1675 |
|
10 | 1676 |
/** Compute the type of a conditional expression, after |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1677 |
* checking that it exists. See JLS 15.25. Does not take into |
10 | 1678 |
* account the special case where condition and both arms |
1679 |
* are constants. |
|
1680 |
* |
|
1681 |
* @param pos The source position to be used for error |
|
1682 |
* diagnostics. |
|
1683 |
* @param thentype The type of the expression's then-part. |
|
1684 |
* @param elsetype The type of the expression's else-part. |
|
1685 |
*/ |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
1686 |
Type condType(DiagnosticPosition pos, |
10 | 1687 |
Type thentype, Type elsetype) { |
1688 |
// If same type, that is the result |
|
1689 |
if (types.isSameType(thentype, elsetype)) |
|
1690 |
return thentype.baseType(); |
|
1691 |
||
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1692 |
Type thenUnboxed = (thentype.isPrimitive()) |
10 | 1693 |
? thentype : types.unboxedType(thentype); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1694 |
Type elseUnboxed = (elsetype.isPrimitive()) |
10 | 1695 |
? elsetype : types.unboxedType(elsetype); |
1696 |
||
1697 |
// Otherwise, if both arms can be converted to a numeric |
|
1698 |
// type, return the least numeric type that fits both arms |
|
1699 |
// (i.e. return larger of the two, or return int if one |
|
1700 |
// arm is short, the other is char). |
|
1701 |
if (thenUnboxed.isPrimitive() && elseUnboxed.isPrimitive()) { |
|
1702 |
// If one arm has an integer subrange type (i.e., byte, |
|
1703 |
// short, or char), and the other is an integer constant |
|
1704 |
// that fits into the subrange, return the subrange type. |
|
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1705 |
if (thenUnboxed.getTag().isStrictSubRangeOf(INT) && |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1706 |
elseUnboxed.hasTag(INT) && |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1707 |
types.isAssignable(elseUnboxed, thenUnboxed)) { |
10 | 1708 |
return thenUnboxed.baseType(); |
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1709 |
} |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1710 |
if (elseUnboxed.getTag().isStrictSubRangeOf(INT) && |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1711 |
thenUnboxed.hasTag(INT) && |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1712 |
types.isAssignable(thenUnboxed, elseUnboxed)) { |
10 | 1713 |
return elseUnboxed.baseType(); |
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1714 |
} |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1715 |
|
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1716 |
for (TypeTag tag : primitiveTags) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1717 |
Type candidate = syms.typeOfTag[tag.ordinal()]; |
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1718 |
if (types.isSubtype(thenUnboxed, candidate) && |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1719 |
types.isSubtype(elseUnboxed, candidate)) { |
10 | 1720 |
return candidate; |
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1721 |
} |
10 | 1722 |
} |
1723 |
} |
|
1724 |
||
1725 |
// Those were all the cases that could result in a primitive |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1726 |
if (thentype.isPrimitive()) |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1727 |
thentype = types.boxedClass(thentype).type; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1728 |
if (elsetype.isPrimitive()) |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1729 |
elsetype = types.boxedClass(elsetype).type; |
10 | 1730 |
|
1731 |
if (types.isSubtype(thentype, elsetype)) |
|
1732 |
return elsetype.baseType(); |
|
1733 |
if (types.isSubtype(elsetype, thentype)) |
|
1734 |
return thentype.baseType(); |
|
1735 |
||
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1736 |
if (thentype.hasTag(VOID) || elsetype.hasTag(VOID)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1737 |
log.error(pos, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1738 |
Errors.NeitherConditionalSubtype(thentype, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1739 |
elsetype)); |
10 | 1740 |
return thentype.baseType(); |
1741 |
} |
|
1742 |
||
1743 |
// both are known to be reference types. The result is |
|
1744 |
// lub(thentype,elsetype). This cannot fail, as it will |
|
1745 |
// always be possible to infer "Object" if nothing better. |
|
1746 |
return types.lub(thentype.baseType(), elsetype.baseType()); |
|
1747 |
} |
|
1748 |
||
18395
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1749 |
final static TypeTag[] primitiveTags = new TypeTag[]{ |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1750 |
BYTE, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1751 |
CHAR, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1752 |
SHORT, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1753 |
INT, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1754 |
LONG, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1755 |
FLOAT, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1756 |
DOUBLE, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1757 |
BOOLEAN, |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1758 |
}; |
d56a5fbf0b32
8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents:
18393
diff
changeset
|
1759 |
|
10 | 1760 |
public void visitIf(JCIf tree) { |
1761 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1762 |
attribStat(tree.thenpart, env); |
|
1763 |
if (tree.elsepart != null) |
|
1764 |
attribStat(tree.elsepart, env); |
|
1765 |
chk.checkEmptyIf(tree); |
|
1766 |
result = null; |
|
1767 |
} |
|
1768 |
||
1769 |
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
|
1770 |
//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
|
1771 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1772 |
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
|
1773 |
attribExpr(tree.expr, localEnv); |
10 | 1774 |
result = null; |
1775 |
} |
|
1776 |
||
1777 |
public void visitBreak(JCBreak tree) { |
|
1778 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1779 |
result = null; |
|
1780 |
} |
|
1781 |
||
1782 |
public void visitContinue(JCContinue tree) { |
|
1783 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1784 |
result = null; |
|
1785 |
} |
|
1786 |
//where |
|
1787 |
/** Return the target of a break or continue statement, if it exists, |
|
1788 |
* report an error if not. |
|
1789 |
* Note: The target of a labelled break or continue is the |
|
1790 |
* (non-labelled) statement tree referred to by the label, |
|
1791 |
* not the tree representing the labelled statement itself. |
|
1792 |
* |
|
1793 |
* @param pos The position to be used for error diagnostics |
|
1794 |
* @param tag The tag of the jump statement. This is either |
|
1795 |
* Tree.BREAK or Tree.CONTINUE. |
|
1796 |
* @param label The label of the jump statement, or null if no |
|
1797 |
* label is given. |
|
1798 |
* @param env The environment current at the jump statement. |
|
1799 |
*/ |
|
1800 |
private JCTree findJumpTarget(DiagnosticPosition pos, |
|
10950 | 1801 |
JCTree.Tag tag, |
10 | 1802 |
Name label, |
1803 |
Env<AttrContext> env) { |
|
1804 |
// Search environments outwards from the point of jump. |
|
1805 |
Env<AttrContext> env1 = env; |
|
1806 |
LOOP: |
|
1807 |
while (env1 != null) { |
|
1808 |
switch (env1.tree.getTag()) { |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1809 |
case LABELLED: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1810 |
JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1811 |
if (label == labelled.label) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1812 |
// If jump is a continue, check that target is a loop. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1813 |
if (tag == CONTINUE) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1814 |
if (!labelled.body.hasTag(DOLOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1815 |
!labelled.body.hasTag(WHILELOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1816 |
!labelled.body.hasTag(FORLOOP) && |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1817 |
!labelled.body.hasTag(FOREACHLOOP)) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1818 |
log.error(pos, Errors.NotLoopLabel(label)); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1819 |
// Found labelled statement target, now go inwards |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1820 |
// to next non-labelled tree. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1821 |
return TreeInfo.referencedStatement(labelled); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1822 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1823 |
return labelled; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1824 |
} |
10 | 1825 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1826 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1827 |
case DOLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1828 |
case WHILELOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1829 |
case FORLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1830 |
case FOREACHLOOP: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1831 |
if (label == null) return env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1832 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1833 |
case SWITCH: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1834 |
if (label == null && tag == BREAK) return env1.tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1835 |
break; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1836 |
case LAMBDA: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1837 |
case METHODDEF: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1838 |
case CLASSDEF: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1839 |
break LOOP; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1840 |
default: |
10 | 1841 |
} |
1842 |
env1 = env1.next; |
|
1843 |
} |
|
1844 |
if (label != null) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1845 |
log.error(pos, Errors.UndefLabel(label)); |
10950 | 1846 |
else if (tag == CONTINUE) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1847 |
log.error(pos, Errors.ContOutsideLoop); |
10 | 1848 |
else |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1849 |
log.error(pos, Errors.BreakOutsideSwitchLoop); |
10 | 1850 |
return null; |
1851 |
} |
|
1852 |
||
1853 |
public void visitReturn(JCReturn tree) { |
|
1854 |
// Check that there is an enclosing method which is |
|
1855 |
// nested within than the enclosing class. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1856 |
if (env.info.returnResult == null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1857 |
log.error(tree.pos(), Errors.RetOutsideMeth); |
10 | 1858 |
} else { |
1859 |
// Attribute return expression, if it exists, and check that |
|
1860 |
// it conforms to result type of enclosing method. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1861 |
if (tree.expr != null) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1862 |
if (env.info.returnResult.pt.hasTag(VOID)) { |
14547 | 1863 |
env.info.returnResult.checkContext.report(tree.expr.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1864 |
diags.fragment(Fragments.UnexpectedRetVal)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1865 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1866 |
attribTree(tree.expr, env, env.info.returnResult); |
18902 | 1867 |
} else if (!env.info.returnResult.pt.hasTag(VOID) && |
1868 |
!env.info.returnResult.pt.hasTag(NONE)) { |
|
14547 | 1869 |
env.info.returnResult.checkContext.report(tree.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1870 |
diags.fragment(Fragments.MissingRetVal(env.info.returnResult.pt))); |
10 | 1871 |
} |
1872 |
} |
|
1873 |
result = null; |
|
1874 |
} |
|
1875 |
||
1876 |
public void visitThrow(JCThrow tree) { |
|
14547 | 1877 |
Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType); |
1878 |
if (allowPoly) { |
|
1879 |
chk.checkType(tree, owntype, syms.throwableType); |
|
1880 |
} |
|
10 | 1881 |
result = null; |
1882 |
} |
|
1883 |
||
1884 |
public void visitAssert(JCAssert tree) { |
|
1885 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1886 |
if (tree.detail != null) { |
|
1887 |
chk.checkNonVoid(tree.detail.pos(), attribExpr(tree.detail, env)); |
|
1888 |
} |
|
1889 |
result = null; |
|
1890 |
} |
|
1891 |
||
1892 |
/** Visitor method for method invocations. |
|
1893 |
* NOTE: The method part of an application will have in its type field |
|
1894 |
* the return type of the method, not the method's type itself! |
|
1895 |
*/ |
|
1896 |
public void visitApply(JCMethodInvocation tree) { |
|
1897 |
// The local environment of a method application is |
|
1898 |
// a new environment nested in the current one. |
|
1899 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
1900 |
||
1901 |
// The types of the actual method arguments. |
|
1902 |
List<Type> argtypes; |
|
1903 |
||
1904 |
// The types of the actual method type arguments. |
|
1905 |
List<Type> typeargtypes = null; |
|
1906 |
||
1907 |
Name methName = TreeInfo.name(tree.meth); |
|
1908 |
||
1909 |
boolean isConstructorCall = |
|
1910 |
methName == names._this || methName == names._super; |
|
1911 |
||
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
1912 |
ListBuffer<Type> argtypesBuf = new ListBuffer<>(); |
10 | 1913 |
if (isConstructorCall) { |
1914 |
// We are seeing a ...this(...) or ...super(...) call. |
|
1915 |
// Check that this is the first statement in a constructor. |
|
1916 |
if (checkFirstConstructorStat(tree, env)) { |
|
1917 |
||
1918 |
// Record the fact |
|
1919 |
// that this is a constructor call (using isSelfCall). |
|
1920 |
localEnv.info.isSelfCall = true; |
|
1921 |
||
1922 |
// Attribute arguments, yielding list of argument types. |
|
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
1923 |
KindSelector kind = attribArgs(KindSelector.MTH, tree.args, localEnv, argtypesBuf); |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
1924 |
argtypes = argtypesBuf.toList(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1925 |
typeargtypes = attribTypes(tree.typeargs, localEnv); |
10 | 1926 |
|
1927 |
// Variable `site' points to the class in which the called |
|
1928 |
// constructor is defined. |
|
1929 |
Type site = env.enclClass.sym.type; |
|
1930 |
if (methName == names._super) { |
|
1931 |
if (site == syms.objectType) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1932 |
log.error(tree.meth.pos(), Errors.NoSuperclass(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
|
1933 |
site = types.createErrorType(syms.objectType); |
10 | 1934 |
} else { |
1935 |
site = types.supertype(site); |
|
1936 |
} |
|
1937 |
} |
|
1938 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1939 |
if (site.hasTag(CLASS)) { |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1940 |
Type encl = site.getEnclosingType(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1941 |
while (encl != null && encl.hasTag(TYPEVAR)) |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1942 |
encl = encl.getUpperBound(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1943 |
if (encl.hasTag(CLASS)) { |
10 | 1944 |
// we are calling a nested class |
1945 |
||
10950 | 1946 |
if (tree.meth.hasTag(SELECT)) { |
10 | 1947 |
JCTree qualifier = ((JCFieldAccess) tree.meth).selected; |
1948 |
||
1949 |
// We are seeing a prefixed call, of the form |
|
1950 |
// <expr>.super(...). |
|
1951 |
// Check that the prefix expression conforms |
|
1952 |
// to the outer instance type of the class. |
|
1953 |
chk.checkRefType(qualifier.pos(), |
|
1954 |
attribExpr(qualifier, localEnv, |
|
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1955 |
encl)); |
10 | 1956 |
} else if (methName == names._super) { |
1957 |
// qualifier omitted; check for existence |
|
1958 |
// of an appropriate implicit qualifier. |
|
1959 |
rs.resolveImplicitThis(tree.meth.pos(), |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8616
diff
changeset
|
1960 |
localEnv, site, true); |
10 | 1961 |
} |
10950 | 1962 |
} else if (tree.meth.hasTag(SELECT)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1963 |
log.error(tree.meth.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
1964 |
Errors.IllegalQualNotIcls(site.tsym)); |
10 | 1965 |
} |
1966 |
||
1967 |
// if we're calling a java.lang.Enum constructor, |
|
1968 |
// prefix the implicit String and int parameters |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
1969 |
if (site.tsym == syms.enumSym) |
10 | 1970 |
argtypes = argtypes.prepend(syms.intType).prepend(syms.stringType); |
1971 |
||
1972 |
// Resolve the called constructor under the assumption |
|
1973 |
// that we are referring to a superclass instance of the |
|
1974 |
// current instance (JLS ???). |
|
1975 |
boolean selectSuperPrev = localEnv.info.selectSuper; |
|
1976 |
localEnv.info.selectSuper = true; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
1977 |
localEnv.info.pendingResolutionPhase = null; |
10 | 1978 |
Symbol sym = rs.resolveConstructor( |
1979 |
tree.meth.pos(), localEnv, site, argtypes, typeargtypes); |
|
1980 |
localEnv.info.selectSuper = selectSuperPrev; |
|
1981 |
||
1982 |
// Set method symbol to resolved constructor... |
|
1983 |
TreeInfo.setSymbol(tree.meth, sym); |
|
1984 |
||
1985 |
// ...and check that it is legal in the current context. |
|
1986 |
// (this will also set the tree's type) |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
1987 |
Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1988 |
checkId(tree.meth, site, sym, localEnv, |
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
1989 |
new ResultInfo(kind, mpt)); |
10 | 1990 |
} |
1991 |
// Otherwise, `site' is an error type and we do nothing |
|
1992 |
} |
|
1993 |
result = tree.type = syms.voidType; |
|
1994 |
} else { |
|
1995 |
// Otherwise, we are seeing a regular method call. |
|
1996 |
// Attribute the arguments, yielding list of argument types, ... |
|
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
1997 |
KindSelector kind = attribArgs(KindSelector.VAL, tree.args, localEnv, argtypesBuf); |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
1998 |
argtypes = argtypesBuf.toList(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
1999 |
typeargtypes = attribAnyTypes(tree.typeargs, localEnv); |
10 | 2000 |
|
2001 |
// ... and attribute the method using as a prototype a methodtype |
|
2002 |
// whose formal argument types is exactly the list of actual |
|
2003 |
// arguments (this will also set the method symbol). |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
2004 |
Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2005 |
localEnv.info.pendingResolutionPhase = null; |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
2006 |
Type mtype = attribTree(tree.meth, localEnv, new ResultInfo(kind, mpt, resultInfo.checkContext)); |
10 | 2007 |
|
2008 |
// Compute the result type. |
|
2009 |
Type restype = mtype.getReturnType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2010 |
if (restype.hasTag(WILDCARD)) |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6594
diff
changeset
|
2011 |
throw new AssertionError(mtype); |
10 | 2012 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2013 |
Type qualifier = (tree.meth.hasTag(SELECT)) |
10 | 2014 |
? ((JCFieldAccess) tree.meth).selected.type |
2015 |
: env.enclClass.sym.type; |
|
39810
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2016 |
Symbol msym = TreeInfo.symbol(tree.meth); |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2017 |
restype = adjustMethodReturnType(msym, qualifier, methName, argtypes, restype); |
10 | 2018 |
|
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
2019 |
chk.checkRefTypes(tree.typeargs, typeargtypes); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
2020 |
|
10 | 2021 |
// Check that value of resulting type is admissible in the |
2022 |
// current context. Also, capture the return type |
|
33708
99085a01b536
8141613: Compiler fails to infer generic type
mcimadamore
parents:
33366
diff
changeset
|
2023 |
Type capturedRes = resultInfo.checkContext.inferenceContext().cachedCapture(tree, restype, true); |
99085a01b536
8141613: Compiler fails to infer generic type
mcimadamore
parents:
33366
diff
changeset
|
2024 |
result = check(tree, capturedRes, KindSelector.VAL, resultInfo); |
10 | 2025 |
} |
1358 | 2026 |
chk.validate(tree.typeargs, localEnv); |
10 | 2027 |
} |
2028 |
//where |
|
39810
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2029 |
Type adjustMethodReturnType(Symbol msym, Type qualifierType, Name methodName, List<Type> argtypes, Type restype) { |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2030 |
if (msym != null && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2031 |
msym.owner == syms.objectType.tsym && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2032 |
methodName == names.getClass && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2033 |
argtypes.isEmpty()) { |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2034 |
// as a special case, x.getClass() has type Class<? extends |X|> |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2035 |
return new ClassType(restype.getEnclosingType(), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2036 |
List.of(new WildcardType(types.erasure(qualifierType), |
39810
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2037 |
BoundKind.EXTENDS, |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2038 |
syms.boundClass)), |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2039 |
restype.tsym, |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2040 |
restype.getMetadata()); |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2041 |
} else if (msym != null && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2042 |
msym.owner == syms.arrayClass && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2043 |
methodName == names.clone && |
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
2044 |
types.isArray(qualifierType)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2045 |
// as a special case, array.clone() has a result that is |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2046 |
// the same as static type of the array being cloned |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2047 |
return qualifierType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2048 |
} else { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2049 |
return restype; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2050 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2051 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2052 |
|
10 | 2053 |
/** Check that given application node appears as first statement |
2054 |
* in a constructor call. |
|
2055 |
* @param tree The application node |
|
2056 |
* @param env The environment current at the application. |
|
2057 |
*/ |
|
2058 |
boolean checkFirstConstructorStat(JCMethodInvocation tree, Env<AttrContext> env) { |
|
2059 |
JCMethodDecl enclMethod = env.enclMethod; |
|
2060 |
if (enclMethod != null && enclMethod.name == names.init) { |
|
2061 |
JCBlock body = enclMethod.body; |
|
10950 | 2062 |
if (body.stats.head.hasTag(EXEC) && |
10 | 2063 |
((JCExpressionStatement) body.stats.head).expr == tree) |
2064 |
return true; |
|
2065 |
} |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2066 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2067 |
Errors.CallMustBeFirstStmtInCtor(TreeInfo.name(tree.meth))); |
10 | 2068 |
return false; |
2069 |
} |
|
2070 |
||
2071 |
/** Obtain a method type with given argument types. |
|
2072 |
*/ |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
2073 |
Type newMethodTemplate(Type restype, List<Type> argtypes, List<Type> typeargtypes) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2074 |
MethodType mt = new MethodType(argtypes, restype, List.nil(), syms.methodClass); |
10 | 2075 |
return (typeargtypes == null) ? mt : (Type)new ForAll(typeargtypes, mt); |
2076 |
} |
|
2077 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2078 |
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
|
2079 |
Type owntype = types.createErrorType(tree.type); |
10 | 2080 |
|
2081 |
// The local environment of a class creation is |
|
2082 |
// a new environment nested in the current one. |
|
2083 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
2084 |
||
2085 |
// The anonymous inner class definition of the new expression, |
|
2086 |
// if one is defined by it. |
|
2087 |
JCClassDecl cdef = tree.def; |
|
2088 |
||
2089 |
// If enclosing class is given, attribute it, and |
|
2090 |
// complete class name to be fully qualified |
|
2091 |
JCExpression clazz = tree.clazz; // Class field following new |
|
15385 | 2092 |
JCExpression clazzid; // Identifier in class field |
2093 |
JCAnnotatedType annoclazzid; // Annotated type enclosing clazzid |
|
2094 |
annoclazzid = null; |
|
2095 |
||
2096 |
if (clazz.hasTag(TYPEAPPLY)) { |
|
2097 |
clazzid = ((JCTypeApply) clazz).clazz; |
|
2098 |
if (clazzid.hasTag(ANNOTATED_TYPE)) { |
|
2099 |
annoclazzid = (JCAnnotatedType) clazzid; |
|
2100 |
clazzid = annoclazzid.underlyingType; |
|
2101 |
} |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2102 |
} else { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2103 |
if (clazz.hasTag(ANNOTATED_TYPE)) { |
15385 | 2104 |
annoclazzid = (JCAnnotatedType) clazz; |
2105 |
clazzid = annoclazzid.underlyingType; |
|
2106 |
} else { |
|
2107 |
clazzid = clazz; |
|
2108 |
} |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2109 |
} |
10 | 2110 |
|
2111 |
JCExpression clazzid1 = clazzid; // The same in fully qualified form |
|
2112 |
||
2113 |
if (tree.encl != null) { |
|
2114 |
// We are seeing a qualified new, of the form |
|
2115 |
// <expr>.new C <...> (...) ... |
|
2116 |
// In this case, we let clazz stand for the name of the |
|
2117 |
// allocated class C prefixed with the type of the qualifier |
|
2118 |
// expression, so that we can |
|
2119 |
// resolve it with standard techniques later. I.e., if |
|
2120 |
// <expr> has type T, then <expr>.new C <...> (...) |
|
2121 |
// yields a clazz T.C. |
|
2122 |
Type encltype = chk.checkRefType(tree.encl.pos(), |
|
2123 |
attribExpr(tree.encl, env)); |
|
15385 | 2124 |
// TODO 308: in <expr>.new C, do we also want to add the type annotations |
2125 |
// from expr to the combined type, or not? Yes, do this. |
|
10 | 2126 |
clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), |
2127 |
((JCIdent) clazzid).name); |
|
15385 | 2128 |
|
19122
1841f2fa76de
8017216: javac doesn't fill in end position for some errors of type not found
ksrini
parents:
18920
diff
changeset
|
2129 |
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
|
2130 |
endPosTable.storeEnd(clazzid1, tree.getEndPosition(endPosTable)); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2131 |
if (clazz.hasTag(ANNOTATED_TYPE)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2132 |
JCAnnotatedType annoType = (JCAnnotatedType) clazz; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2133 |
List<JCAnnotation> annos = annoType.annotations; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2134 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2135 |
if (annoType.underlyingType.hasTag(TYPEAPPLY)) { |
15385 | 2136 |
clazzid1 = make.at(tree.pos). |
2137 |
TypeApply(clazzid1, |
|
2138 |
((JCTypeApply) clazz).arguments); |
|
2139 |
} |
|
2140 |
||
2141 |
clazzid1 = make.at(tree.pos). |
|
2142 |
AnnotatedType(annos, clazzid1); |
|
2143 |
} else if (clazz.hasTag(TYPEAPPLY)) { |
|
2144 |
clazzid1 = make.at(tree.pos). |
|
10 | 2145 |
TypeApply(clazzid1, |
2146 |
((JCTypeApply) clazz).arguments); |
|
15385 | 2147 |
} |
2148 |
||
2149 |
clazz = clazzid1; |
|
10 | 2150 |
} |
2151 |
||
2152 |
// Attribute clazz expression and store |
|
2153 |
// symbol + type back into the attributed tree. |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2154 |
Type clazztype; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2155 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2156 |
try { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2157 |
env.info.isNewClass = true; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2158 |
clazztype = TreeInfo.isEnumInit(env.tree) ? |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2159 |
attribIdentAsEnumType(env, (JCIdent)clazz) : |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2160 |
attribType(clazz, env); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2161 |
} finally { |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2162 |
env.info.isNewClass = false; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
2163 |
} |
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12915
diff
changeset
|
2164 |
|
8635
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
2165 |
clazztype = chk.checkDiamond(tree, clazztype); |
1358 | 2166 |
chk.validate(clazz, localEnv); |
10 | 2167 |
if (tree.encl != null) { |
2168 |
// We have to work in this case to store |
|
2169 |
// symbol + type back into the attributed tree. |
|
2170 |
tree.clazz.type = clazztype; |
|
2171 |
TreeInfo.setSymbol(clazzid, TreeInfo.symbol(clazzid1)); |
|
2172 |
clazzid.type = ((JCIdent) clazzid).sym.type; |
|
15385 | 2173 |
if (annoclazzid != null) { |
2174 |
annoclazzid.type = clazzid.type; |
|
2175 |
} |
|
10 | 2176 |
if (!clazztype.isErroneous()) { |
2177 |
if (cdef != null && clazztype.tsym.isInterface()) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2178 |
log.error(tree.encl.pos(), Errors.AnonClassImplIntfNoQualForNew); |
10 | 2179 |
} else if (clazztype.tsym.isStatic()) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2180 |
log.error(tree.encl.pos(), Errors.QualifiedNewOfStaticClass(clazztype.tsym)); |
10 | 2181 |
} |
2182 |
} |
|
2183 |
} else if (!clazztype.tsym.isInterface() && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
2184 |
clazztype.getEnclosingType().hasTag(CLASS)) { |
10 | 2185 |
// Check for the existence of an apropos outer instance |
2186 |
rs.resolveImplicitThis(tree.pos(), env, clazztype); |
|
2187 |
} |
|
2188 |
||
2189 |
// Attribute constructor arguments. |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
2190 |
ListBuffer<Type> argtypesBuf = new ListBuffer<>(); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2191 |
final KindSelector pkind = |
27856
d4711a6931e2
8065986: Compiler fails to NullPointerException when calling super with Object<>()
mcimadamore
parents:
27851
diff
changeset
|
2192 |
attribArgs(KindSelector.VAL, tree.args, localEnv, argtypesBuf); |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
2193 |
List<Type> argtypes = argtypesBuf.toList(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2194 |
List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
10 | 2195 |
|
48931
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
2196 |
if (clazztype.hasTag(CLASS) || clazztype.hasTag(ERROR)) { |
10 | 2197 |
// Enums may not be instantiated except implicitly |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
2198 |
if ((clazztype.tsym.flags_field & Flags.ENUM) != 0 && |
10950 | 2199 |
(!env.tree.hasTag(VARDEF) || |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
2200 |
(((JCVariableDecl) env.tree).mods.flags & Flags.ENUM) == 0 || |
10 | 2201 |
((JCVariableDecl) env.tree).init != tree)) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2202 |
log.error(tree.pos(), Errors.EnumCantBeInstantiated); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2203 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2204 |
boolean isSpeculativeDiamondInferenceRound = TreeInfo.isDiamond(tree) && |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2205 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2206 |
boolean skipNonDiamondPath = false; |
10 | 2207 |
// Check that class is not abstract |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2208 |
if (cdef == null && !isSpeculativeDiamondInferenceRound && // class body may be nulled out in speculative tree copy |
10 | 2209 |
(clazztype.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2210 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2211 |
Errors.AbstractCantBeInstantiated(clazztype.tsym)); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2212 |
skipNonDiamondPath = true; |
10 | 2213 |
} else if (cdef != null && clazztype.tsym.isInterface()) { |
2214 |
// Check that no constructor arguments are given to |
|
2215 |
// anonymous classes implementing an interface |
|
2216 |
if (!argtypes.isEmpty()) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2217 |
log.error(tree.args.head.pos(), Errors.AnonClassImplIntfNoArgs); |
10 | 2218 |
|
2219 |
if (!typeargtypes.isEmpty()) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2220 |
log.error(tree.typeargs.head.pos(), Errors.AnonClassImplIntfNoTypeargs); |
10 | 2221 |
|
2222 |
// Error recovery: pretend no arguments were supplied. |
|
2223 |
argtypes = List.nil(); |
|
2224 |
typeargtypes = List.nil(); |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2225 |
skipNonDiamondPath = true; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2226 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2227 |
if (TreeInfo.isDiamond(tree)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2228 |
ClassType site = new ClassType(clazztype.getEnclosingType(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2229 |
clazztype.tsym.type.getTypeArguments(), |
24396 | 2230 |
clazztype.tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
2231 |
clazztype.getMetadata()); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2232 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2233 |
Env<AttrContext> diamondEnv = localEnv.dup(tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2234 |
diamondEnv.info.selectSuper = cdef != null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2235 |
diamondEnv.info.pendingResolutionPhase = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2236 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2237 |
//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
|
2238 |
//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
|
2239 |
//of the resolved constructor will be a partially instantiated type |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2240 |
Symbol constructor = rs.resolveDiamond(tree.pos(), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2241 |
diamondEnv, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2242 |
site, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2243 |
argtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2244 |
typeargtypes); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2245 |
tree.constructor = constructor.baseSymbol(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2246 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2247 |
final TypeSymbol csym = clazztype.tsym; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2248 |
ResultInfo diamondResult = new ResultInfo(pkind, newMethodTemplate(resultInfo.pt, argtypes, typeargtypes), |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2249 |
diamondContext(tree, csym, resultInfo.checkContext), CheckMode.NO_TREE_UPDATE); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2250 |
Type constructorType = tree.constructorType = types.createErrorType(clazztype); |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2251 |
constructorType = checkId(tree, site, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2252 |
constructor, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2253 |
diamondEnv, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2254 |
diamondResult); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2255 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2256 |
tree.clazz.type = types.createErrorType(clazztype); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2257 |
if (!constructorType.isErroneous()) { |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2258 |
tree.clazz.type = clazz.type = constructorType.getReturnType(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2259 |
tree.constructorType = types.createMethodTypeWithReturn(constructorType, syms.voidType); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2260 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2261 |
clazztype = chk.checkClassType(tree.clazz, tree.clazz.type, true); |
10 | 2262 |
} |
2263 |
||
2264 |
// Resolve the called constructor under the assumption |
|
2265 |
// that we are referring to a superclass instance of the |
|
2266 |
// current instance (JLS ???). |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2267 |
else if (!skipNonDiamondPath) { |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
2268 |
//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
|
2269 |
//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
|
2270 |
//order to avoid downstream failures |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
2271 |
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
|
2272 |
rsEnv.info.selectSuper = cdef != null; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2273 |
rsEnv.info.pendingResolutionPhase = null; |
10 | 2274 |
tree.constructor = rs.resolveConstructor( |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
2275 |
tree.pos(), rsEnv, clazztype, argtypes, typeargtypes); |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2276 |
if (cdef == null) { //do not check twice! |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2277 |
tree.constructorType = checkId(tree, |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2278 |
clazztype, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2279 |
tree.constructor, |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2280 |
rsEnv, |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2281 |
new ResultInfo(pkind, newMethodTemplate(syms.voidType, argtypes, typeargtypes), CheckMode.NO_TREE_UPDATE)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2282 |
if (rsEnv.info.lastResolveVarargs()) |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2283 |
Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null); |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
2284 |
} |
10 | 2285 |
} |
2286 |
||
2287 |
if (cdef != null) { |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2288 |
visitAnonymousClassDefinition(tree, clazz, clazztype, cdef, localEnv, argtypes, typeargtypes, pkind); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2289 |
return; |
10 | 2290 |
} |
2291 |
||
2292 |
if (tree.constructor != null && tree.constructor.kind == MTH) |
|
2293 |
owntype = clazztype; |
|
2294 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2295 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2296 |
InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2297 |
if (tree.constructorType != null && inferenceContext.free(tree.constructorType)) { |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2298 |
//we need to wait for inference to finish and then replace inference vars in the constructor type |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2299 |
inferenceContext.addFreeTypeListener(List.of(tree.constructorType), |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2300 |
instantiatedContext -> { |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2301 |
tree.constructorType = instantiatedContext.asInstType(tree.constructorType); |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2302 |
}); |
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2303 |
} |
1358 | 2304 |
chk.validate(tree.typeargs, localEnv); |
10 | 2305 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2306 |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2307 |
// where |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2308 |
private void visitAnonymousClassDefinition(JCNewClass tree, JCExpression clazz, Type clazztype, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2309 |
JCClassDecl cdef, Env<AttrContext> localEnv, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2310 |
List<Type> argtypes, List<Type> typeargtypes, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2311 |
KindSelector pkind) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2312 |
// We are seeing an anonymous class instance creation. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2313 |
// In this case, the class instance creation |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2314 |
// expression |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2315 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2316 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2317 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2318 |
// is represented internally as |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2319 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2320 |
// E . new <typeargs1>C<typargs2>(args) ( class <empty-name> { ... } ) . |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2321 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2322 |
// This expression is then *transformed* as follows: |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2323 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2324 |
// (1) add an extends or implements clause |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2325 |
// (2) add a constructor. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2326 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2327 |
// For instance, if C is a class, and ET is the type of E, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2328 |
// the expression |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2329 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2330 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2331 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2332 |
// is translated to (where X is a fresh name and typarams is the |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2333 |
// parameter list of the super constructor): |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2334 |
// |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2335 |
// new <typeargs1>X(<*nullchk*>E, args) where |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2336 |
// X extends C<typargs2> { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2337 |
// <typarams> X(ET e, args) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2338 |
// e.<typeargs1>super(args) |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2339 |
// } |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2340 |
// ... |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2341 |
// } |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2342 |
InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2343 |
final boolean isDiamond = TreeInfo.isDiamond(tree); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2344 |
if (isDiamond |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2345 |
&& ((tree.constructorType != null && inferenceContext.free(tree.constructorType)) |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2346 |
|| (tree.clazz.type != null && inferenceContext.free(tree.clazz.type)))) { |
31113
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2347 |
final ResultInfo resultInfoForClassDefinition = this.resultInfo; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2348 |
inferenceContext.addFreeTypeListener(List.of(tree.constructorType, tree.clazz.type), |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2349 |
instantiatedContext -> { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2350 |
tree.constructorType = instantiatedContext.asInstType(tree.constructorType); |
32912
dd06b5fd9300
8133135: Compiler internall error (NPE) on anonymous class defined by qualified instance creation expression with diamond
sadayapalam
parents:
32709
diff
changeset
|
2351 |
tree.clazz.type = clazz.type = instantiatedContext.asInstType(clazz.type); |
31113
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2352 |
ResultInfo prevResult = this.resultInfo; |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2353 |
try { |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2354 |
this.resultInfo = resultInfoForClassDefinition; |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2355 |
visitAnonymousClassDefinition(tree, clazz, clazz.type, cdef, |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2356 |
localEnv, argtypes, typeargtypes, pkind); |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2357 |
} finally { |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2358 |
this.resultInfo = prevResult; |
646511cb5873
8081521: Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.
sadayapalam
parents:
30845
diff
changeset
|
2359 |
} |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2360 |
}); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2361 |
} else { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2362 |
if (isDiamond && clazztype.hasTag(CLASS)) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2363 |
List<Type> invalidDiamondArgs = chk.checkDiamondDenotable((ClassType)clazztype); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2364 |
if (!clazztype.isErroneous() && invalidDiamondArgs.nonEmpty()) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2365 |
// One or more types inferred in the previous steps is non-denotable. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2366 |
Fragment fragment = Diamond(clazztype.tsym); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2367 |
log.error(tree.clazz.pos(), |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2368 |
Errors.CantApplyDiamond1( |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2369 |
fragment, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2370 |
invalidDiamondArgs.size() > 1 ? |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2371 |
DiamondInvalidArgs(invalidDiamondArgs, fragment) : |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2372 |
DiamondInvalidArg(invalidDiamondArgs, fragment))); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2373 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2374 |
// For <>(){}, inferred types must also be accessible. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2375 |
for (Type t : clazztype.getTypeArguments()) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2376 |
rs.checkAccessibleType(env, t); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2377 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2378 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2379 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2380 |
// If we already errored, be careful to avoid a further avalanche. ErrorType answers |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2381 |
// false for isInterface call even when the original type is an interface. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2382 |
boolean implementing = clazztype.tsym.isInterface() || |
48931
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
2383 |
clazztype.isErroneous() && !clazztype.getOriginalType().hasTag(NONE) && |
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
2384 |
clazztype.getOriginalType().tsym.isInterface(); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2385 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2386 |
if (implementing) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2387 |
cdef.implementing = List.of(clazz); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2388 |
} else { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2389 |
cdef.extending = clazz; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2390 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2391 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2392 |
if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2393 |
isSerializable(clazztype)) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2394 |
localEnv.info.isSerializable = true; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2395 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2396 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2397 |
attribStat(cdef, localEnv); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2398 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2399 |
List<Type> finalargtypes; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2400 |
// If an outer instance is given, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2401 |
// prefix it to the constructor arguments |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2402 |
// and delete it from the new expression |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2403 |
if (tree.encl != null && !clazztype.tsym.isInterface()) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2404 |
finalargtypes = argtypes.prepend(tree.encl.type); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2405 |
} else { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2406 |
finalargtypes = argtypes; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2407 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2408 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2409 |
// Reassign clazztype and recompute constructor. As this necessarily involves |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2410 |
// another attribution pass for deferred types in the case of <>, replicate |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2411 |
// them. Original arguments have right decorations already. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2412 |
if (isDiamond && pkind.contains(KindSelector.POLY)) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2413 |
finalargtypes = finalargtypes.map(deferredAttr.deferredCopier); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2414 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2415 |
|
48931
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
2416 |
clazztype = clazztype.hasTag(ERROR) ? types.createErrorType(cdef.sym.type) |
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
2417 |
: cdef.sym.type; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2418 |
Symbol sym = tree.constructor = rs.resolveConstructor( |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2419 |
tree.pos(), localEnv, clazztype, finalargtypes, typeargtypes); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2420 |
Assert.check(!sym.kind.isResolutionError()); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2421 |
tree.constructor = sym; |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2422 |
tree.constructorType = checkId(tree, |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2423 |
clazztype, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2424 |
tree.constructor, |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2425 |
localEnv, |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2426 |
new ResultInfo(pkind, newMethodTemplate(syms.voidType, finalargtypes, typeargtypes), CheckMode.NO_TREE_UPDATE)); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2427 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2428 |
Type owntype = (tree.constructor != null && tree.constructor.kind == MTH) ? |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2429 |
clazztype : types.createErrorType(tree.type); |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
2430 |
result = check(tree, owntype, KindSelector.VAL, resultInfo.dup(CheckMode.NO_INFERENCE_HOOK)); |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2431 |
chk.validate(tree.typeargs, localEnv); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2432 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2433 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2434 |
CheckContext diamondContext(JCNewClass clazz, TypeSymbol tsym, CheckContext checkContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2435 |
return new Check.NestedCheckContext(checkContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2436 |
@Override |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2437 |
public void report(DiagnosticPosition _unused, JCDiagnostic details) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2438 |
enclosingContext.report(clazz.clazz, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2439 |
diags.fragment(Fragments.CantApplyDiamond1(Fragments.Diamond(tsym), details))); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2440 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2441 |
}; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2442 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2443 |
|
10 | 2444 |
/** Make an attributed null check tree. |
2445 |
*/ |
|
2446 |
public JCExpression makeNullCheck(JCExpression arg) { |
|
41154
ed8625a2f0f1
8166108: VerifyError passing anonymous inner class to supertype constructor
sadayapalam
parents:
40504
diff
changeset
|
2447 |
// optimization: new Outer() can never be null; skip null check |
ed8625a2f0f1
8166108: VerifyError passing anonymous inner class to supertype constructor
sadayapalam
parents:
40504
diff
changeset
|
2448 |
if (arg.getTag() == NEWCLASS) |
ed8625a2f0f1
8166108: VerifyError passing anonymous inner class to supertype constructor
sadayapalam
parents:
40504
diff
changeset
|
2449 |
return arg; |
10 | 2450 |
// optimization: X.this is never null; skip null check |
2451 |
Name name = TreeInfo.name(arg); |
|
2452 |
if (name == names._this || name == names._super) return arg; |
|
2453 |
||
10950 | 2454 |
JCTree.Tag optag = NULLCHK; |
10 | 2455 |
JCUnary tree = make.at(arg.pos).Unary(optag, arg); |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
2456 |
tree.operator = operators.resolveUnary(arg, optag, arg.type); |
10 | 2457 |
tree.type = arg.type; |
2458 |
return tree; |
|
2459 |
} |
|
2460 |
||
2461 |
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
|
2462 |
Type owntype = types.createErrorType(tree.type); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2463 |
Env<AttrContext> localEnv = env.dup(tree); |
10 | 2464 |
Type elemtype; |
2465 |
if (tree.elemtype != null) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2466 |
elemtype = attribType(tree.elemtype, localEnv); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2467 |
chk.validate(tree.elemtype, localEnv); |
10 | 2468 |
owntype = elemtype; |
2469 |
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
|
2470 |
attribExpr(l.head, localEnv, syms.intType); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
2471 |
owntype = new ArrayType(owntype, syms.arrayClass); |
10 | 2472 |
} |
2473 |
} else { |
|
2474 |
// we are seeing an untyped aggregate { ... } |
|
2475 |
// 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
|
2476 |
if (pt().hasTag(ARRAY)) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2477 |
elemtype = types.elemtype(pt()); |
10 | 2478 |
} else { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
2479 |
if (!pt().hasTag(ERROR) && |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
2480 |
(env.info.enclVar == null || !env.info.enclVar.type.isErroneous())) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2481 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2482 |
Errors.IllegalInitializerForType(pt())); |
10 | 2483 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2484 |
elemtype = types.createErrorType(pt()); |
10 | 2485 |
} |
2486 |
} |
|
2487 |
if (tree.elems != null) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
2488 |
attribExprs(tree.elems, localEnv, elemtype); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
2489 |
owntype = new ArrayType(elemtype, syms.arrayClass); |
10 | 2490 |
} |
2491 |
if (!types.isReifiable(elemtype)) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2492 |
log.error(tree.pos(), Errors.GenericArrayCreation); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2493 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
10 | 2494 |
} |
2495 |
||
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2496 |
/* |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2497 |
* 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
|
2498 |
* 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
|
2499 |
* descriptor contains inference variables in argument position the lambda expression |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2500 |
* is 'stuck' (see DeferredAttr). |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2501 |
*/ |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
2502 |
@Override |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2503 |
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
|
2504 |
if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
2505 |
if (pt().hasTag(NONE) && (env.info.enclVar == null || !env.info.enclVar.type.isErroneous())) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2506 |
//lambda only allowed in assignment or method invocation/cast context |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2507 |
log.error(that.pos(), Errors.UnexpectedLambda); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2508 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2509 |
result = that.type = types.createErrorType(pt()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2510 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2511 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2512 |
//create an environment for attribution of the lambda expression |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2513 |
final Env<AttrContext> localEnv = lambdaEnv(that, env); |
14547 | 2514 |
boolean needsRecovery = |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2515 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2516 |
try { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2517 |
if (needsRecovery && isSerializable(pt())) { |
24219 | 2518 |
localEnv.info.isSerializable = true; |
41629 | 2519 |
localEnv.info.isLambda = true; |
24219 | 2520 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2521 |
List<Type> explicitParamTypes = null; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
2522 |
if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2523 |
//attribute lambda parameters |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2524 |
attribStats(that.params, localEnv); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2525 |
explicitParamTypes = TreeInfo.types(that.params); |
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 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2528 |
TargetInfo targetInfo = getTargetInfo(that, resultInfo, explicitParamTypes); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2529 |
Type currentTarget = targetInfo.target; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2530 |
Type lambdaType = targetInfo.descriptor; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2531 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2532 |
if (currentTarget.isErroneous()) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2533 |
result = that.type = currentTarget; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2534 |
return; |
14547 | 2535 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2536 |
|
19916
5b5f188dbdd4
8023389: Javac fails to infer type for lambda used with intersection type and wildcards
vromero
parents:
19914
diff
changeset
|
2537 |
setFunctionalInfo(localEnv, that, pt(), lambdaType, currentTarget, resultInfo.checkContext); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
2538 |
|
14723
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2539 |
if (lambdaType.hasTag(FORALL)) { |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2540 |
//lambda expression target desc cannot be a generic method |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2541 |
Fragment msg = Fragments.InvalidGenericLambdaTarget(lambdaType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2542 |
kindName(currentTarget.tsym), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2543 |
currentTarget.tsym); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2544 |
resultInfo.checkContext.report(that, diags.fragment(msg)); |
14723
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2545 |
result = that.type = types.createErrorType(pt()); |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2546 |
return; |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2547 |
} |
46aa71a5e4e0
8004102: Add support for generic functional descriptors
mcimadamore
parents:
14722
diff
changeset
|
2548 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
2549 |
if (that.paramKind == JCLambda.ParameterKind.IMPLICIT) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2550 |
//add param type info in the AST |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2551 |
List<Type> actuals = lambdaType.getParameterTypes(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2552 |
List<JCVariableDecl> params = that.params; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2553 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2554 |
boolean arityMismatch = false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2555 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2556 |
while (params.nonEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2557 |
if (actuals.isEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2558 |
//not enough actuals to perform lambda parameter inference |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2559 |
arityMismatch = true; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2560 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2561 |
//reset previously set info |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2562 |
Type argType = arityMismatch ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2563 |
syms.errType : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2564 |
actuals.head; |
47318
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
2565 |
setSyntheticVariableType(params.head, argType); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2566 |
params.head.sym = null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2567 |
actuals = actuals.isEmpty() ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2568 |
actuals : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2569 |
actuals.tail; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2570 |
params = params.tail; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2571 |
} |
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 |
//attribute lambda parameters |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2574 |
attribStats(that.params, localEnv); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2575 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2576 |
if (arityMismatch) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2577 |
resultInfo.checkContext.report(that, diags.fragment(Fragments.IncompatibleArgTypesInLambda)); |
19916
5b5f188dbdd4
8023389: Javac fails to infer type for lambda used with intersection type and wildcards
vromero
parents:
19914
diff
changeset
|
2578 |
result = that.type = types.createErrorType(currentTarget); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2579 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2580 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2581 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2582 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2583 |
//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
|
2584 |
//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
|
2585 |
//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
|
2586 |
//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
|
2587 |
needsRecovery = false; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2588 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2589 |
ResultInfo bodyResultInfo = localEnv.info.returnResult = |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2590 |
lambdaBodyResult(that, lambdaType, resultInfo); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2591 |
|
19914 | 2592 |
if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { |
2593 |
attribTree(that.getBody(), localEnv, bodyResultInfo); |
|
2594 |
} else { |
|
2595 |
JCBlock body = (JCBlock)that.body; |
|
2596 |
attribStats(body.stats, localEnv); |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2597 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2598 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2599 |
result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
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 |
boolean isSpeculativeRound = |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2602 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2603 |
|
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2604 |
preFlow(that); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2605 |
flow.analyzeLambda(env, that, make, isSpeculativeRound); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2606 |
|
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
2607 |
that.type = currentTarget; //avoids recovery at this stage |
19933 | 2608 |
checkLambdaCompatible(that, lambdaType, resultInfo.checkContext); |
14058
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 |
if (!isSpeculativeRound) { |
19933 | 2611 |
//add thrown types as bounds to the thrown types free variables if needed: |
2612 |
if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) { |
|
2613 |
List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make); |
|
45756
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
2614 |
if(!checkExConstraints(inferredThrownTypes, lambdaType.getThrownTypes(), resultInfo.checkContext.inferenceContext())) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
2615 |
log.error(that, Errors.IncompatibleThrownTypesInMref(lambdaType.getThrownTypes())); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
2616 |
} |
19933 | 2617 |
} |
2618 |
||
19916
5b5f188dbdd4
8023389: Javac fails to infer type for lambda used with intersection type and wildcards
vromero
parents:
19914
diff
changeset
|
2619 |
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2620 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2621 |
result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2622 |
} catch (Types.FunctionDescriptorLookupError ex) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2623 |
JCDiagnostic cause = ex.getDiagnostic(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2624 |
resultInfo.checkContext.report(that, cause); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2625 |
result = that.type = types.createErrorType(pt()); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2626 |
return; |
30064
39493809b601
8077605: Initializing static fields causes unbounded recursion in javac
jlahoda
parents:
29959
diff
changeset
|
2627 |
} catch (Throwable t) { |
39493809b601
8077605: Initializing static fields causes unbounded recursion in javac
jlahoda
parents:
29959
diff
changeset
|
2628 |
//when an unexpected exception happens, avoid attempts to attribute the same tree again |
39493809b601
8077605: Initializing static fields causes unbounded recursion in javac
jlahoda
parents:
29959
diff
changeset
|
2629 |
//as that would likely cause the same exception again. |
39493809b601
8077605: Initializing static fields causes unbounded recursion in javac
jlahoda
parents:
29959
diff
changeset
|
2630 |
needsRecovery = false; |
39493809b601
8077605: Initializing static fields causes unbounded recursion in javac
jlahoda
parents:
29959
diff
changeset
|
2631 |
throw t; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2632 |
} finally { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2633 |
localEnv.info.scope.leave(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2634 |
if (needsRecovery) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2635 |
attribTree(that, env, recoveryInfo); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2636 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2637 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
2638 |
} |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2639 |
//where |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2640 |
class TargetInfo { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2641 |
Type target; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2642 |
Type descriptor; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2643 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2644 |
public TargetInfo(Type target, Type descriptor) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2645 |
this.target = target; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2646 |
this.descriptor = descriptor; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2647 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2648 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2649 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2650 |
TargetInfo getTargetInfo(JCPolyExpression that, ResultInfo resultInfo, List<Type> explicitParamTypes) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2651 |
Type lambdaType; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2652 |
Type currentTarget = resultInfo.pt; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2653 |
if (resultInfo.pt != Type.recoveryType) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2654 |
/* We need to adjust the target. If the target is an |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2655 |
* intersection type, for example: SAM & I1 & I2 ... |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2656 |
* the target will be updated to SAM |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2657 |
*/ |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2658 |
currentTarget = targetChecker.visit(currentTarget, that); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2659 |
if (explicitParamTypes != null) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2660 |
currentTarget = infer.instantiateFunctionalInterface(that, |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2661 |
currentTarget, explicitParamTypes, resultInfo.checkContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2662 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2663 |
currentTarget = types.removeWildcards(currentTarget); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2664 |
lambdaType = types.findDescriptorType(currentTarget); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2665 |
} else { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2666 |
currentTarget = Type.recoveryType; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2667 |
lambdaType = fallbackDescriptorType(that); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2668 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2669 |
if (that.hasTag(LAMBDA) && lambdaType.hasTag(FORALL)) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2670 |
//lambda expression target desc cannot be a generic method |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2671 |
Fragment msg = Fragments.InvalidGenericLambdaTarget(lambdaType, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2672 |
kindName(currentTarget.tsym), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2673 |
currentTarget.tsym); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2674 |
resultInfo.checkContext.report(that, diags.fragment(msg)); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2675 |
currentTarget = types.createErrorType(pt()); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2676 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2677 |
return new TargetInfo(currentTarget, lambdaType); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2678 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2679 |
|
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2680 |
void preFlow(JCLambda tree) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2681 |
new PostAttrAnalyzer() { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2682 |
@Override |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2683 |
public void scan(JCTree tree) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2684 |
if (tree == null || |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2685 |
(tree.type != null && |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2686 |
tree.type == Type.stuckType)) { |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2687 |
//don't touch stuck expressions! |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2688 |
return; |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2689 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2690 |
super.scan(tree); |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2691 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2692 |
}.scan(tree); |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2693 |
} |
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18911
diff
changeset
|
2694 |
|
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2695 |
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
|
2696 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2697 |
@Override |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2698 |
public Type visitClassType(ClassType t, DiagnosticPosition pos) { |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29051
diff
changeset
|
2699 |
return t.isIntersection() ? |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2700 |
visitIntersectionClassType((IntersectionClassType)t, pos) : t; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2701 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2702 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2703 |
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
|
2704 |
Symbol desc = types.findDescriptorSymbol(makeNotionalInterface(ict)); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2705 |
Type target = null; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2706 |
for (Type bound : ict.getExplicitComponents()) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2707 |
TypeSymbol boundSym = bound.tsym; |
50061
20520a835f48
8202597: javac is not inducing a notional interface if Object appears in an intersection type
vromero
parents:
49887
diff
changeset
|
2708 |
if (bound.tsym == syms.objectType.tsym) { |
20520a835f48
8202597: javac is not inducing a notional interface if Object appears in an intersection type
vromero
parents:
49887
diff
changeset
|
2709 |
continue; |
20520a835f48
8202597: javac is not inducing a notional interface if Object appears in an intersection type
vromero
parents:
49887
diff
changeset
|
2710 |
} |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2711 |
if (types.isFunctionalInterface(boundSym) && |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2712 |
types.findDescriptorSymbol(boundSym) == desc) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2713 |
target = bound; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2714 |
} 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
|
2715 |
//bound must be an interface |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2716 |
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
|
2717 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2718 |
} |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2719 |
return target != null ? |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2720 |
target : |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2721 |
ict.getExplicitComponents().head; //error recovery |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
2722 |
} |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2723 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2724 |
private TypeSymbol makeNotionalInterface(IntersectionClassType ict) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
2725 |
ListBuffer<Type> targs = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
2726 |
ListBuffer<Type> supertypes = new ListBuffer<>(); |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2727 |
for (Type i : ict.interfaces_field) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2728 |
if (i.isParameterized()) { |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2729 |
targs.appendList(i.tsym.type.allparams()); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2730 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2731 |
supertypes.append(i.tsym.type); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2732 |
} |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29051
diff
changeset
|
2733 |
IntersectionClassType notionalIntf = types.makeIntersectionType(supertypes.toList()); |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2734 |
notionalIntf.allparams_field = targs.toList(); |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2735 |
notionalIntf.tsym.flags_field |= INTERFACE; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2736 |
return notionalIntf.tsym; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2737 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2738 |
|
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2739 |
private void reportIntersectionError(DiagnosticPosition pos, String key, Object... args) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2740 |
resultInfo.checkContext.report(pos, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2741 |
diags.fragment(Fragments.BadIntersectionTargetForFunctionalExpr(diags.fragment(key, args)))); |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2742 |
} |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2743 |
}; |
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
2744 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2745 |
private Type fallbackDescriptorType(JCExpression tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2746 |
switch (tree.getTag()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2747 |
case LAMBDA: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2748 |
JCLambda lambda = (JCLambda)tree; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2749 |
List<Type> argtypes = List.nil(); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2750 |
for (JCVariableDecl param : lambda.params) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2751 |
argtypes = param.vartype != null ? |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2752 |
argtypes.append(param.vartype.type) : |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2753 |
argtypes.append(syms.errType); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2754 |
} |
16972
b5e557f4d536
8011376: Spurious checked exception errors in nested method call
mcimadamore
parents:
16809
diff
changeset
|
2755 |
return new MethodType(argtypes, Type.recoveryType, |
b5e557f4d536
8011376: Spurious checked exception errors in nested method call
mcimadamore
parents:
16809
diff
changeset
|
2756 |
List.of(syms.throwableType), syms.methodClass); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2757 |
case REFERENCE: |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2758 |
return new MethodType(List.nil(), Type.recoveryType, |
16972
b5e557f4d536
8011376: Spurious checked exception errors in nested method call
mcimadamore
parents:
16809
diff
changeset
|
2759 |
List.of(syms.throwableType), syms.methodClass); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2760 |
default: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2761 |
Assert.error("Cannot get here!"); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2762 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2763 |
return null; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2764 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2765 |
|
16972
b5e557f4d536
8011376: Spurious checked exception errors in nested method call
mcimadamore
parents:
16809
diff
changeset
|
2766 |
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
|
2767 |
final InferenceContext inferenceContext, final Type... ts) { |
14547 | 2768 |
checkAccessibleTypes(pos, env, inferenceContext, List.from(ts)); |
2769 |
} |
|
2770 |
||
16972
b5e557f4d536
8011376: Spurious checked exception errors in nested method call
mcimadamore
parents:
16809
diff
changeset
|
2771 |
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
|
2772 |
final InferenceContext inferenceContext, final List<Type> ts) { |
14547 | 2773 |
if (inferenceContext.free(ts)) { |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
2774 |
inferenceContext.addFreeTypeListener(ts, |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
2775 |
solvedContext -> checkAccessibleTypes(pos, env, solvedContext, solvedContext.asInstTypes(ts))); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2776 |
} else { |
14547 | 2777 |
for (Type t : ts) { |
2778 |
rs.checkAccessibleType(env, t); |
|
2779 |
} |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2780 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2781 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2782 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2783 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2784 |
* Lambda/method reference have a special check context that ensures |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2785 |
* 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
|
2786 |
* type according to both the inherited context and the assignment |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2787 |
* context. |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2788 |
*/ |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2789 |
class FunctionalReturnContext extends Check.NestedCheckContext { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2790 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2791 |
FunctionalReturnContext(CheckContext enclosingContext) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2792 |
super(enclosingContext); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2793 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2794 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2795 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2796 |
public boolean compatible(Type found, Type req, Warner warn) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2797 |
//return type must be compatible in both current context and assignment context |
38538
8bdc63ff6961
8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents:
38508
diff
changeset
|
2798 |
return chk.basicHandler.compatible(inferenceContext().asUndetVar(found), inferenceContext().asUndetVar(req), warn); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2799 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
2800 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2801 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2802 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2803 |
enclosingContext.report(pos, diags.fragment(Fragments.IncompatibleRetTypeInLambda(details))); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2804 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2805 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2806 |
|
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2807 |
class ExpressionLambdaReturnContext extends FunctionalReturnContext { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2808 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2809 |
JCExpression expr; |
38508
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2810 |
boolean expStmtExpected; |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2811 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2812 |
ExpressionLambdaReturnContext(JCExpression expr, CheckContext enclosingContext) { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2813 |
super(enclosingContext); |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2814 |
this.expr = expr; |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2815 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2816 |
|
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2817 |
@Override |
38508
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2818 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2819 |
if (expStmtExpected) { |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2820 |
enclosingContext.report(pos, diags.fragment(Fragments.StatExprExpected)); |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2821 |
} else { |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2822 |
super.report(pos, details); |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2823 |
} |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2824 |
} |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2825 |
|
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2826 |
@Override |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2827 |
public boolean compatible(Type found, Type req, Warner warn) { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2828 |
//a void return is compatible with an expression statement lambda |
38508
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2829 |
if (req.hasTag(VOID)) { |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2830 |
expStmtExpected = true; |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2831 |
return TreeInfo.isExpressionStatement(expr); |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2832 |
} else { |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2833 |
return super.compatible(found, req, warn); |
03c87ceca5fd
8153884: Expression lambda erroneously compatible with void-returning descriptor
mcimadamore
parents:
37634
diff
changeset
|
2834 |
} |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2835 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2836 |
} |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
2837 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2838 |
ResultInfo lambdaBodyResult(JCLambda that, Type descriptor, ResultInfo resultInfo) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2839 |
FunctionalReturnContext funcContext = that.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2840 |
new ExpressionLambdaReturnContext((JCExpression)that.getBody(), resultInfo.checkContext) : |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2841 |
new FunctionalReturnContext(resultInfo.checkContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2842 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2843 |
return descriptor.getReturnType() == Type.recoveryType ? |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2844 |
recoveryInfo : |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2845 |
new ResultInfo(KindSelector.VAL, |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2846 |
descriptor.getReturnType(), funcContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2847 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2848 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2849 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2850 |
* Lambda compatibility. Check that given return types, thrown types, parameter types |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2851 |
* are compatible with the expected functional interface descriptor. This means that: |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2852 |
* (i) parameter types must be identical to those of the target descriptor; (ii) return |
19933 | 2853 |
* 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
|
2854 |
*/ |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2855 |
void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) { |
23132
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23129
diff
changeset
|
2856 |
Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2857 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2858 |
//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
|
2859 |
//values, we must ensure that void/value compatibility is correct; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2860 |
//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
|
2861 |
//the descriptor's return type must be void |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2862 |
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
|
2863 |
!returnType.hasTag(VOID) && returnType != Type.recoveryType) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2864 |
Fragment msg = |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2865 |
Fragments.IncompatibleRetTypeInLambda(Fragments.MissingRetVal(returnType)); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2866 |
checkContext.report(tree, |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2867 |
diags.fragment(msg)); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2868 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2869 |
|
23132
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23129
diff
changeset
|
2870 |
List<Type> argTypes = checkContext.inferenceContext().asUndetVars(descriptor.getParameterTypes()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2871 |
if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2872 |
checkContext.report(tree, diags.fragment(Fragments.IncompatibleArgTypesInLambda)); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2873 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2874 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2875 |
|
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2876 |
/* Map to hold 'fake' clinit methods. If a lambda is used to initialize a |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2877 |
* static field and that lambda has type annotations, these annotations will |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2878 |
* also be stored at these fake clinit methods. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2879 |
* |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2880 |
* LambdaToMethod also use fake clinit methods so they can be reused. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2881 |
* Also as LTM is a phase subsequent to attribution, the methods from |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2882 |
* clinits can be safely removed by LTM to save memory. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2883 |
*/ |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2884 |
private Map<ClassSymbol, MethodSymbol> clinits = new HashMap<>(); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2885 |
|
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2886 |
public MethodSymbol removeClinit(ClassSymbol sym) { |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2887 |
return clinits.remove(sym); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2888 |
} |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2889 |
|
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2890 |
/* This method returns an environment to be used to attribute a lambda |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2891 |
* expression. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2892 |
* |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2893 |
* The owner of this environment is a method symbol. If the current owner |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2894 |
* is not a method, for example if the lambda is used to initialize |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2895 |
* a field, then if the field is: |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2896 |
* |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2897 |
* - an instance field, we use the first constructor. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2898 |
* - a static field, we create a fake clinit method. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2899 |
*/ |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
23969
diff
changeset
|
2900 |
public Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2901 |
Env<AttrContext> lambdaEnv; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2902 |
Symbol owner = env.info.scope.owner; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2903 |
if (owner.kind == VAR && owner.owner.kind == TYP) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2904 |
//field initializer |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2905 |
ClassSymbol enclClass = owner.enclClass(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
2906 |
Symbol newScopeOwner = env.info.scope.owner; |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2907 |
/* if the field isn't static, then we can get the first constructor |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2908 |
* and use it as the owner of the environment. This is what |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2909 |
* LTM code is doing to look for type annotations so we are fine. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2910 |
*/ |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2911 |
if ((owner.flags() & STATIC) == 0) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
2912 |
for (Symbol s : enclClass.members_field.getSymbolsByName(names.init)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
2913 |
newScopeOwner = s; |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2914 |
break; |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2915 |
} |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2916 |
} else { |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2917 |
/* if the field is static then we need to create a fake clinit |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2918 |
* method, this method can later be reused by LTM. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2919 |
*/ |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2920 |
MethodSymbol clinit = clinits.get(enclClass); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2921 |
if (clinit == null) { |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2922 |
Type clinitType = new MethodType(List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2923 |
syms.voidType, List.nil(), syms.methodClass); |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2924 |
clinit = new MethodSymbol(STATIC | SYNTHETIC | PRIVATE, |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2925 |
names.clinit, clinitType, enclClass); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
2926 |
clinit.params = List.nil(); |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2927 |
clinits.put(enclClass, clinit); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2928 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
2929 |
newScopeOwner = clinit; |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
22003
diff
changeset
|
2930 |
} |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
2931 |
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dupUnshared(newScopeOwner))); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2932 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2933 |
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup())); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2934 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2935 |
return lambdaEnv; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
2936 |
} |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
2937 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2938 |
@Override |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2939 |
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
|
2940 |
if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
2941 |
if (pt().hasTag(NONE) && (env.info.enclVar == null || !env.info.enclVar.type.isErroneous())) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2942 |
//method reference only allowed in assignment or method invocation/cast context |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2943 |
log.error(that.pos(), Errors.UnexpectedMref); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2944 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2945 |
result = that.type = types.createErrorType(pt()); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2946 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2947 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2948 |
final Env<AttrContext> localEnv = env.dup(that); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2949 |
try { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2950 |
//attribute member reference qualifier - if this is a constructor |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2951 |
//reference, the expected kind must be a type |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
2952 |
Type exprType = attribTree(that.expr, env, memberReferenceQualifierResult(that)); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2953 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2954 |
if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2955 |
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
|
2956 |
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
|
2957 |
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
|
2958 |
that.typeargs != null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2959 |
log.error(that.expr.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2960 |
Errors.InvalidMref(Kinds.kindName(that.getMode()), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
2961 |
Fragments.MrefInferAndExplicitParams)); |
19918
3bdf0c6b869c
8023549: Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied
vromero
parents:
19916
diff
changeset
|
2962 |
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
|
2963 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2964 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2965 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2966 |
if (exprType.isErroneous()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2967 |
//if the qualifier expression contains problems, |
15718 | 2968 |
//give up attribution of method reference |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2969 |
result = that.type = exprType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2970 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2971 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2972 |
|
17583
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
2973 |
if (TreeInfo.isStaticSelector(that.expr, names)) { |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
2974 |
//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
|
2975 |
//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
|
2976 |
//raw selector (because of inference) |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
2977 |
chk.validate(that.expr, env, false); |
33363
f03a03067799
8139836: Can't use super::x method reference when x is protected
sadayapalam
parents:
32950
diff
changeset
|
2978 |
} else { |
f03a03067799
8139836: Can't use super::x method reference when x is protected
sadayapalam
parents:
32950
diff
changeset
|
2979 |
Symbol lhsSym = TreeInfo.symbol(that.expr); |
f03a03067799
8139836: Can't use super::x method reference when x is protected
sadayapalam
parents:
32950
diff
changeset
|
2980 |
localEnv.info.selectSuper = lhsSym != null && lhsSym.name == names._super; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2981 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2982 |
//attrib type-arguments |
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
2983 |
List<Type> typeargtypes = List.nil(); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2984 |
if (that.typeargs != null) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2985 |
typeargtypes = attribTypes(that.typeargs, localEnv); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2986 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2987 |
|
24219 | 2988 |
boolean isTargetSerializable = |
2989 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2990 |
isSerializable(pt()); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2991 |
TargetInfo targetInfo = getTargetInfo(that, resultInfo, null); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2992 |
Type currentTarget = targetInfo.target; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
2993 |
Type desc = targetInfo.descriptor; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2994 |
|
24219 | 2995 |
setFunctionalInfo(localEnv, that, pt(), desc, currentTarget, resultInfo.checkContext); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
2996 |
List<Type> argtypes = desc.getParameterTypes(); |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
2997 |
Resolve.MethodCheck referenceCheck = rs.resolveMethodCheck; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
2998 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
2999 |
if (resultInfo.checkContext.inferenceContext().free(argtypes)) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3000 |
referenceCheck = rs.new MethodReferenceCheck(resultInfo.checkContext.inferenceContext()); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3001 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3002 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3003 |
Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = null; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3004 |
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
|
3005 |
try { |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21716
diff
changeset
|
3006 |
refResult = rs.resolveMemberReference(localEnv, that, that.expr.type, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21716
diff
changeset
|
3007 |
that.name, argtypes, typeargtypes, referenceCheck, |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3008 |
resultInfo.checkContext.inferenceContext(), rs.basicReferenceChooser); |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3009 |
} finally { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3010 |
resultInfo.checkContext.inferenceContext().rollback(saved_undet); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3011 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3012 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3013 |
Symbol refSym = refResult.fst; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3014 |
Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3015 |
|
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3016 |
/** this switch will need to go away and be replaced by the new RESOLUTION_TARGET testing |
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3017 |
* JDK-8075541 |
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3018 |
*/ |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3019 |
if (refSym.kind != MTH) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3020 |
boolean targetError; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3021 |
switch (refSym.kind) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3022 |
case ABSENT_MTH: |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3023 |
case MISSING_ENCL: |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3024 |
targetError = false; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3025 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3026 |
case WRONG_MTH: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3027 |
case WRONG_MTHS: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3028 |
case AMBIGUOUS: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3029 |
case HIDDEN: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3030 |
case STATICERR: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3031 |
targetError = true; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3032 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3033 |
default: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3034 |
Assert.error("unexpected result kind " + refSym.kind); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3035 |
targetError = false; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3036 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3037 |
|
24400
f05df7f58567
8037379: fix for JDK-8029569 doesn't cover all possible cases
vromero
parents:
24396
diff
changeset
|
3038 |
JCDiagnostic detailsDiag = ((Resolve.ResolveError)refSym.baseSymbol()).getDiagnostic(JCDiagnostic.DiagnosticType.FRAGMENT, |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3039 |
that, exprType.tsym, exprType, that.name, argtypes, typeargtypes); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3040 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3041 |
JCDiagnostic.DiagnosticType diagKind = targetError ? |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3042 |
JCDiagnostic.DiagnosticType.FRAGMENT : JCDiagnostic.DiagnosticType.ERROR; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3043 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3044 |
JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3045 |
"invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3046 |
|
24219 | 3047 |
if (targetError && currentTarget == Type.recoveryType) { |
14547 | 3048 |
//a target error doesn't make sense during recovery stage |
3049 |
//as we don't know what actual parameter types are |
|
24219 | 3050 |
result = that.type = currentTarget; |
14547 | 3051 |
return; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3052 |
} else { |
14547 | 3053 |
if (targetError) { |
3054 |
resultInfo.checkContext.report(that, diag); |
|
3055 |
} else { |
|
3056 |
log.report(diag); |
|
3057 |
} |
|
24219 | 3058 |
result = that.type = types.createErrorType(currentTarget); |
14547 | 3059 |
return; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3060 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3061 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3062 |
|
16293
bf5e87940aee
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
mcimadamore
parents:
15718
diff
changeset
|
3063 |
that.sym = refSym.baseSymbol(); |
bf5e87940aee
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
mcimadamore
parents:
15718
diff
changeset
|
3064 |
that.kind = lookupHelper.referenceKind(that.sym); |
16328
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16323
diff
changeset
|
3065 |
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
|
3066 |
|
16323
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16320
diff
changeset
|
3067 |
if (desc.getReturnType() == Type.recoveryType) { |
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16320
diff
changeset
|
3068 |
// stop here |
24219 | 3069 |
result = that.type = currentTarget; |
16323
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16320
diff
changeset
|
3070 |
return; |
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16320
diff
changeset
|
3071 |
} |
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16320
diff
changeset
|
3072 |
|
43582
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3073 |
if (!env.info.isSpeculative && that.getMode() == JCMemberReference.ReferenceMode.NEW) { |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3074 |
Type enclosingType = exprType.getEnclosingType(); |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3075 |
if (enclosingType != null && enclosingType.hasTag(CLASS)) { |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3076 |
// Check for the existence of an apropriate outer instance |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3077 |
rs.resolveImplicitThis(that.pos(), env, exprType); |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3078 |
} |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3079 |
} |
a6c58d4cb05b
8173456: com.sun.tools.javac.util.Assert.error during code compilation
sadayapalam
parents:
43138
diff
changeset
|
3080 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3081 |
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
|
3082 |
|
17583
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3083 |
if (that.getMode() == ReferenceMode.INVOKE && |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3084 |
TreeInfo.isStaticSelector(that.expr, names) && |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3085 |
that.kind.isUnbound() && |
47315
31f541df4187
8063054: Incorrect raw type warning for method reference
mcimadamore
parents:
47268
diff
changeset
|
3086 |
lookupHelper.site.isRaw()) { |
17583
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3087 |
chk.checkRaw(that.expr, localEnv); |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3088 |
} |
91949b5f7651
8012685: Spurious raw types warning when using unbound method references
mcimadamore
parents:
17582
diff
changeset
|
3089 |
|
16293
bf5e87940aee
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
mcimadamore
parents:
15718
diff
changeset
|
3090 |
if (that.sym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) && |
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3091 |
exprType.getTypeArguments().nonEmpty()) { |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3092 |
//static ref with class type-args |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3093 |
log.error(that.expr.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3094 |
Errors.InvalidMref(Kinds.kindName(that.getMode()), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3095 |
Fragments.StaticMrefWithTargs)); |
24219 | 3096 |
result = that.type = types.createErrorType(currentTarget); |
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3097 |
return; |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3098 |
} |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3099 |
|
16293
bf5e87940aee
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
mcimadamore
parents:
15718
diff
changeset
|
3100 |
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
|
3101 |
// 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
|
3102 |
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
|
3103 |
} |
24219 | 3104 |
|
3105 |
if (isTargetSerializable) { |
|
41629 | 3106 |
chk.checkAccessFromSerializableElement(that, true); |
24219 | 3107 |
} |
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3108 |
} |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14723
diff
changeset
|
3109 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3110 |
ResultInfo checkInfo = |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3111 |
resultInfo.dup(newMethodTemplate( |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3112 |
desc.getReturnType().hasTag(VOID) ? Type.noType : desc.getReturnType(), |
24401
0d793293862a
8028503: javac, for method references a primitive type can be added as a bound
vromero
parents:
24400
diff
changeset
|
3113 |
that.kind.isUnbound() ? argtypes.tail : argtypes, typeargtypes), |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
3114 |
new FunctionalReturnContext(resultInfo.checkContext), CheckMode.NO_TREE_UPDATE); |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
3115 |
|
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
3116 |
Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3117 |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3118 |
if (that.kind.isUnbound() && |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3119 |
resultInfo.checkContext.inferenceContext().free(argtypes.head)) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3120 |
//re-generate inference constraints for unbound receiver |
23132
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23129
diff
changeset
|
3121 |
if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asUndetVar(argtypes.head), exprType)) { |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3122 |
//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
|
3123 |
//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
|
3124 |
//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
|
3125 |
Assert.error("Can't get here"); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3126 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3127 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18903
diff
changeset
|
3128 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3129 |
if (!refType.isErroneous()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3130 |
refType = types.createMethodTypeWithReturn(refType, |
39810
d290bef927c4
8161985: Spurious override of Object.getClass leads to NPE
mcimadamore
parents:
38829
diff
changeset
|
3131 |
adjustMethodReturnType(refSym, lookupHelper.site, that.name, checkInfo.pt.getParameterTypes(), refType.getReturnType())); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3132 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3133 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3134 |
//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
|
3135 |
//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
|
3136 |
boolean isSpeculativeRound = |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3137 |
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; |
28148
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
3138 |
|
6415a95b07fd
8066974: Compiler doesn't infer method's generic type information in lambda body
mcimadamore
parents:
28142
diff
changeset
|
3139 |
that.type = currentTarget; //avoids recovery at this stage |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3140 |
checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3141 |
if (!isSpeculativeRound) { |
24219 | 3142 |
checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3143 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3144 |
result = check(that, currentTarget, KindSelector.VAL, resultInfo); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3145 |
} catch (Types.FunctionDescriptorLookupError ex) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3146 |
JCDiagnostic cause = ex.getDiagnostic(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3147 |
resultInfo.checkContext.report(that, cause); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3148 |
result = that.type = types.createErrorType(pt()); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3149 |
return; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3150 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3151 |
} |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
16293
diff
changeset
|
3152 |
//where |
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
16293
diff
changeset
|
3153 |
ResultInfo memberReferenceQualifierResult(JCMemberReference tree) { |
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
16293
diff
changeset
|
3154 |
//if this is a constructor reference, the expected kind must be a type |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3155 |
return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ? |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3156 |
KindSelector.VAL_TYP : KindSelector.TYP, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3157 |
Type.noType); |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
16293
diff
changeset
|
3158 |
} |
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
16293
diff
changeset
|
3159 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3160 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3161 |
@SuppressWarnings("fallthrough") |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3162 |
void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { |
28591
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3163 |
InferenceContext inferenceContext = checkContext.inferenceContext(); |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3164 |
Type returnType = inferenceContext.asUndetVar(descriptor.getReturnType()); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3165 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3166 |
Type resType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3167 |
switch (tree.getMode()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3168 |
case NEW: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3169 |
if (!tree.expr.type.isRaw()) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3170 |
resType = tree.expr.type; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3171 |
break; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3172 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3173 |
default: |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3174 |
resType = refType.getReturnType(); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3175 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3176 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3177 |
Type incompatibleReturnType = resType; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3178 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3179 |
if (returnType.hasTag(VOID)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3180 |
incompatibleReturnType = null; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3181 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3182 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3183 |
if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3184 |
if (resType.isErroneous() || |
44184
606c14ee20ed
8175317: javac does not issue unchecked warnings when checking method reference return types
mcimadamore
parents:
44060
diff
changeset
|
3185 |
new FunctionalReturnContext(checkContext).compatible(resType, returnType, |
606c14ee20ed
8175317: javac does not issue unchecked warnings when checking method reference return types
mcimadamore
parents:
44060
diff
changeset
|
3186 |
checkContext.checkWarner(tree, resType, returnType))) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3187 |
incompatibleReturnType = null; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3188 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3189 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3190 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3191 |
if (incompatibleReturnType != null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3192 |
Fragment msg = |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3193 |
Fragments.IncompatibleRetTypeInMref(Fragments.InconvertibleTypes(resType, descriptor.getReturnType())); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3194 |
checkContext.report(tree, diags.fragment(msg)); |
28591
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3195 |
} else { |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3196 |
if (inferenceContext.free(refType)) { |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3197 |
// we need to wait for inference to finish and then replace inference vars in the referent type |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3198 |
inferenceContext.addFreeTypeListener(List.of(refType), |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3199 |
instantiatedContext -> { |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3200 |
tree.referentType = instantiatedContext.asInstType(refType); |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3201 |
}); |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3202 |
} else { |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3203 |
tree.referentType = refType; |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28459
diff
changeset
|
3204 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3205 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3206 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3207 |
if (!speculativeAttr) { |
45756
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3208 |
if (!checkExConstraints(refType.getThrownTypes(), descriptor.getThrownTypes(), inferenceContext)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3209 |
log.error(tree, Errors.IncompatibleThrownTypesInMref(refType.getThrownTypes())); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3210 |
} |
45756
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3211 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3212 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3213 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3214 |
boolean checkExConstraints( |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3215 |
List<Type> thrownByFuncExpr, |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3216 |
List<Type> thrownAtFuncType, |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3217 |
InferenceContext inferenceContext) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3218 |
/** 18.2.5: Otherwise, let E1, ..., En be the types in the function type's throws clause that |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3219 |
* are not proper types |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3220 |
*/ |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3221 |
List<Type> nonProperList = thrownAtFuncType.stream() |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3222 |
.filter(e -> inferenceContext.free(e)).collect(List.collector()); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3223 |
List<Type> properList = thrownAtFuncType.diff(nonProperList); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3224 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3225 |
/** Let X1,...,Xm be the checked exception types that the lambda body can throw or |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3226 |
* in the throws clause of the invocation type of the method reference's compile-time |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3227 |
* declaration |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3228 |
*/ |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3229 |
List<Type> checkedList = thrownByFuncExpr.stream() |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3230 |
.filter(e -> chk.isChecked(e)).collect(List.collector()); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3231 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3232 |
/** If n = 0 (the function type's throws clause consists only of proper types), then |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3233 |
* if there exists some i (1 <= i <= m) such that Xi is not a subtype of any proper type |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3234 |
* in the throws clause, the constraint reduces to false; otherwise, the constraint |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3235 |
* reduces to true |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3236 |
*/ |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3237 |
ListBuffer<Type> uncaughtByProperTypes = new ListBuffer<>(); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3238 |
for (Type checked : checkedList) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3239 |
boolean isSubtype = false; |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3240 |
for (Type proper : properList) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3241 |
if (types.isSubtype(checked, proper)) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3242 |
isSubtype = true; |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3243 |
break; |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3244 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3245 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3246 |
if (!isSubtype) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3247 |
uncaughtByProperTypes.add(checked); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3248 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3249 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3250 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3251 |
if (nonProperList.isEmpty() && !uncaughtByProperTypes.isEmpty()) { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3252 |
return false; |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3253 |
} |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3254 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3255 |
/** If n > 0, the constraint reduces to a set of subtyping constraints: |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3256 |
* for all i (1 <= i <= m), if Xi is not a subtype of any proper type in the |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3257 |
* throws clause, then the constraints include, for all j (1 <= j <= n), <Xi <: Ej> |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3258 |
*/ |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3259 |
List<Type> nonProperAsUndet = inferenceContext.asUndetVars(nonProperList); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3260 |
uncaughtByProperTypes.forEach(checkedEx -> { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3261 |
nonProperAsUndet.forEach(nonProper -> { |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3262 |
types.isSubtype(checkedEx, nonProper); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3263 |
}); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3264 |
}); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3265 |
|
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3266 |
/** In addition, for all j (1 <= j <= n), the constraint reduces to the bound throws Ej |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3267 |
*/ |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3268 |
nonProperAsUndet.stream() |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3269 |
.filter(t -> t.hasTag(UNDETVAR)) |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3270 |
.forEach(t -> ((UndetVar)t).setThrow()); |
67f4f8f4d34a
8182047: javac compile error on type-parameter-exceptions in lambda expressions
vromero
parents:
45750
diff
changeset
|
3271 |
return true; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3272 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3273 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3274 |
/** |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3275 |
* 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
|
3276 |
* 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
|
3277 |
* current inference context. |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3278 |
*/ |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
3279 |
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
|
3280 |
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
|
3281 |
if (checkContext.inferenceContext().free(descriptorType)) { |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
3282 |
checkContext.inferenceContext().addFreeTypeListener(List.of(pt, descriptorType), |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
3283 |
inferenceContext -> setFunctionalInfo(env, fExpr, pt, inferenceContext.asInstType(descriptorType), |
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42822
diff
changeset
|
3284 |
inferenceContext.asInstType(primaryTarget), checkContext)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3285 |
} else { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
3286 |
ListBuffer<Type> targets = new ListBuffer<>(); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3287 |
if (pt.hasTag(CLASS)) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3288 |
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
|
3289 |
targets.append(types.removeWildcards(primaryTarget)); //this goes first |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3290 |
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
|
3291 |
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
|
3292 |
targets.append(types.removeWildcards(t)); |
16809
5acfcb821d65
8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents:
16808
diff
changeset
|
3293 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3294 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3295 |
} else { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
3296 |
targets.append(types.removeWildcards(primaryTarget)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3297 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3298 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3299 |
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
|
3300 |
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
|
3301 |
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
|
3302 |
//check that functional interface class is well-formed |
25273
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3303 |
try { |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3304 |
/* Types.makeFunctionalInterfaceClass() may throw an exception |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3305 |
* when it's executed post-inference. See the listener code |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3306 |
* above. |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3307 |
*/ |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3308 |
ClassSymbol csym = types.makeFunctionalInterfaceClass(env, |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3309 |
names.empty, List.of(fExpr.targets.head), ABSTRACT); |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3310 |
if (csym != null) { |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3311 |
chk.checkImplementations(env.tree, csym, csym); |
29553
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3312 |
try { |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3313 |
//perform an additional functional interface check on the synthetic class, |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3314 |
//as there may be spurious errors for raw targets - because of existing issues |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3315 |
//with membership and inheritance (see JDK-8074570). |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3316 |
csym.flags_field |= INTERFACE; |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3317 |
types.findDescriptorType(csym.type); |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3318 |
} catch (FunctionDescriptorLookupError err) { |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3319 |
resultInfo.checkContext.report(fExpr, |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3320 |
diags.fragment(Fragments.NoSuitableFunctionalIntfInst(fExpr.targets.head))); |
716d47f5a45e
8074381: java.lang.AssertionError during compiling
mcimadamore
parents:
29552
diff
changeset
|
3321 |
} |
25273
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3322 |
} |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3323 |
} catch (Types.FunctionDescriptorLookupError ex) { |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3324 |
JCDiagnostic cause = ex.getDiagnostic(); |
87443756f3ac
8038182: javac crash with FunctionDescriptorLookupError for invalid functional interface
vromero
parents:
25007
diff
changeset
|
3325 |
resultInfo.checkContext.report(env.tree, cause); |
19127
8a0cbd5cb055
8020804: javac crashes when speculative attribution infers intersection type with array component
mcimadamore
parents:
19122
diff
changeset
|
3326 |
} |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18662
diff
changeset
|
3327 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3328 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3329 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
3330 |
|
10 | 3331 |
public void visitParens(JCParens tree) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3332 |
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
|
3333 |
result = check(tree, owntype, pkind(), resultInfo); |
10 | 3334 |
Symbol sym = TreeInfo.symbol(tree); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3335 |
if (sym != null && sym.kind.matches(KindSelector.TYP_PCK)) |
45750
15404afd36ab
8058408: Compiler should emit a clearer message for invalid parenthesized expression
sadayapalam
parents:
45605
diff
changeset
|
3336 |
log.error(tree.pos(), Errors.IllegalParenthesizedExpression); |
10 | 3337 |
} |
3338 |
||
3339 |
public void visitAssign(JCAssign tree) { |
|
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3340 |
Type owntype = attribTree(tree.lhs, env.dup(tree), varAssignmentInfo); |
10 | 3341 |
Type capturedType = capture(owntype); |
3342 |
attribExpr(tree.rhs, env, owntype); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3343 |
result = check(tree, capturedType, KindSelector.VAL, resultInfo); |
10 | 3344 |
} |
3345 |
||
3346 |
public void visitAssignop(JCAssignOp tree) { |
|
3347 |
// Attribute arguments. |
|
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3348 |
Type owntype = attribTree(tree.lhs, env, varAssignmentInfo); |
10 | 3349 |
Type operand = attribExpr(tree.rhs, env); |
3350 |
// Find operator. |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
3351 |
Symbol operator = tree.operator = operators.resolveBinary(tree, tree.getTag().noAssignOp(), owntype, operand); |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39810
diff
changeset
|
3352 |
if (operator != operators.noOpSymbol && |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
3353 |
!owntype.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
3354 |
!operand.isErroneous()) { |
166 | 3355 |
chk.checkDivZero(tree.rhs.pos(), operator, operand); |
3356 |
chk.checkCastable(tree.rhs.pos(), |
|
3357 |
operator.type.getReturnType(), |
|
3358 |
owntype); |
|
10 | 3359 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3360 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
10 | 3361 |
} |
3362 |
||
3363 |
public void visitUnary(JCUnary tree) { |
|
3364 |
// Attribute arguments. |
|
10950 | 3365 |
Type argtype = (tree.getTag().isIncOrDecUnaryOp()) |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3366 |
? attribTree(tree.arg, env, varAssignmentInfo) |
10 | 3367 |
: chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env)); |
3368 |
||
3369 |
// Find operator. |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
3370 |
Symbol operator = tree.operator = operators.resolveUnary(tree, tree.getTag(), argtype); |
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
|
3371 |
Type owntype = types.createErrorType(tree.type); |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39810
diff
changeset
|
3372 |
if (operator != operators.noOpSymbol && |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
3373 |
!argtype.isErroneous()) { |
10950 | 3374 |
owntype = (tree.getTag().isIncOrDecUnaryOp()) |
10 | 3375 |
? tree.arg.type |
3376 |
: operator.type.getReturnType(); |
|
3377 |
int opc = ((OperatorSymbol)operator).opcode; |
|
3378 |
||
3379 |
// If the argument is constant, fold it. |
|
3380 |
if (argtype.constValue() != null) { |
|
3381 |
Type ctype = cfolder.fold1(opc, argtype); |
|
3382 |
if (ctype != null) { |
|
3383 |
owntype = cfolder.coerce(ctype, owntype); |
|
3384 |
} |
|
3385 |
} |
|
3386 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3387 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
10 | 3388 |
} |
3389 |
||
3390 |
public void visitBinary(JCBinary tree) { |
|
3391 |
// Attribute arguments. |
|
3392 |
Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env)); |
|
29552
690d0becaf32
8074148: Attr.visitBinary flags error at wrong position
sadayapalam
parents:
29430
diff
changeset
|
3393 |
Type right = chk.checkNonVoid(tree.rhs.pos(), attribExpr(tree.rhs, env)); |
10 | 3394 |
// Find operator. |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
3395 |
Symbol operator = tree.operator = operators.resolveBinary(tree, tree.getTag(), left, right); |
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
|
3396 |
Type owntype = types.createErrorType(tree.type); |
39920
4923274643f2
8161708: javac, consider a different way to handle access code for operators
vromero
parents:
39810
diff
changeset
|
3397 |
if (operator != operators.noOpSymbol && |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
3398 |
!left.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
3399 |
!right.isErroneous()) { |
10 | 3400 |
owntype = operator.type.getReturnType(); |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
3401 |
int opc = ((OperatorSymbol)operator).opcode; |
10 | 3402 |
// If both arguments are constants, fold them. |
3403 |
if (left.constValue() != null && right.constValue() != null) { |
|
3404 |
Type ctype = cfolder.fold2(opc, left, right); |
|
3405 |
if (ctype != null) { |
|
3406 |
owntype = cfolder.coerce(ctype, owntype); |
|
3407 |
} |
|
3408 |
} |
|
3409 |
||
3410 |
// Check that argument types of a reference ==, != are |
|
18662
1cac45e71eb9
8013357: javac accepts erroneous binary comparison operations
emc
parents:
18657
diff
changeset
|
3411 |
// castable to each other, (JLS 15.21). Note: unboxing |
1cac45e71eb9
8013357: javac accepts erroneous binary comparison operations
emc
parents:
18657
diff
changeset
|
3412 |
// comparisons will not have an acmp* opc at this point. |
10 | 3413 |
if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) { |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
3414 |
if (!types.isCastable(left, right, new Warner(tree.pos()))) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3415 |
log.error(tree.pos(), Errors.IncomparableTypes(left, right)); |
10 | 3416 |
} |
3417 |
} |
|
3418 |
||
3419 |
chk.checkDivZero(tree.rhs.pos(), operator, right); |
|
3420 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3421 |
result = check(tree, owntype, KindSelector.VAL, resultInfo); |
10 | 3422 |
} |
3423 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3424 |
public void visitTypeCast(final JCTypeCast tree) { |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
3425 |
Type clazztype = attribType(tree.clazz, env); |
6351 | 3426 |
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
|
3427 |
//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
|
3428 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
3429 |
Env<AttrContext> localEnv = env.dup(tree); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3430 |
//should we propagate the target type? |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3431 |
final ResultInfo castInfo; |
16975
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16972
diff
changeset
|
3432 |
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
|
3433 |
boolean isPoly = allowPoly && (expr.hasTag(LAMBDA) || expr.hasTag(REFERENCE)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3434 |
if (isPoly) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3435 |
//expression is a poly - we need to propagate target type info |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3436 |
castInfo = new ResultInfo(KindSelector.VAL, clazztype, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3437 |
new Check.NestedCheckContext(resultInfo.checkContext) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3438 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3439 |
public boolean compatible(Type found, Type req, Warner warn) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3440 |
return types.isCastable(found, req, warn); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3441 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3442 |
}); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3443 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3444 |
//standalone cast - target-type info is not propagated |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3445 |
castInfo = unknownExprInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3446 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3447 |
Type exprtype = attribTree(tree.expr, localEnv, castInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3448 |
Type owntype = isPoly ? clazztype : chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
10 | 3449 |
if (exprtype.constValue() != null) |
3450 |
owntype = cfolder.coerce(exprtype, owntype); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3451 |
result = check(tree, capture(owntype), KindSelector.VAL, resultInfo); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3452 |
if (!isPoly) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3453 |
chk.checkRedundantCast(localEnv, tree); |
10 | 3454 |
} |
3455 |
||
3456 |
public void visitTypeTest(JCInstanceOf tree) { |
|
3457 |
Type exprtype = chk.checkNullOrRefType( |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3458 |
tree.expr.pos(), attribExpr(tree.expr, env)); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
3459 |
Type clazztype = attribType(tree.clazz, env); |
20251
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3460 |
if (!clazztype.hasTag(TYPEVAR)) { |
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3461 |
clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype); |
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3462 |
} |
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3463 |
if (!clazztype.isErroneous() && !types.isReifiable(clazztype)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3464 |
log.error(tree.clazz.pos(), Errors.IllegalGenericTypeForInstof); |
20251
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3465 |
clazztype = types.createErrorType(clazztype); |
90a73be53aa0
4881267: improve diagnostic for "instanceof T" for type parameter T
kizune
parents:
20249
diff
changeset
|
3466 |
} |
6351 | 3467 |
chk.validate(tree.clazz, env, false); |
10 | 3468 |
chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3469 |
result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo); |
10 | 3470 |
} |
3471 |
||
3472 |
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
|
3473 |
Type owntype = types.createErrorType(tree.type); |
10 | 3474 |
Type atype = attribExpr(tree.indexed, env); |
3475 |
attribExpr(tree.index, env, syms.intType); |
|
3476 |
if (types.isArray(atype)) |
|
3477 |
owntype = types.elemtype(atype); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3478 |
else if (!atype.hasTag(ERROR)) |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3479 |
log.error(tree.pos(), Errors.ArrayReqButFound(atype)); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3480 |
if (!pkind().contains(KindSelector.VAL)) |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3481 |
owntype = capture(owntype); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3482 |
result = check(tree, owntype, KindSelector.VAR, resultInfo); |
10 | 3483 |
} |
3484 |
||
3485 |
public void visitIdent(JCIdent tree) { |
|
3486 |
Symbol sym; |
|
3487 |
||
3488 |
// Find symbol |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3489 |
if (pt().hasTag(METHOD) || pt().hasTag(FORALL)) { |
10 | 3490 |
// If we are looking for a method, the prototype `pt' will be a |
3491 |
// 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
|
3492 |
env.info.pendingResolutionPhase = null; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3493 |
sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments()); |
10 | 3494 |
} else if (tree.sym != null && tree.sym.kind != VAR) { |
3495 |
sym = tree.sym; |
|
3496 |
} else { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3497 |
sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind()); |
10 | 3498 |
} |
3499 |
tree.sym = sym; |
|
3500 |
||
3501 |
// (1) Also find the environment current for the class where |
|
3502 |
// sym is defined (`symEnv'). |
|
3503 |
// Only for pre-tiger versions (1.4 and earlier): |
|
3504 |
// (2) Also determine whether we access symbol out of an anonymous |
|
3505 |
// class in a this or super call. This is illegal for instance |
|
3506 |
// members since such classes don't carry a this$n link. |
|
3507 |
// (`noOuterThisPath'). |
|
3508 |
Env<AttrContext> symEnv = env; |
|
3509 |
boolean noOuterThisPath = false; |
|
3510 |
if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3511 |
sym.kind.matches(KindSelector.VAL_MTH) && |
10 | 3512 |
sym.owner.kind == TYP && |
3513 |
tree.name != names._this && tree.name != names._super) { |
|
3514 |
||
3515 |
// Find environment in which identifier is defined. |
|
3516 |
while (symEnv.outer != null && |
|
3517 |
!sym.isMemberOf(symEnv.enclClass.sym, types)) { |
|
3518 |
if ((symEnv.enclClass.sym.flags() & NOOUTERTHIS) != 0) |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
3519 |
noOuterThisPath = false; |
10 | 3520 |
symEnv = symEnv.outer; |
3521 |
} |
|
3522 |
} |
|
3523 |
||
3524 |
// If symbol is a variable, ... |
|
3525 |
if (sym.kind == VAR) { |
|
3526 |
VarSymbol v = (VarSymbol)sym; |
|
3527 |
||
3528 |
// ..., evaluate its initializer, if it has one, and check for |
|
3529 |
// illegal forward reference. |
|
3530 |
checkInit(tree, env, v, false); |
|
3531 |
||
3532 |
// If we are expecting a variable (as opposed to a value), check |
|
3533 |
// that the variable is assignable in the current environment. |
|
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3534 |
if (KindSelector.ASG.subset(pkind())) |
10 | 3535 |
checkAssignable(tree.pos(), v, null, env); |
3536 |
} |
|
3537 |
||
3538 |
// In a constructor body, |
|
3539 |
// if symbol is a field or instance method, check that it is |
|
3540 |
// not accessed before the supertype constructor is called. |
|
3541 |
if ((symEnv.info.isSelfCall || noOuterThisPath) && |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3542 |
sym.kind.matches(KindSelector.VAL_MTH) && |
10 | 3543 |
sym.owner.kind == TYP && |
3544 |
(sym.flags() & STATIC) == 0) { |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3545 |
chk.earlyRefError(tree.pos(), sym.kind == VAR ? |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3546 |
sym : thisSym(tree.pos(), env)); |
10 | 3547 |
} |
3548 |
Env<AttrContext> env1 = env; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3549 |
if (sym.kind != ERR && sym.kind != TYP && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3550 |
sym.owner != null && sym.owner != env1.enclClass.sym) { |
10 | 3551 |
// If the found symbol is inaccessible, then it is |
3552 |
// accessed through an enclosing instance. Locate this |
|
3553 |
// enclosing instance: |
|
3554 |
while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) |
|
3555 |
env1 = env1.outer; |
|
3556 |
} |
|
24219 | 3557 |
|
3558 |
if (env.info.isSerializable) { |
|
41629 | 3559 |
chk.checkAccessFromSerializableElement(tree, env.info.isLambda); |
24219 | 3560 |
} |
3561 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3562 |
result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); |
10 | 3563 |
} |
3564 |
||
3565 |
public void visitSelect(JCFieldAccess tree) { |
|
3566 |
// Determine the expected kind of the qualifier expression. |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3567 |
KindSelector skind = KindSelector.NIL; |
10 | 3568 |
if (tree.name == names._this || tree.name == names._super || |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3569 |
tree.name == names._class) |
10 | 3570 |
{ |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3571 |
skind = KindSelector.TYP; |
10 | 3572 |
} else { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3573 |
if (pkind().contains(KindSelector.PCK)) |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3574 |
skind = KindSelector.of(skind, KindSelector.PCK); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3575 |
if (pkind().contains(KindSelector.TYP)) |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3576 |
skind = KindSelector.of(skind, KindSelector.TYP, KindSelector.PCK); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3577 |
if (pkind().contains(KindSelector.VAL_MTH)) |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3578 |
skind = KindSelector.of(skind, KindSelector.VAL, KindSelector.TYP); |
10 | 3579 |
} |
3580 |
||
3581 |
// Attribute the qualifier expression, and determine its symbol (if any). |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
3582 |
Type site = attribTree(tree.selected, env, new ResultInfo(skind, Type.noType)); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3583 |
if (!pkind().contains(KindSelector.TYP_PCK)) |
10 | 3584 |
site = capture(site); // Capture field access |
3585 |
||
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
3586 |
// don't allow T.class T[].class, etc |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3587 |
if (skind == KindSelector.TYP) { |
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24794
diff
changeset
|
3588 |
Type elt = site; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3589 |
while (elt.hasTag(ARRAY)) |
24396 | 3590 |
elt = ((ArrayType)elt).elemtype; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3591 |
if (elt.hasTag(TYPEVAR)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3592 |
log.error(tree.pos(), Errors.TypeVarCantBeDeref); |
26780
82b0aaba473d
8057794: Compiler Error when obtaining .class property
jlahoda
parents:
26532
diff
changeset
|
3593 |
result = tree.type = types.createErrorType(tree.name, site.tsym, site); |
82b0aaba473d
8057794: Compiler Error when obtaining .class property
jlahoda
parents:
26532
diff
changeset
|
3594 |
tree.sym = tree.type.tsym; |
82b0aaba473d
8057794: Compiler Error when obtaining .class property
jlahoda
parents:
26532
diff
changeset
|
3595 |
return ; |
10 | 3596 |
} |
3597 |
} |
|
3598 |
||
3599 |
// If qualifier symbol is a type or `super', assert `selectSuper' |
|
3600 |
// for the selection. This is relevant for determining whether |
|
3601 |
// protected symbols are accessible. |
|
3602 |
Symbol sitesym = TreeInfo.symbol(tree.selected); |
|
3603 |
boolean selectSuperPrev = env.info.selectSuper; |
|
3604 |
env.info.selectSuper = |
|
3605 |
sitesym != null && |
|
3606 |
sitesym.name == names._super; |
|
3607 |
||
3608 |
// Determine the symbol represented by the selection. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3609 |
env.info.pendingResolutionPhase = null; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3610 |
Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); |
27845
afce9de2de10
8059921: Missing compile error in Java 8 mode for Interface.super.field access
vromero
parents:
27844
diff
changeset
|
3611 |
if (sym.kind == VAR && sym.name != names._super && env.info.defaultSuperCallSite != null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3612 |
log.error(tree.selected.pos(), Errors.NotEnclClass(site.tsym)); |
27845
afce9de2de10
8059921: Missing compile error in Java 8 mode for Interface.super.field access
vromero
parents:
27844
diff
changeset
|
3613 |
sym = syms.errSymbol; |
afce9de2de10
8059921: Missing compile error in Java 8 mode for Interface.super.field access
vromero
parents:
27844
diff
changeset
|
3614 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3615 |
if (sym.exists() && !isType(sym) && pkind().contains(KindSelector.TYP_PCK)) { |
10 | 3616 |
site = capture(site); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3617 |
sym = selectSym(tree, sitesym, site, env, resultInfo); |
10 | 3618 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3619 |
boolean varArgs = env.info.lastResolveVarargs(); |
10 | 3620 |
tree.sym = sym; |
3621 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3622 |
if (site.hasTag(TYPEVAR) && !isType(sym) && sym.kind != ERR) { |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29147
diff
changeset
|
3623 |
site = types.skipTypeVars(site, true); |
511
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
3624 |
} |
10 | 3625 |
|
3626 |
// If that symbol is a variable, ... |
|
3627 |
if (sym.kind == VAR) { |
|
3628 |
VarSymbol v = (VarSymbol)sym; |
|
3629 |
||
3630 |
// ..., evaluate its initializer, if it has one, and check for |
|
3631 |
// illegal forward reference. |
|
3632 |
checkInit(tree, env, v, true); |
|
3633 |
||
3634 |
// If we are expecting a variable (as opposed to a value), check |
|
3635 |
// that the variable is assignable in the current environment. |
|
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3636 |
if (KindSelector.ASG.subset(pkind())) |
10 | 3637 |
checkAssignable(tree.pos(), v, tree.selected, env); |
3638 |
} |
|
3639 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3640 |
if (sitesym != null && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3641 |
sitesym.kind == VAR && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3642 |
((VarSymbol)sitesym).isResourceVariable() && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3643 |
sym.kind == MTH && |
9079
e512a7712be3
7032633: javac -Xlint:all warns about flush() within try on an auto-closeable resource
mcimadamore
parents:
9076
diff
changeset
|
3644 |
sym.name.equals(names.close) && |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3645 |
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
|
3646 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3647 |
log.warning(LintCategory.TRY, tree, Warnings.TryExplicitCloseCall); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3648 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
3649 |
|
10 | 3650 |
// Disallow selecting a type from an expression |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3651 |
if (isType(sym) && (sitesym == null || !sitesym.kind.matches(KindSelector.TYP_PCK))) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3652 |
tree.type = check(tree.selected, pt(), |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3653 |
sitesym == null ? |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3654 |
KindSelector.VAL : sitesym.kind.toSelector(), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3655 |
new ResultInfo(KindSelector.TYP_PCK, pt())); |
10 | 3656 |
} |
3657 |
||
3658 |
if (isType(sitesym)) { |
|
3659 |
if (sym.name == names._this) { |
|
3660 |
// If `C' is the currently compiled class, check that |
|
3661 |
// C.this' does not appear in a call to a super(...) |
|
3662 |
if (env.info.isSelfCall && |
|
3663 |
site.tsym == env.enclClass.sym) { |
|
3664 |
chk.earlyRefError(tree.pos(), sym); |
|
3665 |
} |
|
3666 |
} else { |
|
3667 |
// Check if type-qualified fields or methods are static (JLS) |
|
3668 |
if ((sym.flags() & STATIC) == 0 && |
|
3669 |
sym.name != names._super && |
|
3670 |
(sym.kind == VAR || sym.kind == MTH)) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3671 |
rs.accessBase(rs.new StaticError(sym), |
10 | 3672 |
tree.pos(), site, sym.name, true); |
3673 |
} |
|
3674 |
} |
|
24901
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
3675 |
if (!allowStaticInterfaceMethods && sitesym.isInterface() && |
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
3676 |
sym.isStatic() && sym.kind == MTH) { |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47318
diff
changeset
|
3677 |
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.pos(), Feature.STATIC_INTERFACE_METHODS_INVOKE.error(sourceName)); |
24901
73bacb7d064e
8037385: constant pool errors with -target 1.7 and static default methods
dlsmith
parents:
24900
diff
changeset
|
3678 |
} |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3679 |
} else if (sym.kind != ERR && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3680 |
(sym.flags() & STATIC) != 0 && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3681 |
sym.name != names._class) { |
5002
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
3682 |
// 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
|
3683 |
// a warning. Make allowance for the class of an array type e.g. Object[].class) |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
3684 |
chk.warnStatic(tree, Warnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); |
10 | 3685 |
} |
3686 |
||
3687 |
// If we are selecting an instance member via a `super', ... |
|
3688 |
if (env.info.selectSuper && (sym.flags() & STATIC) == 0) { |
|
3689 |
||
3690 |
// Check that super-qualified symbols are not abstract (JLS) |
|
3691 |
rs.checkNonAbstract(tree.pos(), sym); |
|
3692 |
||
3693 |
if (site.isRaw()) { |
|
3694 |
// Determine argument types for site. |
|
3695 |
Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym); |
|
3696 |
if (site1 != null) site = site1; |
|
3697 |
} |
|
3698 |
} |
|
3699 |
||
24219 | 3700 |
if (env.info.isSerializable) { |
41629 | 3701 |
chk.checkAccessFromSerializableElement(tree, env.info.isLambda); |
24219 | 3702 |
} |
3703 |
||
10 | 3704 |
env.info.selectSuper = selectSuperPrev; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3705 |
result = checkId(tree, site, sym, env, resultInfo); |
10 | 3706 |
} |
3707 |
//where |
|
3708 |
/** Determine symbol referenced by a Select expression, |
|
3709 |
* |
|
3710 |
* @param tree The select tree. |
|
3711 |
* @param site The type of the selected expression, |
|
3712 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3713 |
* @param resultInfo The current result. |
10 | 3714 |
*/ |
3715 |
private Symbol selectSym(JCFieldAccess tree, |
|
8045 | 3716 |
Symbol location, |
10 | 3717 |
Type site, |
3718 |
Env<AttrContext> env, |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3719 |
ResultInfo resultInfo) { |
10 | 3720 |
DiagnosticPosition pos = tree.pos(); |
3721 |
Name name = tree.name; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3722 |
switch (site.getTag()) { |
10 | 3723 |
case PACKAGE: |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3724 |
return rs.accessBase( |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3725 |
rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), |
8045 | 3726 |
pos, location, site, name, true); |
10 | 3727 |
case ARRAY: |
3728 |
case CLASS: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3729 |
if (resultInfo.pt.hasTag(METHOD) || resultInfo.pt.hasTag(FORALL)) { |
10 | 3730 |
return rs.resolveQualifiedMethod( |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3731 |
pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments()); |
10 | 3732 |
} else if (name == names._this || name == names._super) { |
3733 |
return rs.resolveSelf(pos, env, site.tsym, name); |
|
3734 |
} else if (name == names._class) { |
|
3735 |
// In this case, we have already made sure in |
|
3736 |
// visitSelect that qualifier expression is a type. |
|
49887 | 3737 |
return syms.getClassField(site, types); |
10 | 3738 |
} else { |
3739 |
// 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
|
3740 |
Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3741 |
sym = rs.accessBase(sym, pos, location, site, name, true); |
10 | 3742 |
return sym; |
3743 |
} |
|
3744 |
case WILDCARD: |
|
3745 |
throw new AssertionError(tree); |
|
3746 |
case TYPEVAR: |
|
3747 |
// Normally, site.getUpperBound() shouldn't be null. |
|
3748 |
// It should only happen during memberEnter/attribBase |
|
8045 | 3749 |
// when determining the super type which *must* beac |
10 | 3750 |
// done before attributing the type variables. In |
3751 |
// other words, we are seeing this illegal program: |
|
3752 |
// class B<T> extends A<T.foo> {} |
|
3753 |
Symbol sym = (site.getUpperBound() != null) |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3754 |
? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo) |
10 | 3755 |
: null; |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
3756 |
if (sym == null) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3757 |
log.error(pos, Errors.TypeVarCantBeDeref); |
10 | 3758 |
return syms.errSymbol; |
3759 |
} else { |
|
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
3760 |
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
|
3761 |
rs.new AccessError(env, site, sym) : |
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
3762 |
sym; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3763 |
rs.accessBase(sym2, pos, location, site, name, true); |
10 | 3764 |
return sym; |
3765 |
} |
|
3766 |
case ERROR: |
|
3767 |
// 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
|
3768 |
return types.createErrorType(name, site.tsym, site).tsym; |
10 | 3769 |
default: |
3770 |
// The qualifier expression is of a primitive type -- only |
|
3771 |
// .class is allowed for these. |
|
3772 |
if (name == names._class) { |
|
3773 |
// In this case, we have already made sure in Select that |
|
3774 |
// qualifier expression is a type. |
|
49887 | 3775 |
return syms.getClassField(site, types); |
10 | 3776 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
3777 |
log.error(pos, Errors.CantDeref(site)); |
10 | 3778 |
return syms.errSymbol; |
3779 |
} |
|
3780 |
} |
|
3781 |
} |
|
3782 |
||
3783 |
/** Determine type of identifier or select expression and check that |
|
3784 |
* (1) the referenced symbol is not deprecated |
|
3785 |
* (2) the symbol's type is safe (@see checkSafe) |
|
3786 |
* (3) if symbol is a variable, check that its type and kind are |
|
3787 |
* compatible with the prototype and protokind. |
|
3788 |
* (4) if symbol is an instance field of a raw type, |
|
3789 |
* which is being assigned to, issue an unchecked warning if its |
|
3790 |
* type changes under erasure. |
|
3791 |
* (5) if symbol is an instance method of a raw type, issue an |
|
3792 |
* unchecked warning if its argument types change under erasure. |
|
3793 |
* If checks succeed: |
|
3794 |
* If symbol is a constant, return its constant type |
|
3795 |
* else if symbol is a method, return its result type |
|
3796 |
* otherwise return its type. |
|
3797 |
* Otherwise return errType. |
|
3798 |
* |
|
3799 |
* @param tree The syntax tree representing the identifier |
|
3800 |
* @param site If this is a select, the type of the selected |
|
3801 |
* expression, otherwise the type of the current class. |
|
3802 |
* @param sym The symbol representing the identifier. |
|
3803 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
3804 |
* @param resultInfo The expected result |
10 | 3805 |
*/ |
3806 |
Type checkId(JCTree tree, |
|
3807 |
Type site, |
|
3808 |
Symbol sym, |
|
3809 |
Env<AttrContext> env, |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3810 |
ResultInfo resultInfo) { |
14547 | 3811 |
return (resultInfo.pt.hasTag(FORALL) || resultInfo.pt.hasTag(METHOD)) ? |
3812 |
checkMethodId(tree, site, sym, env, resultInfo) : |
|
3813 |
checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo); |
|
3814 |
} |
|
3815 |
||
3816 |
Type checkMethodId(JCTree tree, |
|
3817 |
Type site, |
|
3818 |
Symbol sym, |
|
3819 |
Env<AttrContext> env, |
|
3820 |
ResultInfo resultInfo) { |
|
3821 |
boolean isPolymorhicSignature = |
|
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
18382
diff
changeset
|
3822 |
(sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) != 0; |
14547 | 3823 |
return isPolymorhicSignature ? |
3824 |
checkSigPolyMethodId(tree, site, sym, env, resultInfo) : |
|
3825 |
checkMethodIdInternal(tree, site, sym, env, resultInfo); |
|
3826 |
} |
|
3827 |
||
3828 |
Type checkSigPolyMethodId(JCTree tree, |
|
3829 |
Type site, |
|
3830 |
Symbol sym, |
|
3831 |
Env<AttrContext> env, |
|
3832 |
ResultInfo resultInfo) { |
|
3833 |
//recover original symbol for signature polymorphic methods |
|
3834 |
checkMethodIdInternal(tree, site, sym.baseSymbol(), env, resultInfo); |
|
3835 |
env.info.pendingResolutionPhase = Resolve.MethodResolutionPhase.BASIC; |
|
3836 |
return sym.type; |
|
3837 |
} |
|
3838 |
||
3839 |
Type checkMethodIdInternal(JCTree tree, |
|
3840 |
Type site, |
|
3841 |
Symbol sym, |
|
3842 |
Env<AttrContext> env, |
|
3843 |
ResultInfo resultInfo) { |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3844 |
if (resultInfo.pkind.contains(KindSelector.POLY)) { |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
3845 |
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
|
3846 |
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
|
3847 |
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
|
3848 |
return owntype; |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
3849 |
} else { |
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
18412
diff
changeset
|
3850 |
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
|
3851 |
} |
14547 | 3852 |
} |
3853 |
||
3854 |
Type checkIdInternal(JCTree tree, |
|
3855 |
Type site, |
|
3856 |
Symbol sym, |
|
3857 |
Type pt, |
|
3858 |
Env<AttrContext> env, |
|
3859 |
ResultInfo resultInfo) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3860 |
if (pt.isErroneous()) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3861 |
return types.createErrorType(site); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3862 |
} |
10 | 3863 |
Type owntype; // The computed type of this identifier occurrence. |
3864 |
switch (sym.kind) { |
|
3865 |
case TYP: |
|
3866 |
// For types, the computed type equals the symbol's type, |
|
3867 |
// except for two situations: |
|
3868 |
owntype = sym.type; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3869 |
if (owntype.hasTag(CLASS)) { |
14369
3d660d08d1f7
7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents:
14366
diff
changeset
|
3870 |
chk.checkForBadAuxiliaryClassAccess(tree.pos(), env, (ClassSymbol)sym); |
10 | 3871 |
Type ownOuter = owntype.getEnclosingType(); |
3872 |
||
3873 |
// (a) If the symbol's type is parameterized, erase it |
|
3874 |
// because no type parameters were given. |
|
3875 |
// We recover generic outer type later in visitTypeApply. |
|
3876 |
if (owntype.tsym.type.getTypeArguments().nonEmpty()) { |
|
3877 |
owntype = types.erasure(owntype); |
|
3878 |
} |
|
3879 |
||
3880 |
// (b) If the symbol's type is an inner class, then |
|
3881 |
// we have to interpret its outer type as a superclass |
|
3882 |
// of the site type. Example: |
|
3883 |
// |
|
3884 |
// class Tree<A> { class Visitor { ... } } |
|
3885 |
// class PointTree extends Tree<Point> { ... } |
|
3886 |
// ...PointTree.Visitor... |
|
3887 |
// |
|
3888 |
// Then the type of the last expression above is |
|
3889 |
// Tree<Point>.Visitor. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3890 |
else if (ownOuter.hasTag(CLASS) && site != ownOuter) { |
10 | 3891 |
Type normOuter = site; |
15385 | 3892 |
if (normOuter.hasTag(CLASS)) { |
10 | 3893 |
normOuter = types.asEnclosingSuper(site, ownOuter.tsym); |
15385 | 3894 |
} |
10 | 3895 |
if (normOuter == null) // perhaps from an import |
3896 |
normOuter = types.erasure(ownOuter); |
|
3897 |
if (normOuter != ownOuter) |
|
3898 |
owntype = new ClassType( |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
3899 |
normOuter, List.nil(), owntype.tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
3900 |
owntype.getMetadata()); |
10 | 3901 |
} |
3902 |
} |
|
3903 |
break; |
|
3904 |
case VAR: |
|
3905 |
VarSymbol v = (VarSymbol)sym; |
|
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3906 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3907 |
if (env.info.enclVar != null |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3908 |
&& v.type.hasTag(NONE)) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3909 |
//self reference to implicitly typed variable declaration |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3910 |
log.error(TreeInfo.positionFor(v, env.enclClass), Errors.CantInferLocalVarType(v.name, Fragments.LocalSelfRef)); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3911 |
return v.type = types.createErrorType(v.type); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3912 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
3913 |
|
10 | 3914 |
// Test (4): if symbol is an instance field of a raw type, |
3915 |
// which is being assigned to, issue an unchecked warning if |
|
3916 |
// its type changes under erasure. |
|
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27553
diff
changeset
|
3917 |
if (KindSelector.ASG.subset(pkind()) && |
10 | 3918 |
v.owner.kind == TYP && |
3919 |
(v.flags() & STATIC) == 0 && |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3920 |
(site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
10 | 3921 |
Type s = types.asOuterSuper(site, v.owner); |
3922 |
if (s != null && |
|
3923 |
s.isRaw() && |
|
3924 |
!types.isSameType(v.type, v.erasure(types))) { |
|
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
3925 |
chk.warnUnchecked(tree.pos(), Warnings.UncheckedAssignToVar(v, s)); |
10 | 3926 |
} |
3927 |
} |
|
3928 |
// The computed type of a variable is the type of the |
|
3929 |
// variable symbol, taken as a member of the site type. |
|
3930 |
owntype = (sym.owner.kind == TYP && |
|
3931 |
sym.name != names._this && sym.name != names._super) |
|
3932 |
? types.memberType(site, sym) |
|
3933 |
: sym.type; |
|
3934 |
||
3935 |
// If the variable is a constant, record constant value in |
|
3936 |
// computed type. |
|
3937 |
if (v.getConstValue() != null && isStaticReference(tree)) |
|
3938 |
owntype = owntype.constType(v.getConstValue()); |
|
3939 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3940 |
if (resultInfo.pkind == KindSelector.VAL) { |
10 | 3941 |
owntype = capture(owntype); // capture "names as expressions" |
3942 |
} |
|
3943 |
break; |
|
3944 |
case MTH: { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
3945 |
owntype = checkMethod(site, sym, |
44392
e21b18355690
8177097: Generic method reference returning wildcard parameterized type does not compile
mcimadamore
parents:
44194
diff
changeset
|
3946 |
new ResultInfo(resultInfo.pkind, resultInfo.pt.getReturnType(), resultInfo.checkContext, resultInfo.checkMode), |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
13689
diff
changeset
|
3947 |
env, TreeInfo.args(env.tree), resultInfo.pt.getParameterTypes(), |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
3948 |
resultInfo.pt.getTypeArguments()); |
10 | 3949 |
break; |
3950 |
} |
|
3951 |
case PCK: case ERR: |
|
3952 |
owntype = sym.type; |
|
3953 |
break; |
|
3954 |
default: |
|
3955 |
throw new AssertionError("unexpected kind: " + sym.kind + |
|
3956 |
" in tree " + tree); |
|
3957 |
} |
|
3958 |
||
32950
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3959 |
// Emit a `deprecation' warning if symbol is deprecated. |
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3960 |
// (for constructors (but not for constructor references), the error |
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3961 |
// was given when the constructor was resolved) |
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3962 |
|
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3963 |
if (sym.name != names.init || tree.hasTag(REFERENCE)) { |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
3964 |
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
|
3965 |
chk.checkSunAPI(tree.pos(), sym); |
15724 | 3966 |
chk.checkProfile(tree.pos(), sym); |
3661 | 3967 |
} |
10 | 3968 |
|
32950
22315d47485b
8065219: Deprecated warning in method reference are missing in some cases.
sadayapalam
parents:
32912
diff
changeset
|
3969 |
// If symbol is a variable, check that its type and |
10 | 3970 |
// kind are compatible with the prototype and protokind. |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3971 |
return check(tree, owntype, sym.kind.toSelector(), resultInfo); |
10 | 3972 |
} |
3973 |
||
3974 |
/** Check that variable is initialized and evaluate the variable's |
|
3975 |
* initializer, if not yet done. Also check that variable is not |
|
3976 |
* referenced before it is defined. |
|
3977 |
* @param tree The tree making up the variable reference. |
|
3978 |
* @param env The current environment. |
|
3979 |
* @param v The variable's symbol. |
|
3980 |
*/ |
|
3981 |
private void checkInit(JCTree tree, |
|
3982 |
Env<AttrContext> env, |
|
3983 |
VarSymbol v, |
|
3984 |
boolean onlyWarning) { |
|
3985 |
// A forward reference is diagnosed if the declaration position |
|
3986 |
// of the variable is greater than the current tree position |
|
3987 |
// and the tree and variable definition occur in the same class |
|
3988 |
// definition. Note that writes don't count as references. |
|
3989 |
// This check applies only to class and instance |
|
3990 |
// variables. Local variables follow different scope rules, |
|
3991 |
// and are subject to definite assignment checking. |
|
32164
6c65d5b414bc
8053906: javac is accepting a self-referencing variable initializer inside a lambda expression
vromero
parents:
31937
diff
changeset
|
3992 |
Env<AttrContext> initEnv = enclosingInitEnv(env); |
6c65d5b414bc
8053906: javac is accepting a self-referencing variable initializer inside a lambda expression
vromero
parents:
31937
diff
changeset
|
3993 |
if (initEnv != null && |
6c65d5b414bc
8053906: javac is accepting a self-referencing variable initializer inside a lambda expression
vromero
parents:
31937
diff
changeset
|
3994 |
(initEnv.info.enclVar == v || v.pos > tree.pos) && |
10 | 3995 |
v.owner.kind == TYP && |
3996 |
v.owner == env.info.scope.owner.enclClass() && |
|
3997 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && |
|
10950 | 3998 |
(!env.tree.hasTag(ASSIGN) || |
10 | 3999 |
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { |
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4000 |
if (!onlyWarning || isStaticEnumField(v)) { |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4001 |
Error errkey = (initEnv.info.enclVar == v) ? |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4002 |
Errors.IllegalSelfRef : Errors.IllegalForwardRef; |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4003 |
log.error(tree.pos(), errkey); |
10 | 4004 |
} else if (useBeforeDeclarationWarning) { |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4005 |
Warning warnkey = (initEnv.info.enclVar == v) ? |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4006 |
Warnings.SelfRef(v) : Warnings.ForwardRef(v); |
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4007 |
log.warning(tree.pos(), warnkey); |
10 | 4008 |
} |
4009 |
} |
|
4010 |
||
4011 |
v.getConstValue(); // ensure initializer is evaluated |
|
4012 |
||
4013 |
checkEnumInitializer(tree, env, v); |
|
4014 |
} |
|
4015 |
||
4016 |
/** |
|
25846
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4017 |
* Returns the enclosing init environment associated with this env (if any). An init env |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4018 |
* can be either a field declaration env or a static/instance initializer env. |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4019 |
*/ |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4020 |
Env<AttrContext> enclosingInitEnv(Env<AttrContext> env) { |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4021 |
while (true) { |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4022 |
switch (env.tree.getTag()) { |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4023 |
case VARDEF: |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4024 |
JCVariableDecl vdecl = (JCVariableDecl)env.tree; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4025 |
if (vdecl.sym.owner.kind == TYP) { |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4026 |
//field |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4027 |
return env; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4028 |
} |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4029 |
break; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4030 |
case BLOCK: |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4031 |
if (env.next.tree.hasTag(CLASSDEF)) { |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4032 |
//instance/static initializer |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4033 |
return env; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4034 |
} |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4035 |
break; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4036 |
case METHODDEF: |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4037 |
case CLASSDEF: |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4038 |
case TOPLEVEL: |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4039 |
return null; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4040 |
} |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4041 |
Assert.checkNonNull(env.next); |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4042 |
env = env.next; |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4043 |
} |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4044 |
} |
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4045 |
|
e7124d0dc984
8051958: Cannot assign a value to final variable in lambda
mcimadamore
parents:
25844
diff
changeset
|
4046 |
/** |
10 | 4047 |
* Check for illegal references to static members of enum. In |
4048 |
* an enum type, constructors and initializers may not |
|
4049 |
* reference its static members unless they are constant. |
|
4050 |
* |
|
4051 |
* @param tree The tree making up the variable reference. |
|
4052 |
* @param env The current environment. |
|
4053 |
* @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
|
4054 |
* @jls section 8.9 Enums |
10 | 4055 |
*/ |
4056 |
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
|
4057 |
// JLS: |
10 | 4058 |
// |
4059 |
// "It is a compile-time error to reference a static field |
|
4060 |
// of an enum type that is not a compile-time constant |
|
4061 |
// (15.28) from constructors, instance initializer blocks, |
|
4062 |
// or instance variable initializer expressions of that |
|
4063 |
// type. It is a compile-time error for the constructors, |
|
4064 |
// instance initializer blocks, or instance variable |
|
4065 |
// initializer expressions of an enum constant e to refer |
|
4066 |
// to itself or to an enum constant of the same type that |
|
4067 |
// is declared to the right of e." |
|
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4068 |
if (isStaticEnumField(v)) { |
10 | 4069 |
ClassSymbol enclClass = env.info.scope.owner.enclClass(); |
4070 |
||
4071 |
if (enclClass == null || enclClass.owner == null) |
|
4072 |
return; |
|
4073 |
||
4074 |
// See if the enclosing class is the enum (or a |
|
4075 |
// subclass thereof) declaring v. If not, this |
|
4076 |
// reference is OK. |
|
4077 |
if (v.owner != enclClass && !types.isSubtype(enclClass.type, v.owner.type)) |
|
4078 |
return; |
|
4079 |
||
4080 |
// If the reference isn't from an initializer, then |
|
4081 |
// the reference is OK. |
|
4082 |
if (!Resolve.isInitializer(env)) |
|
4083 |
return; |
|
4084 |
||
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4085 |
log.error(tree.pos(), Errors.IllegalEnumStaticRef); |
10 | 4086 |
} |
4087 |
} |
|
4088 |
||
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4089 |
/** 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
|
4090 |
* Note: enum literals should not be regarded as such |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4091 |
*/ |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4092 |
private boolean isStaticEnumField(VarSymbol v) { |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4093 |
return Flags.isEnum(v.owner) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4094 |
Flags.isStatic(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4095 |
!Flags.isConstant(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
4096 |
v.name != names._class; |
10 | 4097 |
} |
4098 |
||
4099 |
/** |
|
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
4100 |
* Check that method arguments conform to its instantiation. |
10 | 4101 |
**/ |
4102 |
public Type checkMethod(Type site, |
|
19914 | 4103 |
final Symbol sym, |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
4104 |
ResultInfo resultInfo, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
4105 |
Env<AttrContext> env, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
4106 |
final List<JCExpression> argtrees, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12334
diff
changeset
|
4107 |
List<Type> argtypes, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
4108 |
List<Type> typeargtypes) { |
10 | 4109 |
// Test (5): if symbol is an instance method of a raw type, issue |
4110 |
// an unchecked warning if its argument types change under erasure. |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
4111 |
if ((sym.flags() & STATIC) == 0 && |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4112 |
(site.hasTag(CLASS) || site.hasTag(TYPEVAR))) { |
10 | 4113 |
Type s = types.asOuterSuper(site, sym.owner); |
4114 |
if (s != null && s.isRaw() && |
|
4115 |
!types.isSameTypes(sym.type.getParameterTypes(), |
|
4116 |
sym.erasure(types).getParameterTypes())) { |
|
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4117 |
chk.warnUnchecked(env.tree.pos(), Warnings.UncheckedCallMbrOfRawType(sym, s)); |
10 | 4118 |
} |
4119 |
} |
|
4120 |
||
14547 | 4121 |
if (env.info.defaultSuperCallSite != null) { |
4122 |
for (Type sup : types.interfaces(env.enclClass.type).prepend(types.supertype((env.enclClass.type)))) { |
|
4123 |
if (!sup.tsym.isSubClass(sym.enclClass(), types) || |
|
4124 |
types.isSameType(sup, env.info.defaultSuperCallSite)) continue; |
|
4125 |
List<MethodSymbol> icand_sup = |
|
4126 |
types.interfaceCandidates(sup, (MethodSymbol)sym); |
|
4127 |
if (icand_sup.nonEmpty() && |
|
4128 |
icand_sup.head != sym && |
|
4129 |
icand_sup.head.overrides(sym, icand_sup.head.enclClass(), types, true)) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4130 |
log.error(env.tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4131 |
Errors.IllegalDefaultSuperCall(env.info.defaultSuperCallSite, Fragments.OverriddenDefault(sym, sup))); |
14547 | 4132 |
break; |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4133 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4134 |
} |
14547 | 4135 |
env.info.defaultSuperCallSite = null; |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4136 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4137 |
|
16330
66e277848a69
8009299: Javac crashes when compiling method reference to static interface method
mcimadamore
parents:
16328
diff
changeset
|
4138 |
if (sym.isStatic() && site.isInterface() && env.tree.hasTag(APPLY)) { |
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4139 |
JCMethodInvocation app = (JCMethodInvocation)env.tree; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4140 |
if (app.meth.hasTag(SELECT) && |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4141 |
!TreeInfo.isStaticSelector(((JCFieldAccess)app.meth).selected, names)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4142 |
log.error(env.tree.pos(), Errors.IllegalStaticIntfMethCall(site)); |
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4143 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4144 |
} |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
4145 |
|
10 | 4146 |
// Compute the identifier's instantiated type. |
4147 |
// For methods, we need to compute the instance type by |
|
4148 |
// Resolve.instantiate from the symbol's type as well as |
|
4149 |
// any type arguments and value arguments. |
|
35349
4a13a361309a
8147493: regression when type-checking unchecked method calls
mcimadamore
parents:
33907
diff
changeset
|
4150 |
Warner noteWarner = new Warner(); |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4151 |
try { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
4152 |
Type owntype = rs.checkMethod( |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4153 |
env, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4154 |
site, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4155 |
sym, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4156 |
resultInfo, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4157 |
argtypes, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4158 |
typeargtypes, |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4159 |
noteWarner); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4160 |
|
18381
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4161 |
DeferredAttr.DeferredTypeMap checkDeferredMap = |
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4162 |
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
|
4163 |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29553
diff
changeset
|
4164 |
argtypes = argtypes.map(checkDeferredMap); |
18381
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4165 |
|
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4166 |
if (noteWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4167 |
chk.warnUnchecked(env.tree.pos(), Warnings.UncheckedMethInvocationApplied(kindName(sym), |
18381
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4168 |
sym.name, |
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4169 |
rs.methodArguments(sym.type.getParameterTypes()), |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29553
diff
changeset
|
4170 |
rs.methodArguments(argtypes.map(checkDeferredMap)), |
18381
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4171 |
kindName(sym.location()), |
48721
ef3557eb4306
8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents:
48449
diff
changeset
|
4172 |
sym.location())); |
43761
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4173 |
if (resultInfo.pt != Infer.anyPoly || |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4174 |
!owntype.hasTag(METHOD) || |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4175 |
!owntype.isPartial()) { |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4176 |
//if this is not a partially inferred method type, erase return type. Otherwise, |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4177 |
//erasure is carried out in PartiallyInferredMethodType.check(). |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4178 |
owntype = new MethodType(owntype.getParameterTypes(), |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4179 |
types.erasure(owntype.getReturnType()), |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4180 |
types.erasure(owntype.getThrownTypes()), |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4181 |
syms.methodClass); |
f50592785b30
8174249: Regression in generic method unchecked calls
mcimadamore
parents:
43582
diff
changeset
|
4182 |
} |
18381
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4183 |
} |
56a7f54f4166
8015432: javac crashes with stack overflow when method called recursively from nested generic call
mcimadamore
parents:
18379
diff
changeset
|
4184 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4185 |
PolyKind pkind = (sym.type.hasTag(FORALL) && |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4186 |
sym.type.getReturnType().containsAny(((ForAll)sym.type).tvars)) ? |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4187 |
PolyKind.POLY : PolyKind.STANDALONE; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4188 |
TreeInfo.setPolyKind(env.tree, pkind); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4189 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4190 |
return (resultInfo.pt == Infer.anyPoly) ? |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4191 |
owntype : |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4192 |
chk.checkMethod(owntype, sym, env, argtrees, argtypes, env.info.lastResolveVarargs(), |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32164
diff
changeset
|
4193 |
resultInfo.checkContext.inferenceContext()); |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4194 |
} catch (Infer.InferenceException ex) { |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4195 |
//invalid target type - propagate exception outwards or report error |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4196 |
//depending on the current check context |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4197 |
resultInfo.checkContext.report(env.tree.pos(), ex.getDiagnostic()); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4198 |
return types.createErrorType(site); |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4199 |
} catch (Resolve.InapplicableMethodException ex) { |
19914 | 4200 |
final JCDiagnostic diag = ex.getDiagnostic(); |
4201 |
Resolve.InapplicableSymbolError errSym = rs.new InapplicableSymbolError(null) { |
|
4202 |
@Override |
|
4203 |
protected Pair<Symbol, JCDiagnostic> errCandidate() { |
|
22163 | 4204 |
return new Pair<>(sym, diag); |
19914 | 4205 |
} |
4206 |
}; |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29553
diff
changeset
|
4207 |
List<Type> argtypes2 = argtypes.map( |
19914 | 4208 |
rs.new ResolveDeferredRecoveryMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); |
4209 |
JCDiagnostic errDiag = errSym.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, |
|
4210 |
env.tree, sym, site, sym.name, argtypes2, typeargtypes); |
|
4211 |
log.report(errDiag); |
|
4212 |
return types.createErrorType(site); |
|
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12916
diff
changeset
|
4213 |
} |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
4214 |
} |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
4215 |
|
10 | 4216 |
public void visitLiteral(JCLiteral tree) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4217 |
result = check(tree, litType(tree.typetag).constType(tree.value), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4218 |
KindSelector.VAL, resultInfo); |
10 | 4219 |
} |
4220 |
//where |
|
4221 |
/** Return the type of a literal with given type tag. |
|
4222 |
*/ |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4223 |
Type litType(TypeTag tag) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4224 |
return (tag == CLASS) ? syms.stringType : syms.typeOfTag[tag.ordinal()]; |
10 | 4225 |
} |
4226 |
||
4227 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4228 |
result = check(tree, syms.typeOfTag[tree.typetag.ordinal()], KindSelector.TYP, resultInfo); |
10 | 4229 |
} |
4230 |
||
4231 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
4232 |
Type etype = attribType(tree.elemtype, env); |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
4233 |
Type type = new ArrayType(etype, syms.arrayClass); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4234 |
result = check(tree, type, KindSelector.TYP, resultInfo); |
10 | 4235 |
} |
4236 |
||
4237 |
/** Visitor method for parameterized types. |
|
4238 |
* Bound checking is left until later, since types are attributed |
|
4239 |
* before supertype structure is completely known |
|
4240 |
*/ |
|
4241 |
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
|
4242 |
Type owntype = types.createErrorType(tree.type); |
10 | 4243 |
|
4244 |
// Attribute functor part of application and make sure it's a class. |
|
4245 |
Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env)); |
|
4246 |
||
4247 |
// Attribute type parameters |
|
4248 |
List<Type> actuals = attribTypes(tree.arguments, env); |
|
4249 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4250 |
if (clazztype.hasTag(CLASS)) { |
10 | 4251 |
List<Type> formals = clazztype.tsym.type.getTypeArguments(); |
10198
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
4252 |
if (actuals.isEmpty()) //diamond |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
4253 |
actuals = formals; |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
4254 |
|
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
4255 |
if (actuals.length() == formals.length()) { |
10 | 4256 |
List<Type> a = actuals; |
4257 |
List<Type> f = formals; |
|
4258 |
while (a.nonEmpty()) { |
|
4259 |
a.head = a.head.withTypeVar(f.head); |
|
4260 |
a = a.tail; |
|
4261 |
f = f.tail; |
|
4262 |
} |
|
4263 |
// Compute the proper generic outer |
|
4264 |
Type clazzOuter = clazztype.getEnclosingType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4265 |
if (clazzOuter.hasTag(CLASS)) { |
10 | 4266 |
Type site; |
3149 | 4267 |
JCExpression clazz = TreeInfo.typeIn(tree.clazz); |
10950 | 4268 |
if (clazz.hasTag(IDENT)) { |
10 | 4269 |
site = env.enclClass.sym.type; |
10950 | 4270 |
} else if (clazz.hasTag(SELECT)) { |
3149 | 4271 |
site = ((JCFieldAccess) clazz).selected.type; |
10 | 4272 |
} else throw new AssertionError(""+tree); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4273 |
if (clazzOuter.hasTag(CLASS) && site != clazzOuter) { |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4274 |
if (site.hasTag(CLASS)) |
10 | 4275 |
site = types.asOuterSuper(site, clazzOuter.tsym); |
4276 |
if (site == null) |
|
4277 |
site = types.erasure(clazzOuter); |
|
4278 |
clazzOuter = site; |
|
4279 |
} |
|
4280 |
} |
|
24396 | 4281 |
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym, |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
4282 |
clazztype.getMetadata()); |
10 | 4283 |
} else { |
4284 |
if (formals.length() != 0) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4285 |
log.error(tree.pos(), |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4286 |
Errors.WrongNumberTypeArgs(Integer.toString(formals.length()))); |
10 | 4287 |
} else { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4288 |
log.error(tree.pos(), Errors.TypeDoesntTakeParams(clazztype.tsym)); |
10 | 4289 |
} |
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
|
4290 |
owntype = types.createErrorType(tree.type); |
10 | 4291 |
} |
4292 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4293 |
result = check(tree, owntype, KindSelector.TYP, resultInfo); |
10 | 4294 |
} |
4295 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
4296 |
public void visitTypeUnion(JCTypeUnion tree) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
4297 |
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
|
4298 |
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
|
4299 |
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
|
4300 |
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
|
4301 |
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
|
4302 |
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
|
4303 |
syms.throwableType); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4304 |
if (!ctype.isErroneous()) { |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
4305 |
//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
|
4306 |
//unrelated w.r.t. subtyping |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4307 |
if (chk.intersects(ctype, multicatchTypes.toList())) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4308 |
for (Type t : multicatchTypes) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4309 |
boolean sub = types.isSubtype(ctype, t); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4310 |
boolean sup = types.isSubtype(t, ctype); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4311 |
if (sub || sup) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4312 |
//assume 'a' <: 'b' |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4313 |
Type a = sub ? ctype : t; |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4314 |
Type b = sub ? t : ctype; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4315 |
log.error(typeTree.pos(), Errors.MulticatchTypesMustBeDisjoint(a, b)); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4316 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4317 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4318 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4319 |
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
|
4320 |
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
|
4321 |
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
|
4322 |
} else { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
4323 |
if (all_multicatchTypes == null) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19942
diff
changeset
|
4324 |
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
|
4325 |
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
|
4326 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
4327 |
all_multicatchTypes.append(ctype); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
4328 |
} |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
4329 |
} |
30405
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
4330 |
Type t = check(tree, types.lub(multicatchTypes.toList()), |
3da6595b205f
8076279: Refactor Attr.check* methods to receive/handle a CheckMode enumeration
sadayapalam
parents:
30064
diff
changeset
|
4331 |
KindSelector.TYP, resultInfo.dup(CheckMode.NO_TREE_UPDATE)); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4332 |
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
|
4333 |
List<Type> alternatives = |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
4334 |
((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
|
4335 |
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
|
4336 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
4337 |
tree.type = result = t; |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
4338 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
4339 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4340 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4341 |
attribTypes(tree.bounds, env); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4342 |
tree.type = result = checkIntersection(tree, tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4343 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4344 |
|
15385 | 4345 |
public void visitTypeParameter(JCTypeParameter tree) { |
4346 |
TypeVar typeVar = (TypeVar) tree.type; |
|
4347 |
||
4348 |
if (tree.annotations != null && tree.annotations.nonEmpty()) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4349 |
annotate.annotateTypeParameterSecondStage(tree, tree.annotations); |
15385 | 4350 |
} |
4351 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4352 |
if (!typeVar.bound.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4353 |
//fixup type-parameter bound computed in 'attribTypeVariables' |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4354 |
typeVar.bound = checkIntersection(tree, tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4355 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4356 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4357 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4358 |
Type checkIntersection(JCTree tree, List<JCExpression> bounds) { |
22163 | 4359 |
Set<Type> boundSet = new HashSet<>(); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4360 |
if (bounds.nonEmpty()) { |
10 | 4361 |
// 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
|
4362 |
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
|
4363 |
boundSet.add(types.erasure(bounds.head.type)); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4364 |
if (bounds.head.type.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4365 |
return bounds.head.type; |
1532
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
4366 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4367 |
else if (bounds.head.type.hasTag(TYPEVAR)) { |
10 | 4368 |
// 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
|
4369 |
if (bounds.tail.nonEmpty()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4370 |
log.error(bounds.tail.head.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4371 |
Errors.TypeVarMayNotBeFollowedByOtherBounds); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4372 |
return bounds.head.type; |
10 | 4373 |
} |
4374 |
} else { |
|
4375 |
// if first bound was a class or interface, accept only interfaces |
|
4376 |
// as further bounds. |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4377 |
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
|
4378 |
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
|
4379 |
if (bound.type.isErroneous()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4380 |
bounds = List.of(bound); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4381 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4382 |
else if (bound.type.hasTag(CLASS)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4383 |
chk.checkNotRepeated(bound.pos(), types.erasure(bound.type), boundSet); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4384 |
} |
10 | 4385 |
} |
4386 |
} |
|
4387 |
} |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4388 |
|
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4389 |
if (bounds.length() == 0) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4390 |
return syms.objectType; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4391 |
} else if (bounds.length() == 1) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4392 |
return bounds.head.type; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4393 |
} else { |
29147
4cba0458106b
8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents:
29051
diff
changeset
|
4394 |
Type owntype = types.makeIntersectionType(TreeInfo.types(bounds)); |
10 | 4395 |
// ... the variable's bound is a class type flagged COMPOUND |
4396 |
// (see comment for TypeVar.bound). |
|
4397 |
// In this case, generate a class tree that represents the |
|
4398 |
// bound class, ... |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8622
diff
changeset
|
4399 |
JCExpression extending; |
10 | 4400 |
List<JCExpression> implementing; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4401 |
if (!bounds.head.type.isInterface()) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4402 |
extending = bounds.head; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4403 |
implementing = bounds.tail; |
10 | 4404 |
} else { |
4405 |
extending = null; |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4406 |
implementing = bounds; |
10 | 4407 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4408 |
JCClassDecl cd = make.at(tree).ClassDef( |
10 | 4409 |
make.Modifiers(PUBLIC | ABSTRACT), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
4410 |
names.empty, List.nil(), |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
4411 |
extending, implementing, List.nil()); |
10 | 4412 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4413 |
ClassSymbol c = (ClassSymbol)owntype.tsym; |
8032 | 4414 |
Assert.check((c.flags() & COMPOUND) != 0); |
10 | 4415 |
cd.sym = c; |
4416 |
c.sourcefile = env.toplevel.sourcefile; |
|
4417 |
||
4418 |
// ... and attribute the bound class |
|
4419 |
c.flags_field |= UNATTRIBUTED; |
|
4420 |
Env<AttrContext> cenv = enter.classEnv(cd, env); |
|
25007 | 4421 |
typeEnvs.put(c, cenv); |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4422 |
attribClass(c); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4423 |
return owntype; |
10 | 4424 |
} |
4425 |
} |
|
4426 |
||
4427 |
public void visitWildcard(JCWildcard tree) { |
|
4428 |
//- System.err.println("visitWildcard("+tree+");");//DEBUG |
|
4429 |
Type type = (tree.kind.kind == BoundKind.UNBOUND) |
|
4430 |
? syms.objectType |
|
4431 |
: attribType(tree.inner, env); |
|
4432 |
result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type), |
|
4433 |
tree.kind.kind, |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26780
diff
changeset
|
4434 |
syms.boundClass), |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4435 |
KindSelector.TYP, resultInfo); |
10 | 4436 |
} |
4437 |
||
4438 |
public void visitAnnotation(JCAnnotation tree) { |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4439 |
Assert.error("should be handled in annotate"); |
10 | 4440 |
} |
4441 |
||
15385 | 4442 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4443 |
attribAnnotationTypes(tree.annotations, env); |
31560 | 4444 |
Type underlyingType = attribType(tree.underlyingType, env); |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4445 |
Type annotatedType = underlyingType.annotatedType(Annotations.TO_BE_SET); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4446 |
|
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4447 |
if (!env.info.isNewClass) |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4448 |
annotate.annotateTypeSecondStage(tree, tree.annotations, annotatedType); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4449 |
result = tree.type = annotatedType; |
15385 | 4450 |
} |
4451 |
||
10 | 4452 |
public void visitErroneous(JCErroneous tree) { |
4453 |
if (tree.errs != null) |
|
4454 |
for (JCTree err : tree.errs) |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
4455 |
attribTree(err, env, new ResultInfo(KindSelector.ERR, pt())); |
10 | 4456 |
result = tree.type = syms.errType; |
4457 |
} |
|
4458 |
||
4459 |
/** Default visitor method for all other trees. |
|
4460 |
*/ |
|
4461 |
public void visitTree(JCTree tree) { |
|
4462 |
throw new AssertionError(); |
|
4463 |
} |
|
4464 |
||
8845 | 4465 |
/** |
36526 | 4466 |
* Attribute an env for either a top level tree or class or module declaration. |
8845 | 4467 |
*/ |
4468 |
public void attrib(Env<AttrContext> env) { |
|
36526 | 4469 |
switch (env.tree.getTag()) { |
4470 |
case MODULEDEF: |
|
4471 |
attribModule(env.tree.pos(), ((JCModuleDecl)env.tree).sym); |
|
4472 |
break; |
|
4473 |
case TOPLEVEL: |
|
4474 |
attribTopLevel(env); |
|
4475 |
break; |
|
40313
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4476 |
case PACKAGEDEF: |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4477 |
attribPackage(env.tree.pos(), ((JCPackageDecl) env.tree).packge); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4478 |
break; |
36526 | 4479 |
default: |
4480 |
attribClass(env.tree.pos(), env.enclClass.sym); |
|
4481 |
} |
|
8845 | 4482 |
} |
4483 |
||
4484 |
/** |
|
4485 |
* Attribute a top level tree. These trees are encountered when the |
|
4486 |
* package declaration has annotations. |
|
4487 |
*/ |
|
4488 |
public void attribTopLevel(Env<AttrContext> env) { |
|
4489 |
JCCompilationUnit toplevel = env.toplevel; |
|
4490 |
try { |
|
4491 |
annotate.flush(); |
|
4492 |
} catch (CompletionFailure ex) { |
|
4493 |
chk.completionError(toplevel.pos(), ex); |
|
4494 |
} |
|
4495 |
} |
|
4496 |
||
40313
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4497 |
public void attribPackage(DiagnosticPosition pos, PackageSymbol p) { |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4498 |
try { |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4499 |
annotate.flush(); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4500 |
attribPackage(p); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4501 |
} catch (CompletionFailure ex) { |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4502 |
chk.completionError(pos, ex); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4503 |
} |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4504 |
} |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4505 |
|
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4506 |
void attribPackage(PackageSymbol p) { |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4507 |
Env<AttrContext> env = typeEnvs.get(p); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4508 |
chk.checkDeprecatedAnnotation(((JCPackageDecl) env.tree).pid.pos(), p); |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4509 |
} |
a85f92c9a8ab
8068626: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
sadayapalam
parents:
39920
diff
changeset
|
4510 |
|
36526 | 4511 |
public void attribModule(DiagnosticPosition pos, ModuleSymbol m) { |
4512 |
try { |
|
4513 |
annotate.flush(); |
|
4514 |
attribModule(m); |
|
4515 |
} catch (CompletionFailure ex) { |
|
4516 |
chk.completionError(pos, ex); |
|
4517 |
} |
|
4518 |
} |
|
4519 |
||
4520 |
void attribModule(ModuleSymbol m) { |
|
4521 |
// Get environment current at the point of module definition. |
|
4522 |
Env<AttrContext> env = enter.typeEnvs.get(m); |
|
4523 |
attribStat(env.tree, env); |
|
4524 |
} |
|
4525 |
||
10 | 4526 |
/** Main method: attribute class definition associated with given class symbol. |
4527 |
* reporting completion failures at the given position. |
|
4528 |
* @param pos The source position at which completion errors are to be |
|
4529 |
* reported. |
|
4530 |
* @param c The class symbol whose definition will be attributed. |
|
4531 |
*/ |
|
4532 |
public void attribClass(DiagnosticPosition pos, ClassSymbol c) { |
|
4533 |
try { |
|
4534 |
annotate.flush(); |
|
4535 |
attribClass(c); |
|
4536 |
} catch (CompletionFailure ex) { |
|
4537 |
chk.completionError(pos, ex); |
|
4538 |
} |
|
4539 |
} |
|
4540 |
||
4541 |
/** Attribute class definition associated with given class symbol. |
|
4542 |
* @param c The class symbol whose definition will be attributed. |
|
4543 |
*/ |
|
4544 |
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
|
4545 |
if (c.type.hasTag(ERROR)) return; |
10 | 4546 |
|
4547 |
// Check for cycles in the inheritance graph, which can arise from |
|
4548 |
// ill-formed class files. |
|
4549 |
chk.checkNonCyclic(null, c.type); |
|
4550 |
||
4551 |
Type st = types.supertype(c.type); |
|
4552 |
if ((c.flags_field & Flags.COMPOUND) == 0) { |
|
4553 |
// First, attribute superclass. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4554 |
if (st.hasTag(CLASS)) |
10 | 4555 |
attribClass((ClassSymbol)st.tsym); |
4556 |
||
4557 |
// 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
|
4558 |
if (c.owner.kind == TYP && c.owner.type.hasTag(CLASS)) |
10 | 4559 |
attribClass((ClassSymbol)c.owner); |
4560 |
} |
|
4561 |
||
4562 |
// The previous operations might have attributed the current class |
|
4563 |
// if there was a cycle. So we test first whether the class is still |
|
4564 |
// UNATTRIBUTED. |
|
4565 |
if ((c.flags_field & UNATTRIBUTED) != 0) { |
|
4566 |
c.flags_field &= ~UNATTRIBUTED; |
|
4567 |
||
4568 |
// Get environment current at the point of class definition. |
|
25007 | 4569 |
Env<AttrContext> env = typeEnvs.get(c); |
4570 |
||
4571 |
// The info.lint field in the envs stored in typeEnvs is deliberately uninitialized, |
|
10 | 4572 |
// because the annotations were not available at the time the env was created. Therefore, |
4573 |
// we look up the environment chain for the first enclosing environment for which the |
|
4574 |
// lint value is set. Typically, this is the parent env, but might be further if there |
|
4575 |
// are any envs created as a result of TypeParameter nodes. |
|
4576 |
Env<AttrContext> lintEnv = env; |
|
4577 |
while (lintEnv.info.lint == null) |
|
4578 |
lintEnv = lintEnv.next; |
|
4579 |
||
4580 |
// 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
|
4581 |
env.info.lint = lintEnv.info.lint.augment(c); |
10 | 4582 |
|
4583 |
Lint prevLint = chk.setLint(env.info.lint); |
|
4584 |
JavaFileObject prev = log.useSource(c.sourcefile); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
4585 |
ResultInfo prevReturnRes = env.info.returnResult; |
10 | 4586 |
|
4587 |
try { |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19933
diff
changeset
|
4588 |
deferredLintHandler.flush(env.tree); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
4589 |
env.info.returnResult = null; |
10 | 4590 |
// java.lang.Enum may not be subclassed by a non-enum |
4591 |
if (st.tsym == syms.enumSym && |
|
4592 |
((c.flags_field & (Flags.ENUM|Flags.COMPOUND)) == 0)) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4593 |
log.error(env.tree.pos(), Errors.EnumNoSubclassing); |
10 | 4594 |
|
4595 |
// Enums may not be extended by source-level classes |
|
4596 |
if (st.tsym != null && |
|
4597 |
((st.tsym.flags_field & Flags.ENUM) != 0) && |
|
16558
07c08ad4a700
8010179: Remove transitional target values from javac
darcy
parents:
16557
diff
changeset
|
4598 |
((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0)) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4599 |
log.error(env.tree.pos(), Errors.EnumTypesNotExtensible); |
10 | 4600 |
} |
24219 | 4601 |
|
4602 |
if (isSerializable(c.type)) { |
|
4603 |
env.info.isSerializable = true; |
|
4604 |
} |
|
4605 |
||
10 | 4606 |
attribClassBody(env, c); |
4607 |
||
4608 |
chk.checkDeprecatedAnnotation(env.tree.pos(), c); |
|
16333 | 4609 |
chk.checkClassOverrideEqualsAndHashIfNeeded(env.tree.pos(), c); |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21009
diff
changeset
|
4610 |
chk.checkFunctionalInterface((JCClassDecl) env.tree, c); |
41444
b61c805c6173
8153362: Add javac -Xlint warning to list exposed types which are not accessible
jlahoda
parents:
41156
diff
changeset
|
4611 |
chk.checkLeaksNotAccessible(env, (JCClassDecl) env.tree); |
10 | 4612 |
} finally { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
4613 |
env.info.returnResult = prevReturnRes; |
10 | 4614 |
log.useSource(prev); |
4615 |
chk.setLint(prevLint); |
|
4616 |
} |
|
4617 |
||
4618 |
} |
|
4619 |
} |
|
4620 |
||
4621 |
public void visitImport(JCImport tree) { |
|
4622 |
// nothing to do |
|
4623 |
} |
|
4624 |
||
36526 | 4625 |
public void visitModuleDef(JCModuleDecl tree) { |
4626 |
tree.sym.completeUsesProvides(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4627 |
ModuleSymbol msym = tree.sym; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4628 |
Lint lint = env.outer.info.lint = env.outer.info.lint.augment(msym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4629 |
Lint prevLint = chk.setLint(lint); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42416
diff
changeset
|
4630 |
chk.checkModuleName(tree); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4631 |
chk.checkDeprecatedAnnotation(tree, msym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4632 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4633 |
try { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4634 |
deferredLintHandler.flush(tree.pos()); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4635 |
} finally { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4636 |
chk.setLint(prevLint); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
4637 |
} |
36526 | 4638 |
} |
4639 |
||
10 | 4640 |
/** Finish the attribution of a class. */ |
4641 |
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) { |
|
4642 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
8032 | 4643 |
Assert.check(c == tree.sym); |
10 | 4644 |
|
4645 |
// Validate type parameters, supertype and interfaces. |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14724
diff
changeset
|
4646 |
attribStats(tree.typarams, env); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4647 |
if (!c.isAnonymous()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4648 |
//already checked if anonymous |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4649 |
chk.validate(tree.typarams, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4650 |
chk.validate(tree.extending, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4651 |
chk.validate(tree.implementing, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
4652 |
} |
10 | 4653 |
|
28459
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28456
diff
changeset
|
4654 |
c.markAbstractIfNeeded(types); |
48a68a485760
8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents:
28456
diff
changeset
|
4655 |
|
10 | 4656 |
// If this is a non-abstract class, check that it has no abstract |
4657 |
// methods or unimplemented methods of an implemented interface. |
|
4658 |
if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) { |
|
36153 | 4659 |
chk.checkAllDefined(tree.pos(), c); |
10 | 4660 |
} |
4661 |
||
4662 |
if ((c.flags() & ANNOTATION) != 0) { |
|
4663 |
if (tree.implementing.nonEmpty()) |
|
4664 |
log.error(tree.implementing.head.pos(), |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4665 |
Errors.CantExtendIntfAnnotation); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4666 |
if (tree.typarams.nonEmpty()) { |
10 | 4667 |
log.error(tree.typarams.head.pos(), |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4668 |
Errors.IntfAnnotationCantHaveTypeParams(c)); |
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4669 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4670 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4671 |
// If this annotation type has a @Repeatable, validate |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4672 |
Attribute.Compound repeatable = c.getAnnotationTypeMetadata().getRepeatable(); |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
4673 |
// If this annotation type has a @Repeatable, validate |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14953
diff
changeset
|
4674 |
if (repeatable != null) { |
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14953
diff
changeset
|
4675 |
// get diagnostic position for error reporting |
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14953
diff
changeset
|
4676 |
DiagnosticPosition cbPos = getDiagnosticPosition(tree, repeatable.type); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4677 |
Assert.checkNonNull(cbPos); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4678 |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14953
diff
changeset
|
4679 |
chk.validateRepeatable(c, repeatable, cbPos); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4680 |
} |
10 | 4681 |
} else { |
4682 |
// Check that all extended classes and interfaces |
|
4683 |
// are compatible (i.e. no two define methods with same arguments |
|
4684 |
// yet different return types). (JLS 8.4.6.3) |
|
4685 |
chk.checkCompatibleSupertypes(tree.pos(), c.type); |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4686 |
if (allowDefaultMethods) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4687 |
chk.checkDefaultMethodClashes(tree.pos(), c.type); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
4688 |
} |
10 | 4689 |
} |
4690 |
||
4691 |
// Check that class does not import the same parameterized interface |
|
4692 |
// with two different argument lists. |
|
4693 |
chk.checkClassBounds(tree.pos(), c.type); |
|
4694 |
||
4695 |
tree.type = c.type; |
|
4696 |
||
8032 | 4697 |
for (List<JCTypeParameter> l = tree.typarams; |
4698 |
l.nonEmpty(); l = l.tail) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4699 |
Assert.checkNonNull(env.info.scope.findFirst(l.head.name)); |
10 | 4700 |
} |
4701 |
||
4702 |
// Check that a generic class doesn't extend Throwable |
|
4703 |
if (!c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType)) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4704 |
log.error(tree.extending.pos(), Errors.GenericThrowable); |
10 | 4705 |
|
4706 |
// Check that all methods which implement some |
|
4707 |
// method conform to the method they implement. |
|
4708 |
chk.checkImplementations(tree); |
|
4709 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
4710 |
//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
|
4711 |
checkAutoCloseable(tree.pos(), env, c.type); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
4712 |
|
10 | 4713 |
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
4714 |
// Attribute declaration |
|
4715 |
attribStat(l.head, env); |
|
4716 |
// Check that declarations in inner classes are not static (JLS 8.1.2) |
|
4717 |
// Make an exception for static constants. |
|
4718 |
if (c.owner.kind != PCK && |
|
4719 |
((c.flags() & STATIC) == 0 || c.name == names.empty) && |
|
4720 |
(TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) { |
|
4721 |
Symbol sym = null; |
|
10950 | 4722 |
if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym; |
10 | 4723 |
if (sym == null || |
4724 |
sym.kind != VAR || |
|
4725 |
((VarSymbol) sym).getConstValue() == null) |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4726 |
log.error(l.head.pos(), Errors.IclsCantHaveStaticDecl(c)); |
10 | 4727 |
} |
4728 |
} |
|
4729 |
||
4730 |
// Check for cycles among non-initial constructors. |
|
4731 |
chk.checkCyclicConstructors(tree); |
|
4732 |
||
4733 |
// Check for cycles among annotation elements. |
|
4734 |
chk.checkNonCyclicElements(tree); |
|
4735 |
||
4736 |
// Check for proper use of serialVersionUID |
|
37634
a5f740ef93f2
7152104: javac should not warn about missing serialVersionUID for anonymous inner classes
alundblad
parents:
36713
diff
changeset
|
4737 |
if (env.info.lint.isEnabled(LintCategory.SERIAL) |
a5f740ef93f2
7152104: javac should not warn about missing serialVersionUID for anonymous inner classes
alundblad
parents:
36713
diff
changeset
|
4738 |
&& isSerializable(c.type) |
48449
e2b8009bf42c
8191637: Interface with defaults invalid compiler warning for Serializable
jjg
parents:
48246
diff
changeset
|
4739 |
&& (c.flags() & (Flags.ENUM | Flags.INTERFACE)) == 0 |
e2b8009bf42c
8191637: Interface with defaults invalid compiler warning for Serializable
jjg
parents:
48246
diff
changeset
|
4740 |
&& !c.isAnonymous()) { |
10 | 4741 |
checkSerialVersionUID(tree, c); |
4742 |
} |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4743 |
if (allowTypeAnnos) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4744 |
// Correctly organize the postions of the type annotations |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4745 |
typeAnnotations.organizeTypeAnnotationsBodies(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4746 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4747 |
// Check type annotations applicability rules |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4748 |
validateTypeAnnotations(tree, false); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4749 |
} |
10 | 4750 |
} |
4751 |
// where |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4752 |
/** 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
|
4753 |
private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4754 |
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
|
4755 |
if (types.isSameType(al.head.annotationType.type, t)) |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4756 |
return al.head.pos(); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4757 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4758 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4759 |
return null; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4760 |
} |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13439
diff
changeset
|
4761 |
|
24219 | 4762 |
/** check if a type is a subtype of Serializable, if that is available. */ |
4763 |
boolean isSerializable(Type t) { |
|
10 | 4764 |
try { |
4765 |
syms.serializableType.complete(); |
|
4766 |
} |
|
4767 |
catch (CompletionFailure e) { |
|
4768 |
return false; |
|
4769 |
} |
|
24219 | 4770 |
return types.isSubtype(t, syms.serializableType); |
10 | 4771 |
} |
4772 |
||
4773 |
/** Check that an appropriate serialVersionUID member is defined. */ |
|
4774 |
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { |
|
4775 |
||
4776 |
// check for presence of serialVersionUID |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4777 |
VarSymbol svuid = null; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4778 |
for (Symbol sym : c.members().getSymbolsByName(names.serialVersionUID)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4779 |
if (sym.kind == VAR) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4780 |
svuid = (VarSymbol)sym; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4781 |
break; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4782 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4783 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4784 |
|
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25279
diff
changeset
|
4785 |
if (svuid == null) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
4786 |
log.warning(LintCategory.SERIAL, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4787 |
tree.pos(), Warnings.MissingSVUID(c)); |
10 | 4788 |
return; |
4789 |
} |
|
4790 |
||
4791 |
// check that it is static final |
|
4792 |
if ((svuid.flags() & (STATIC | FINAL)) != |
|
4793 |
(STATIC | FINAL)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
4794 |
log.warning(LintCategory.SERIAL, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4795 |
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ImproperSVUID(c)); |
10 | 4796 |
|
4797 |
// check that it is long |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
4798 |
else if (!svuid.type.hasTag(LONG)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
4799 |
log.warning(LintCategory.SERIAL, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4800 |
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.LongSVUID(c)); |
10 | 4801 |
|
4802 |
// check constant |
|
4803 |
else if (svuid.getConstValue() == null) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
4804 |
log.warning(LintCategory.SERIAL, |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4805 |
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ConstantSVUID(c)); |
10 | 4806 |
} |
4807 |
||
4808 |
private Type capture(Type type) { |
|
18911 | 4809 |
return types.capture(type); |
10 | 4810 |
} |
3149 | 4811 |
|
47318
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4812 |
private void setSyntheticVariableType(JCVariableDecl tree, Type type) { |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4813 |
if (type.isErroneous()) { |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4814 |
tree.vartype = make.at(Position.NOPOS).Erroneous(); |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4815 |
} else { |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4816 |
tree.vartype = make.at(Position.NOPOS).Type(type); |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4817 |
} |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4818 |
} |
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
4819 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4820 |
public void validateTypeAnnotations(JCTree tree, boolean sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4821 |
tree.accept(new TypeAnnotationsValidator(sigOnly)); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4822 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4823 |
//where |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4824 |
private final class TypeAnnotationsValidator extends TreeScanner { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4825 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4826 |
private final boolean sigOnly; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4827 |
public TypeAnnotationsValidator(boolean sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4828 |
this.sigOnly = sigOnly; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4829 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4830 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4831 |
public void visitAnnotation(JCAnnotation tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4832 |
chk.validateTypeAnnotation(tree, false); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4833 |
super.visitAnnotation(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4834 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4835 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4836 |
if (!tree.underlyingType.type.isErroneous()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4837 |
super.visitAnnotatedType(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4838 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4839 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4840 |
public void visitTypeParameter(JCTypeParameter tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4841 |
chk.validateTypeAnnotations(tree.annotations, true); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4842 |
scan(tree.bounds); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4843 |
// Don't call super. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4844 |
// This is needed because above we call validateTypeAnnotation with |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4845 |
// false, which would forbid annotations on type parameters. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4846 |
// super.visitTypeParameter(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4847 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4848 |
public void visitMethodDef(JCMethodDecl tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4849 |
if (tree.recvparam != null && |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4850 |
!tree.recvparam.vartype.type.isErroneous()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4851 |
checkForDeclarationAnnotations(tree.recvparam.mods.annotations, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4852 |
tree.recvparam.vartype.type.tsym); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4853 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4854 |
if (tree.restype != null && tree.restype.type != null) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4855 |
validateAnnotatedType(tree.restype, tree.restype.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4856 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4857 |
if (sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4858 |
scan(tree.mods); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4859 |
scan(tree.restype); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4860 |
scan(tree.typarams); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4861 |
scan(tree.recvparam); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4862 |
scan(tree.params); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4863 |
scan(tree.thrown); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4864 |
} else { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4865 |
scan(tree.defaultValue); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4866 |
scan(tree.body); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4867 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4868 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4869 |
public void visitVarDef(final JCVariableDecl tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4870 |
//System.err.println("validateTypeAnnotations.visitVarDef " + tree); |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
4871 |
if (tree.sym != null && tree.sym.type != null && !tree.isImplicitlyTyped()) |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4872 |
validateAnnotatedType(tree.vartype, tree.sym.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4873 |
scan(tree.mods); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4874 |
scan(tree.vartype); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4875 |
if (!sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4876 |
scan(tree.init); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4877 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4878 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4879 |
public void visitTypeCast(JCTypeCast tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4880 |
if (tree.clazz != null && tree.clazz.type != null) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4881 |
validateAnnotatedType(tree.clazz, tree.clazz.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4882 |
super.visitTypeCast(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4883 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4884 |
public void visitTypeTest(JCInstanceOf tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4885 |
if (tree.clazz != null && tree.clazz.type != null) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4886 |
validateAnnotatedType(tree.clazz, tree.clazz.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4887 |
super.visitTypeTest(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4888 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4889 |
public void visitNewClass(JCNewClass tree) { |
27851
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4890 |
if (tree.clazz != null && tree.clazz.type != null) { |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4891 |
if (tree.clazz.hasTag(ANNOTATED_TYPE)) { |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4892 |
checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4893 |
tree.clazz.type.tsym); |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4894 |
} |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4895 |
if (tree.def != null) { |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4896 |
checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4897 |
} |
5f28577d20f6
8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
jfranck
parents:
27845
diff
changeset
|
4898 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4899 |
validateAnnotatedType(tree.clazz, tree.clazz.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4900 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4901 |
super.visitNewClass(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4902 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4903 |
public void visitNewArray(JCNewArray tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4904 |
if (tree.elemtype != null && tree.elemtype.type != null) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4905 |
if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4906 |
checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4907 |
tree.elemtype.type.tsym); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4908 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4909 |
validateAnnotatedType(tree.elemtype, tree.elemtype.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4910 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4911 |
super.visitNewArray(tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4912 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4913 |
public void visitClassDef(JCClassDecl tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4914 |
//System.err.println("validateTypeAnnotations.visitClassDef " + tree); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4915 |
if (sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4916 |
scan(tree.mods); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4917 |
scan(tree.typarams); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4918 |
scan(tree.extending); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4919 |
scan(tree.implementing); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4920 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4921 |
for (JCTree member : tree.defs) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4922 |
if (member.hasTag(Tag.CLASSDEF)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4923 |
continue; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4924 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4925 |
scan(member); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4926 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4927 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4928 |
public void visitBlock(JCBlock tree) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4929 |
if (!sigOnly) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4930 |
scan(tree.stats); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4931 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4932 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4933 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4934 |
/* I would want to model this after |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4935 |
* com.sun.tools.javac.comp.Check.Validator.visitSelectInternal(JCFieldAccess) |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4936 |
* and override visitSelect and visitTypeApply. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4937 |
* However, we only set the annotated type in the top-level type |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4938 |
* of the symbol. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4939 |
* Therefore, we need to override each individual location where a type |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4940 |
* can occur. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4941 |
*/ |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4942 |
private void validateAnnotatedType(final JCTree errtree, final Type type) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4943 |
//System.err.println("Attr.validateAnnotatedType: " + errtree + " type: " + type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4944 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4945 |
if (type.isPrimitiveOrVoid()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4946 |
return; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4947 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4948 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4949 |
JCTree enclTr = errtree; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4950 |
Type enclTy = type; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4951 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4952 |
boolean repeat = true; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4953 |
while (repeat) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4954 |
if (enclTr.hasTag(TYPEAPPLY)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4955 |
List<Type> tyargs = enclTy.getTypeArguments(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4956 |
List<JCExpression> trargs = ((JCTypeApply)enclTr).getTypeArguments(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4957 |
if (trargs.length() > 0) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4958 |
// Nothing to do for diamonds |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4959 |
if (tyargs.length() == trargs.length()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4960 |
for (int i = 0; i < tyargs.length(); ++i) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4961 |
validateAnnotatedType(trargs.get(i), tyargs.get(i)); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4962 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4963 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4964 |
// If the lengths don't match, it's either a diamond |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4965 |
// or some nested type that redundantly provides |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4966 |
// type arguments in the tree. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4967 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4968 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4969 |
// Look at the clazz part of a generic type |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4970 |
enclTr = ((JCTree.JCTypeApply)enclTr).clazz; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4971 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4972 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4973 |
if (enclTr.hasTag(SELECT)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4974 |
enclTr = ((JCTree.JCFieldAccess)enclTr).getExpression(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4975 |
if (enclTy != null && |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4976 |
!enclTy.hasTag(NONE)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4977 |
enclTy = enclTy.getEnclosingType(); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4978 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4979 |
} else if (enclTr.hasTag(ANNOTATED_TYPE)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4980 |
JCAnnotatedType at = (JCTree.JCAnnotatedType) enclTr; |
31560 | 4981 |
if (enclTy == null || enclTy.hasTag(NONE)) { |
4982 |
if (at.getAnnotations().size() == 1) { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4983 |
log.error(at.underlyingType.pos(), Errors.CantTypeAnnotateScoping1(at.getAnnotations().head.attribute)); |
31560 | 4984 |
} else { |
4985 |
ListBuffer<Attribute.Compound> comps = new ListBuffer<>(); |
|
4986 |
for (JCAnnotation an : at.getAnnotations()) { |
|
4987 |
comps.add(an.attribute); |
|
4988 |
} |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44571
diff
changeset
|
4989 |
log.error(at.underlyingType.pos(), Errors.CantTypeAnnotateScoping(comps.toList())); |
31560 | 4990 |
} |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4991 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4992 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4993 |
enclTr = at.underlyingType; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4994 |
// enclTy doesn't need to be changed |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4995 |
} else if (enclTr.hasTag(IDENT)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4996 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4997 |
} else if (enclTr.hasTag(JCTree.Tag.WILDCARD)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
4998 |
JCWildcard wc = (JCWildcard) enclTr; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
4999 |
if (wc.getKind() == JCTree.Kind.EXTENDS_WILDCARD || |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
5000 |
wc.getKind() == JCTree.Kind.SUPER_WILDCARD) { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
5001 |
validateAnnotatedType(wc.getBound(), wc.getBound().type); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5002 |
} else { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5003 |
// Nothing to do for UNBOUND |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5004 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5005 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5006 |
} else if (enclTr.hasTag(TYPEARRAY)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5007 |
JCArrayTypeTree art = (JCArrayTypeTree) enclTr; |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47248
diff
changeset
|
5008 |
validateAnnotatedType(art.getType(), art.elemtype.type); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5009 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5010 |
} else if (enclTr.hasTag(TYPEUNION)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5011 |
JCTypeUnion ut = (JCTypeUnion) enclTr; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5012 |
for (JCTree t : ut.getTypeAlternatives()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5013 |
validateAnnotatedType(t, t.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5014 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5015 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5016 |
} else if (enclTr.hasTag(TYPEINTERSECTION)) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5017 |
JCTypeIntersection it = (JCTypeIntersection) enclTr; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5018 |
for (JCTree t : it.getBounds()) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5019 |
validateAnnotatedType(t, t.type); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5020 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5021 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5022 |
} else if (enclTr.getKind() == JCTree.Kind.PRIMITIVE_TYPE || |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5023 |
enclTr.getKind() == JCTree.Kind.ERRONEOUS) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5024 |
repeat = false; |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5025 |
} else { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5026 |
Assert.error("Unexpected tree: " + enclTr + " with kind: " + enclTr.getKind() + |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5027 |
" within: "+ errtree + " with kind: " + errtree.getKind()); |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5028 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5029 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5030 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5031 |
|
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5032 |
private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5033 |
Symbol sym) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5034 |
// Ensure that no declaration annotations are present. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5035 |
// Note that a tree type might be an AnnotatedType with |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5036 |
// empty annotations, if only declaration annotations were given. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5037 |
// This method will raise an error for such a type. |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5038 |
for (JCAnnotation ai : annotations) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5039 |
if (!ai.type.isErroneous() && |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
5040 |
typeAnnotations.annotationTargetType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) { |
29959
61bfc66866da
8073534: Confusing / incorrect error message regarding annotations on non-declarations
alundblad
parents:
29842
diff
changeset
|
5041 |
log.error(ai.pos(), Errors.AnnotationTypeNotApplicableToType(ai.type)); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5042 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5043 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5044 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5045 |
} |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
5046 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5047 |
// <editor-fold desc="post-attribution visitor"> |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5048 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5049 |
/** |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5050 |
* 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
|
5051 |
* 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
|
5052 |
* 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
|
5053 |
* 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
|
5054 |
* prevents NPE to be progagated during subsequent compilation steps. |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5055 |
*/ |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
5056 |
public void postAttr(JCTree tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
5057 |
new PostAttrAnalyzer().scan(tree); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5058 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5059 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5060 |
class PostAttrAnalyzer extends TreeScanner { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5061 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5062 |
private void initTypeIfNeeded(JCTree that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5063 |
if (that.type == null) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5064 |
if (that.hasTag(METHODDEF)) { |
24609
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5065 |
that.type = dummyMethodType((JCMethodDecl)that); |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5066 |
} else { |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5067 |
that.type = syms.unknownType; |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5068 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5069 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5070 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5071 |
|
24609
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5072 |
/* Construct a dummy method type. If we have a method declaration, |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5073 |
* and the declared return type is void, then use that return type |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5074 |
* instead of UNKNOWN to avoid spurious error messages in lambda |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5075 |
* bodies (see:JDK-8041704). |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5076 |
*/ |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5077 |
private Type dummyMethodType(JCMethodDecl md) { |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5078 |
Type restype = syms.unknownType; |
48931
b25eb74ec283
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents:
48721
diff
changeset
|
5079 |
if (md != null && md.restype != null && md.restype.hasTag(TYPEIDENT)) { |
24609
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5080 |
JCPrimitiveTypeTree prim = (JCPrimitiveTypeTree)md.restype; |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5081 |
if (prim.typetag == VOID) |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5082 |
restype = syms.voidType; |
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5083 |
} |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
5084 |
return new MethodType(List.nil(), restype, |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
42827
diff
changeset
|
5085 |
List.nil(), syms.methodClass); |
24609
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5086 |
} |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5087 |
private Type dummyMethodType() { |
24609
5139d892e270
8041704: wrong error message when mixing lambda expression and inner class
pgovereau
parents:
24401
diff
changeset
|
5088 |
return dummyMethodType(null); |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5089 |
} |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5090 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5091 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5092 |
public void scan(JCTree tree) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5093 |
if (tree == null) return; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5094 |
if (tree instanceof JCExpression) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5095 |
initTypeIfNeeded(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5096 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5097 |
super.scan(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5098 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5099 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5100 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5101 |
public void visitIdent(JCIdent that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5102 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5103 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5104 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5105 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5106 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5107 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5108 |
public void visitSelect(JCFieldAccess that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5109 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5110 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5111 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5112 |
super.visitSelect(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5113 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5114 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5115 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5116 |
public void visitClassDef(JCClassDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5117 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5118 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5119 |
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
|
5120 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5121 |
super.visitClassDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5122 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5123 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5124 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5125 |
public void visitMethodDef(JCMethodDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5126 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5127 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5128 |
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
|
5129 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5130 |
super.visitMethodDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5131 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5132 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5133 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5134 |
public void visitVarDef(JCVariableDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5135 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5136 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5137 |
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
|
5138 |
that.sym.adr = 0; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5139 |
} |
44060
f420de7e26fa
8175790: field JCVariableDecl.vartype can't be null after post attribution analysis
vromero
parents:
43761
diff
changeset
|
5140 |
if (that.vartype == null) { |
47318
423f5e46016e
8188225: AST could be improved in presence of var types.
jlahoda
parents:
47315
diff
changeset
|
5141 |
that.vartype = make.at(Position.NOPOS).Erroneous(); |
44060
f420de7e26fa
8175790: field JCVariableDecl.vartype can't be null after post attribution analysis
vromero
parents:
43761
diff
changeset
|
5142 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5143 |
super.visitVarDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5144 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5145 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5146 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5147 |
public void visitNewClass(JCNewClass that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5148 |
if (that.constructor == null) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5149 |
that.constructor = new MethodSymbol(0, names.init, |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5150 |
dummyMethodType(), syms.noSymbol); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5151 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5152 |
if (that.constructorType == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5153 |
that.constructorType = syms.unknownType; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5154 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5155 |
super.visitNewClass(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5156 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5157 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5158 |
@Override |
10187 | 5159 |
public void visitAssignop(JCAssignOp that) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5160 |
if (that.operator == null) { |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5161 |
that.operator = new OperatorSymbol(names.empty, dummyMethodType(), |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5162 |
-1, syms.noSymbol); |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5163 |
} |
10187 | 5164 |
super.visitAssignop(that); |
5165 |
} |
|
5166 |
||
5167 |
@Override |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5168 |
public void visitBinary(JCBinary that) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5169 |
if (that.operator == null) { |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5170 |
that.operator = new OperatorSymbol(names.empty, dummyMethodType(), |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5171 |
-1, syms.noSymbol); |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5172 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5173 |
super.visitBinary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5174 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5175 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5176 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5177 |
public void visitUnary(JCUnary that) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5178 |
if (that.operator == null) { |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5179 |
that.operator = new OperatorSymbol(names.empty, dummyMethodType(), |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5180 |
-1, syms.noSymbol); |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5181 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5182 |
super.visitUnary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5183 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5184 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5185 |
@Override |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5186 |
public void visitLambda(JCLambda that) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5187 |
super.visitLambda(that); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5188 |
if (that.targets == null) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5189 |
that.targets = List.nil(); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5190 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5191 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5192 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5193 |
@Override |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5194 |
public void visitReference(JCMemberReference that) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5195 |
super.visitReference(that); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5196 |
if (that.sym == null) { |
22685
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5197 |
that.sym = new MethodSymbol(0, names.empty, dummyMethodType(), |
c8d0807378b6
8030816: javac crashes when mixing lambdas and inner classes
vromero
parents:
22440
diff
changeset
|
5198 |
syms.noSymbol); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5199 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5200 |
if (that.targets == null) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5201 |
that.targets = List.nil(); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15356
diff
changeset
|
5202 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
5203 |
} |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5204 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
5205 |
// </editor-fold> |
36526 | 5206 |
|
5207 |
public void setPackageSymbols(JCExpression pid, Symbol pkg) { |
|
5208 |
new TreeScanner() { |
|
5209 |
Symbol packge = pkg; |
|
5210 |
@Override |
|
5211 |
public void visitIdent(JCIdent that) { |
|
5212 |
that.sym = packge; |
|
5213 |
} |
|
5214 |
||
5215 |
@Override |
|
5216 |
public void visitSelect(JCFieldAccess that) { |
|
5217 |
that.sym = packge; |
|
5218 |
packge = packge.owner; |
|
5219 |
super.visitSelect(that); |
|
5220 |
} |
|
5221 |
}.scan(pid); |
|
5222 |
} |
|
5223 |
||
10 | 5224 |
} |