author | jlahoda |
Wed, 02 Nov 2016 16:48:57 +0100 | |
changeset 41931 | d7c9720c4223 |
parent 41526 | 265017792980 |
child 41932 | b23b4712933b |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35810 | 2 |
* Copyright (c) 1999, 2016, 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 |
||
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
28 |
import com.sun.tools.javac.api.Formattable.LocalizedString; |
10 | 29 |
import com.sun.tools.javac.code.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
30 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
14052 | 31 |
import com.sun.tools.javac.code.Symbol.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
32 |
import com.sun.tools.javac.code.Type.*; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
33 |
import com.sun.tools.javac.comp.Attr.ResultInfo; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
34 |
import com.sun.tools.javac.comp.Check.CheckContext; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
35 |
import com.sun.tools.javac.comp.DeferredAttr.AttrMode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
36 |
import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
37 |
import com.sun.tools.javac.comp.DeferredAttr.DeferredType; |
15705 | 38 |
import com.sun.tools.javac.comp.Infer.FreeTypeListener; |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
39 |
import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
40 |
import com.sun.tools.javac.comp.Resolve.MethodResolutionDiagHelper.Template; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
41 |
import com.sun.tools.javac.comp.Resolve.ReferenceLookupResult.StaticKind; |
10 | 42 |
import com.sun.tools.javac.jvm.*; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
43 |
import com.sun.tools.javac.main.Option; |
10 | 44 |
import com.sun.tools.javac.tree.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
45 |
import com.sun.tools.javac.tree.JCTree.*; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
46 |
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
47 |
import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
48 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
49 |
import com.sun.tools.javac.util.DefinedBy.Api; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
50 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
51 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
52 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
10 | 53 |
|
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
54 |
import java.util.Arrays; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
55 |
import java.util.Collection; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
56 |
import java.util.EnumSet; |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
57 |
import java.util.HashSet; |
14052 | 58 |
import java.util.Iterator; |
14444 | 59 |
import java.util.LinkedHashMap; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
60 |
import java.util.Map; |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
61 |
import java.util.Set; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
62 |
import java.util.function.BiFunction; |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
63 |
import java.util.function.BiPredicate; |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
64 |
import java.util.function.Predicate; |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
65 |
import java.util.stream.Stream; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
66 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
67 |
import javax.lang.model.element.ElementVisitor; |
10 | 68 |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
69 |
import com.sun.tools.javac.code.Directive.ExportsDirective; |
10 | 70 |
import static com.sun.tools.javac.code.Flags.*; |
10950 | 71 |
import static com.sun.tools.javac.code.Flags.BLOCK; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
72 |
import static com.sun.tools.javac.code.Flags.STATIC; |
10 | 73 |
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
|
74 |
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:
14062
diff
changeset
|
75 |
import static com.sun.tools.javac.code.TypeTag.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
76 |
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*; |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
77 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
78 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
10950 | 79 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
80 |
|
10 | 81 |
/** Helper class for name resolution, used mostly by the attribution phase. |
82 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
83 |
* <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
|
84 |
* If you write code that depends on this, you do so at your own risk. |
10 | 85 |
* This code and its internal interfaces are subject to change or |
86 |
* deletion without notice.</b> |
|
87 |
*/ |
|
88 |
public class Resolve { |
|
22163 | 89 |
protected static final Context.Key<Resolve> resolveKey = new Context.Key<>(); |
10 | 90 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
91 |
Names names; |
10 | 92 |
Log log; |
93 |
Symtab syms; |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
94 |
Attr attr; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
95 |
DeferredAttr deferredAttr; |
10 | 96 |
Check chk; |
97 |
Infer infer; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24404
diff
changeset
|
98 |
ClassFinder finder; |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
99 |
ModuleFinder moduleFinder; |
10 | 100 |
Types types; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
101 |
JCDiagnostic.Factory diags; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
102 |
public final boolean allowMethodHandles; |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
103 |
public final boolean allowFunctionalInterfaceMostSpecific; |
36526 | 104 |
public final boolean allowModules; |
25435
928866794984
8049075: javac, wildcards and generic vararg method invocation not accepted
vromero
parents:
25279
diff
changeset
|
105 |
public final boolean checkVarargsAccessAfterResolution; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
106 |
private final boolean compactMethodDiags; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
107 |
final EnumSet<VerboseResolutionMode> verboseResolutionMode; |
10 | 108 |
|
36526 | 109 |
private final boolean checkModuleAccess; |
110 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
111 |
WriteableScope polymorphicSignatureScope; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
112 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
113 |
protected Resolve(Context context) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
114 |
context.put(resolveKey, this); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
115 |
syms = Symtab.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
116 |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
117 |
varNotFound = new SymbolNotFoundError(ABSENT_VAR); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
118 |
methodNotFound = new SymbolNotFoundError(ABSENT_MTH); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
119 |
typeNotFound = new SymbolNotFoundError(ABSENT_TYP); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
120 |
referenceNotFound = new ReferenceLookupResult(methodNotFound, null); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
121 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
122 |
names = Names.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
123 |
log = Log.instance(context); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
124 |
attr = Attr.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
125 |
deferredAttr = DeferredAttr.instance(context); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
126 |
chk = Check.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
127 |
infer = Infer.instance(context); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24404
diff
changeset
|
128 |
finder = ClassFinder.instance(context); |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
129 |
moduleFinder = ModuleFinder.instance(context); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
130 |
types = Types.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
131 |
diags = JCDiagnostic.Factory.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
132 |
Source source = Source.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
133 |
Options options = Options.instance(context); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
134 |
compactMethodDiags = options.isSet(Option.XDIAGS, "compact") || |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
135 |
options.isUnset(Option.XDIAGS) && options.isUnset("rawDiagnostics"); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
136 |
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
137 |
Target target = Target.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
138 |
allowMethodHandles = target.hasMethodHandles(); |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
139 |
allowFunctionalInterfaceMostSpecific = source.allowFunctionalInterfaceMostSpecific(); |
25435
928866794984
8049075: javac, wildcards and generic vararg method invocation not accepted
vromero
parents:
25279
diff
changeset
|
140 |
checkVarargsAccessAfterResolution = |
25008
969bfaae5bce
8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents:
24612
diff
changeset
|
141 |
source.allowPostApplicabilityVarargsAccessCheck(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
142 |
polymorphicSignatureScope = WriteableScope.create(syms.noSymbol); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
143 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
144 |
inapplicableMethodException = new InapplicableMethodException(diags); |
36526 | 145 |
|
146 |
allowModules = source.allowModules(); |
|
147 |
||
148 |
// The following is required, for now, to support building |
|
149 |
// Swing beaninfo via javadoc. |
|
150 |
checkModuleAccess = !options.isSet("noModules"); |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
151 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
152 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
153 |
/** error symbols, which are returned when resolution fails |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
154 |
*/ |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
155 |
private final SymbolNotFoundError varNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
156 |
private final SymbolNotFoundError methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
157 |
private final SymbolNotFoundError typeNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
158 |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
159 |
/** empty reference lookup result */ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
160 |
private final ReferenceLookupResult referenceNotFound; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
161 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
162 |
public static Resolve instance(Context context) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
163 |
Resolve instance = context.get(resolveKey); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
164 |
if (instance == null) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
165 |
instance = new Resolve(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
166 |
return instance; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
167 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
168 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
169 |
private static Symbol bestOf(Symbol s1, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
170 |
Symbol s2) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
171 |
return s1.kind.betterThan(s2.kind) ? s1 : s2; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
172 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
173 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
174 |
// <editor-fold defaultstate="collapsed" desc="Verbose resolution diagnostics support"> |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
175 |
enum VerboseResolutionMode { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
176 |
SUCCESS("success"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
177 |
FAILURE("failure"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
178 |
APPLICABLE("applicable"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
179 |
INAPPLICABLE("inapplicable"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
180 |
DEFERRED_INST("deferred-inference"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
181 |
PREDEF("predef"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
182 |
OBJECT_INIT("object-init"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
183 |
INTERNAL("internal"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
184 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14724
diff
changeset
|
185 |
final String opt; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
186 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
187 |
private VerboseResolutionMode(String opt) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
188 |
this.opt = opt; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
189 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
190 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
191 |
static EnumSet<VerboseResolutionMode> getVerboseResolutionMode(Options opts) { |
39599 | 192 |
String s = opts.get("debug.verboseResolution"); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
193 |
EnumSet<VerboseResolutionMode> res = EnumSet.noneOf(VerboseResolutionMode.class); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
194 |
if (s == null) return res; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
195 |
if (s.contains("all")) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
196 |
res = EnumSet.allOf(VerboseResolutionMode.class); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
197 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
198 |
Collection<String> args = Arrays.asList(s.split(",")); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
199 |
for (VerboseResolutionMode mode : values()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
200 |
if (args.contains(mode.opt)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
201 |
res.add(mode); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
202 |
} else if (args.contains("-" + mode.opt)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
203 |
res.remove(mode); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
204 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
205 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
206 |
return res; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
207 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
208 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
209 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
210 |
void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
211 |
List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
212 |
boolean success = !bestSoFar.kind.isResolutionError(); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
213 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
214 |
if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
215 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
216 |
} else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
217 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
218 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
219 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
220 |
if (bestSoFar.name == names.init && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
221 |
bestSoFar.owner == syms.objectType.tsym && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
222 |
!verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
223 |
return; //skip diags for Object constructor resolution |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
224 |
} else if (site == syms.predefClass.type && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
225 |
!verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
226 |
return; //skip spurious diags for predef symbols (i.e. operators) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
227 |
} else if (currentResolutionContext.internalResolution && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
228 |
!verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
229 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
230 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
231 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
232 |
int pos = 0; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
233 |
int mostSpecificPos = -1; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19940
diff
changeset
|
234 |
ListBuffer<JCDiagnostic> subDiags = new ListBuffer<>(); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
235 |
for (Candidate c : currentResolutionContext.candidates) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
236 |
if (currentResolutionContext.step != c.step || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
237 |
(c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
238 |
(!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
239 |
continue; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
240 |
} else { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
241 |
subDiags.append(c.isApplicable() ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
242 |
getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
243 |
getVerboseInapplicableCandidateDiag(pos, c.sym, c.details)); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
244 |
if (c.sym == bestSoFar) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
245 |
mostSpecificPos = pos; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
246 |
pos++; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
247 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
248 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
249 |
String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1"; |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
250 |
List<Type> argtypes2 = argtypes.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, bestSoFar, currentResolutionContext.step)); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
251 |
JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
252 |
site.tsym, mostSpecificPos, currentResolutionContext.step, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
253 |
methodArguments(argtypes2), |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
254 |
methodArguments(typeargtypes)); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
255 |
JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList()); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
256 |
log.report(d); |
10 | 257 |
} |
258 |
||
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
259 |
JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
260 |
JCDiagnostic subDiag = null; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
261 |
if (sym.type.hasTag(FORALL)) { |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
262 |
subDiag = diags.fragment("partial.inst.sig", inst); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
263 |
} |
10 | 264 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
265 |
String key = subDiag == null ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
266 |
"applicable.method.found" : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
267 |
"applicable.method.found.1"; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
268 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
269 |
return diags.fragment(key, pos, sym, subDiag); |
10 | 270 |
} |
271 |
||
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
272 |
JCDiagnostic getVerboseInapplicableCandidateDiag(int pos, Symbol sym, JCDiagnostic subDiag) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
273 |
return diags.fragment("not.applicable.method.found", pos, sym, subDiag); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
274 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
275 |
// </editor-fold> |
10 | 276 |
|
277 |
/* ************************************************************************ |
|
278 |
* Identifier resolution |
|
279 |
*************************************************************************/ |
|
280 |
||
281 |
/** An environment is "static" if its static level is greater than |
|
282 |
* the one of its outer environment |
|
283 |
*/ |
|
14056 | 284 |
protected static boolean isStatic(Env<AttrContext> env) { |
22440
d40c30326317
8028389: NullPointerException compiling annotation values that have bodies
alundblad
parents:
22167
diff
changeset
|
285 |
return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; |
10 | 286 |
} |
287 |
||
288 |
/** An environment is an "initializer" if it is a constructor or |
|
289 |
* an instance initializer. |
|
290 |
*/ |
|
291 |
static boolean isInitializer(Env<AttrContext> env) { |
|
292 |
Symbol owner = env.info.scope.owner; |
|
293 |
return owner.isConstructor() || |
|
294 |
owner.owner.kind == TYP && |
|
295 |
(owner.kind == VAR || |
|
296 |
owner.kind == MTH && (owner.flags() & BLOCK) != 0) && |
|
297 |
(owner.flags() & STATIC) == 0; |
|
298 |
} |
|
299 |
||
300 |
/** Is class accessible in given evironment? |
|
301 |
* @param env The current environment. |
|
302 |
* @param c The class whose accessibility is checked. |
|
303 |
*/ |
|
304 |
public boolean isAccessible(Env<AttrContext> env, TypeSymbol c) { |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
305 |
return isAccessible(env, c, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
306 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
307 |
|
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
308 |
public boolean isAccessible(Env<AttrContext> env, TypeSymbol c, boolean checkInner) { |
32951
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
309 |
|
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
310 |
/* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
311 |
to refer to an inaccessible type |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
312 |
*/ |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
313 |
if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0) |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
314 |
return true; |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
315 |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
316 |
boolean isAccessible = false; |
10 | 317 |
switch ((short)(c.flags() & AccessFlags)) { |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
318 |
case PRIVATE: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
319 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
320 |
env.enclClass.sym.outermostClass() == |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
321 |
c.owner.outermostClass(); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
322 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
323 |
case 0: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
324 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
325 |
env.toplevel.packge == c.owner // fast special case |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
326 |
|| |
32951
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
327 |
env.toplevel.packge == c.packge(); |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
328 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
329 |
default: // error recovery |
36526 | 330 |
isAccessible = true; |
331 |
break; |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
332 |
case PUBLIC: |
36526 | 333 |
if (allowModules && checkModuleAccess) { |
334 |
ModuleSymbol currModule = env.toplevel.modle; |
|
335 |
currModule.complete(); |
|
336 |
PackageSymbol p = c.packge(); |
|
337 |
isAccessible = |
|
338 |
(currModule == p.modle) || currModule.visiblePackages.get(p.fullname) == p || p == syms.rootPackage; |
|
339 |
} else { |
|
340 |
isAccessible = true; |
|
341 |
} |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
342 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
343 |
case PROTECTED: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
344 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
345 |
env.toplevel.packge == c.owner // fast special case |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
346 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
347 |
env.toplevel.packge == c.packge() |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
348 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
349 |
isInnerSubClass(env.enclClass.sym, c.owner); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
350 |
break; |
10 | 351 |
} |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
352 |
return (checkInner == false || c.type.getEnclosingType() == Type.noType) ? |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
353 |
isAccessible : |
7637 | 354 |
isAccessible && isAccessible(env, c.type.getEnclosingType(), checkInner); |
10 | 355 |
} |
356 |
//where |
|
357 |
/** Is given class a subclass of given base class, or an inner class |
|
358 |
* of a subclass? |
|
359 |
* Return null if no such class exists. |
|
360 |
* @param c The class which is the subclass or is contained in it. |
|
361 |
* @param base The base class |
|
362 |
*/ |
|
363 |
private boolean isInnerSubClass(ClassSymbol c, Symbol base) { |
|
364 |
while (c != null && !c.isSubClass(base, types)) { |
|
365 |
c = c.owner.enclClass(); |
|
366 |
} |
|
367 |
return c != null; |
|
368 |
} |
|
369 |
||
370 |
boolean isAccessible(Env<AttrContext> env, Type t) { |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
371 |
return isAccessible(env, t, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
372 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
373 |
|
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
374 |
boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
375 |
return (t.hasTag(ARRAY)) |
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
376 |
? isAccessible(env, types.cvarUpperBound(types.elemtype(t))) |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
377 |
: isAccessible(env, t.tsym, checkInner); |
10 | 378 |
} |
379 |
||
17998
02a5abb2ae2f
7179353: try-with-resources fails to compile with generic exception parameters
vromero
parents:
17804
diff
changeset
|
380 |
/** Is symbol accessible as a member of given type in given environment? |
10 | 381 |
* @param env The current environment. |
382 |
* @param site The type of which the tested symbol is regarded |
|
383 |
* as a member. |
|
384 |
* @param sym The symbol. |
|
385 |
*/ |
|
386 |
public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym) { |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
387 |
return isAccessible(env, site, sym, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
388 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
389 |
public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) { |
10 | 390 |
if (sym.name == names.init && sym.owner != site.tsym) return false; |
32951
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
391 |
|
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
392 |
/* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
393 |
to refer to an inaccessible type |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
394 |
*/ |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
395 |
if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0) |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
396 |
return true; |
a098b538296c
8075799: Extraneous access checks implemented by javac
sadayapalam
parents:
32949
diff
changeset
|
397 |
|
10 | 398 |
switch ((short)(sym.flags() & AccessFlags)) { |
399 |
case PRIVATE: |
|
400 |
return |
|
401 |
(env.enclClass.sym == sym.owner // fast special case |
|
402 |
|| |
|
403 |
env.enclClass.sym.outermostClass() == |
|
404 |
sym.owner.outermostClass()) |
|
405 |
&& |
|
406 |
sym.isInheritedIn(site.tsym, types); |
|
407 |
case 0: |
|
408 |
return |
|
409 |
(env.toplevel.packge == sym.owner.owner // fast special case |
|
410 |
|| |
|
411 |
env.toplevel.packge == sym.packge()) |
|
412 |
&& |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
413 |
isAccessible(env, site, checkInner) |
10 | 414 |
&& |
2511 | 415 |
sym.isInheritedIn(site.tsym, types) |
416 |
&& |
|
417 |
notOverriddenIn(site, sym); |
|
10 | 418 |
case PROTECTED: |
419 |
return |
|
420 |
(env.toplevel.packge == sym.owner.owner // fast special case |
|
421 |
|| |
|
422 |
env.toplevel.packge == sym.packge() |
|
423 |
|| |
|
424 |
isProtectedAccessible(sym, env.enclClass.sym, site) |
|
425 |
|| |
|
426 |
// OK to select instance method or field from 'super' or type name |
|
427 |
// (but type names should be disallowed elsewhere!) |
|
428 |
env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP) |
|
429 |
&& |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
430 |
isAccessible(env, site, checkInner) |
10 | 431 |
&& |
2511 | 432 |
notOverriddenIn(site, sym); |
10 | 433 |
default: // this case includes erroneous combinations as well |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
434 |
return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym); |
2511 | 435 |
} |
436 |
} |
|
437 |
//where |
|
438 |
/* `sym' is accessible only if not overridden by |
|
439 |
* another symbol which is a member of `site' |
|
440 |
* (because, if it is overridden, `sym' is not strictly |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
441 |
* speaking a member of `site'). A polymorphic signature method |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
442 |
* cannot be overridden (e.g. MH.invokeExact(Object[])). |
2511 | 443 |
*/ |
444 |
private boolean notOverriddenIn(Type site, Symbol sym) { |
|
445 |
if (sym.kind != MTH || sym.isConstructor() || sym.isStatic()) |
|
446 |
return true; |
|
447 |
else { |
|
448 |
Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true); |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
449 |
return (s2 == null || s2 == sym || sym.owner == s2.owner || |
3372
544ec1ab333c
6846972: cannot access member of raw type when erasure change overriding into overloading
mcimadamore
parents:
3143
diff
changeset
|
450 |
!types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym))); |
10 | 451 |
} |
452 |
} |
|
453 |
//where |
|
454 |
/** Is given protected symbol accessible if it is selected from given site |
|
455 |
* and the selection takes place in given class? |
|
456 |
* @param sym The symbol with protected access |
|
457 |
* @param c The class where the access takes place |
|
458 |
* @site The type of the qualifier |
|
459 |
*/ |
|
460 |
private |
|
461 |
boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { |
|
21024
e1efbecefefa
8025816: javac crash with method reference with a type variable as the site
vromero
parents:
20249
diff
changeset
|
462 |
Type newSite = site.hasTag(TYPEVAR) ? site.getUpperBound() : site; |
10 | 463 |
while (c != null && |
464 |
!(c.isSubClass(sym.owner, types) && |
|
465 |
(c.flags() & INTERFACE) == 0 && |
|
466 |
// In JLS 2e 6.6.2.1, the subclass restriction applies |
|
467 |
// only to instance fields and methods -- types are excluded |
|
468 |
// regardless of whether they are declared 'static' or not. |
|
21024
e1efbecefefa
8025816: javac crash with method reference with a type variable as the site
vromero
parents:
20249
diff
changeset
|
469 |
((sym.flags() & STATIC) != 0 || sym.kind == TYP || newSite.tsym.isSubClass(c, types)))) |
10 | 470 |
c = c.owner.enclClass(); |
471 |
return c != null; |
|
472 |
} |
|
473 |
||
14547 | 474 |
/** |
475 |
* Performs a recursive scan of a type looking for accessibility problems |
|
476 |
* from current attribution environment |
|
477 |
*/ |
|
478 |
void checkAccessibleType(Env<AttrContext> env, Type t) { |
|
479 |
accessibilityChecker.visit(t, env); |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* Accessibility type-visitor |
|
484 |
*/ |
|
485 |
Types.SimpleVisitor<Void, Env<AttrContext>> accessibilityChecker = |
|
486 |
new Types.SimpleVisitor<Void, Env<AttrContext>>() { |
|
487 |
||
488 |
void visit(List<Type> ts, Env<AttrContext> env) { |
|
489 |
for (Type t : ts) { |
|
490 |
visit(t, env); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
public Void visitType(Type t, Env<AttrContext> env) { |
|
495 |
return null; |
|
496 |
} |
|
497 |
||
498 |
@Override |
|
499 |
public Void visitArrayType(ArrayType t, Env<AttrContext> env) { |
|
500 |
visit(t.elemtype, env); |
|
501 |
return null; |
|
502 |
} |
|
503 |
||
504 |
@Override |
|
505 |
public Void visitClassType(ClassType t, Env<AttrContext> env) { |
|
506 |
visit(t.getTypeArguments(), env); |
|
507 |
if (!isAccessible(env, t, true)) { |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
508 |
accessBase(new AccessError(env, null, t.tsym), env.tree.pos(), env.enclClass.sym, t, t.tsym.name, true); |
14547 | 509 |
} |
510 |
return null; |
|
511 |
} |
|
512 |
||
513 |
@Override |
|
514 |
public Void visitWildcardType(WildcardType t, Env<AttrContext> env) { |
|
515 |
visit(t.type, env); |
|
516 |
return null; |
|
517 |
} |
|
518 |
||
519 |
@Override |
|
520 |
public Void visitMethodType(MethodType t, Env<AttrContext> env) { |
|
521 |
visit(t.getParameterTypes(), env); |
|
522 |
visit(t.getReturnType(), env); |
|
523 |
visit(t.getThrownTypes(), env); |
|
524 |
return null; |
|
525 |
} |
|
526 |
}; |
|
527 |
||
10 | 528 |
/** Try to instantiate the type of a method so that it fits |
17998
02a5abb2ae2f
7179353: try-with-resources fails to compile with generic exception parameters
vromero
parents:
17804
diff
changeset
|
529 |
* given type arguments and argument types. If successful, return |
10 | 530 |
* the method's instantiated type, else return null. |
531 |
* The instantiation will take into account an additional leading |
|
532 |
* formal parameter if the method is an instance method seen as a member |
|
17998
02a5abb2ae2f
7179353: try-with-resources fails to compile with generic exception parameters
vromero
parents:
17804
diff
changeset
|
533 |
* of an under determined site. In this case, we treat site as an additional |
10 | 534 |
* parameter and the parameters of the class containing the method as |
535 |
* additional type variables that get instantiated. |
|
536 |
* |
|
537 |
* @param env The current environment |
|
538 |
* @param site The type of which the method is a member. |
|
539 |
* @param m The method symbol. |
|
540 |
* @param argtypes The invocation's given value arguments. |
|
541 |
* @param typeargtypes The invocation's given type arguments. |
|
542 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
543 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
544 |
*/ |
|
545 |
Type rawInstantiate(Env<AttrContext> env, |
|
546 |
Type site, |
|
547 |
Symbol m, |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
548 |
ResultInfo resultInfo, |
10 | 549 |
List<Type> argtypes, |
550 |
List<Type> typeargtypes, |
|
551 |
boolean allowBoxing, |
|
552 |
boolean useVarargs, |
|
14444 | 553 |
Warner warn) throws Infer.InferenceException { |
10 | 554 |
Type mt = types.memberType(site, m); |
555 |
// tvars is the list of formal type variables for which type arguments |
|
556 |
// need to inferred. |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
557 |
List<Type> tvars = List.nil(); |
10 | 558 |
if (typeargtypes == null) typeargtypes = List.nil(); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
559 |
if (!mt.hasTag(FORALL) && typeargtypes.nonEmpty()) { |
10 | 560 |
// This is not a polymorphic method, but typeargs are supplied |
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9302
diff
changeset
|
561 |
// which is fine, see JLS 15.12.2.1 |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
562 |
} else if (mt.hasTag(FORALL) && typeargtypes.nonEmpty()) { |
10 | 563 |
ForAll pmt = (ForAll) mt; |
564 |
if (typeargtypes.length() != pmt.tvars.length()) |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
565 |
throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args |
10 | 566 |
// Check type arguments are within bounds |
567 |
List<Type> formals = pmt.tvars; |
|
568 |
List<Type> actuals = typeargtypes; |
|
569 |
while (formals.nonEmpty() && actuals.nonEmpty()) { |
|
570 |
List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head), |
|
571 |
pmt.tvars, typeargtypes); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
572 |
for (; bounds.nonEmpty(); bounds = bounds.tail) { |
10 | 573 |
if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn)) |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
574 |
throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
575 |
} |
10 | 576 |
formals = formals.tail; |
577 |
actuals = actuals.tail; |
|
578 |
} |
|
579 |
mt = types.subst(pmt.qtype, pmt.tvars, typeargtypes); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
580 |
} else if (mt.hasTag(FORALL)) { |
10 | 581 |
ForAll pmt = (ForAll) mt; |
582 |
List<Type> tvars1 = types.newInstances(pmt.tvars); |
|
583 |
tvars = tvars.appendList(tvars1); |
|
584 |
mt = types.subst(pmt.qtype, pmt.tvars, tvars1); |
|
585 |
} |
|
586 |
||
587 |
// find out whether we need to go the slow route via infer |
|
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
588 |
boolean instNeeded = tvars.tail != null; /*inlined: tvars.nonEmpty()*/ |
10 | 589 |
for (List<Type> l = argtypes; |
590 |
l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded; |
|
591 |
l = l.tail) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
592 |
if (l.head.hasTag(FORALL)) instNeeded = true; |
10 | 593 |
} |
594 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
595 |
if (instNeeded) { |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
596 |
return infer.instantiateMethod(env, |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
597 |
tvars, |
10 | 598 |
(MethodType)mt, |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
599 |
resultInfo, |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
600 |
(MethodSymbol)m, |
10 | 601 |
argtypes, |
602 |
allowBoxing, |
|
603 |
useVarargs, |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
604 |
currentResolutionContext, |
10 | 605 |
warn); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
606 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
607 |
|
19914 | 608 |
DeferredAttr.DeferredAttrContext dc = currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn); |
609 |
currentResolutionContext.methodCheck.argumentsAcceptable(env, dc, |
|
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
610 |
argtypes, mt.getParameterTypes(), warn); |
19914 | 611 |
dc.complete(); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
612 |
return mt; |
10 | 613 |
} |
614 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
615 |
Type checkMethod(Env<AttrContext> env, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
616 |
Type site, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
617 |
Symbol m, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
618 |
ResultInfo resultInfo, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
619 |
List<Type> argtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
620 |
List<Type> typeargtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
621 |
Warner warn) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
622 |
MethodResolutionContext prevContext = currentResolutionContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
623 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
624 |
currentResolutionContext = new MethodResolutionContext(); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
625 |
currentResolutionContext.attrMode = (resultInfo.pt == Infer.anyPoly) ? |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
626 |
AttrMode.SPECULATIVE : DeferredAttr.AttrMode.CHECK; |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
627 |
if (env.tree.hasTag(JCTree.Tag.REFERENCE)) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
628 |
//method/constructor references need special check class |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
629 |
//to handle inference variables in 'argtypes' (might happen |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
630 |
//during an unsticking round) |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
631 |
currentResolutionContext.methodCheck = |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
632 |
new MethodReferenceCheck(resultInfo.checkContext.inferenceContext()); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
633 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
634 |
MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
635 |
return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
636 |
step.isBoxingRequired(), step.isVarargsRequired(), warn); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
637 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
638 |
finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
639 |
currentResolutionContext = prevContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
640 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
641 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
642 |
|
10 | 643 |
/** Same but returns null instead throwing a NoInstanceException |
644 |
*/ |
|
645 |
Type instantiate(Env<AttrContext> env, |
|
646 |
Type site, |
|
647 |
Symbol m, |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
648 |
ResultInfo resultInfo, |
10 | 649 |
List<Type> argtypes, |
650 |
List<Type> typeargtypes, |
|
651 |
boolean allowBoxing, |
|
652 |
boolean useVarargs, |
|
653 |
Warner warn) { |
|
654 |
try { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
655 |
return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
656 |
allowBoxing, useVarargs, warn); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
657 |
} catch (InapplicableMethodException ex) { |
10 | 658 |
return null; |
659 |
} |
|
660 |
} |
|
661 |
||
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
662 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
663 |
* This interface defines an entry point that should be used to perform a |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
664 |
* method check. A method check usually consist in determining as to whether |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
665 |
* a set of types (actuals) is compatible with another set of types (formals). |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
666 |
* Since the notion of compatibility can vary depending on the circumstances, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
667 |
* this interfaces allows to easily add new pluggable method check routines. |
10 | 668 |
*/ |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
669 |
interface MethodCheck { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
670 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
671 |
* Main method check routine. A method check usually consist in determining |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
672 |
* as to whether a set of types (actuals) is compatible with another set of |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
673 |
* types (formals). If an incompatibility is found, an unchecked exception |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
674 |
* is assumed to be thrown. |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
675 |
*/ |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
676 |
void argumentsAcceptable(Env<AttrContext> env, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
677 |
DeferredAttrContext deferredAttrContext, |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
678 |
List<Type> argtypes, |
10 | 679 |
List<Type> formals, |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
680 |
Warner warn); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
681 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
682 |
/** |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
683 |
* Retrieve the method check object that will be used during a |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
684 |
* most specific check. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
685 |
*/ |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
686 |
MethodCheck mostSpecificCheck(List<Type> actuals); |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
687 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
688 |
|
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
689 |
/** |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
690 |
* Helper enum defining all method check diagnostics (used by resolveMethodCheck). |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
691 |
*/ |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
692 |
enum MethodCheckDiag { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
693 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
694 |
* Actuals and formals differs in length. |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
695 |
*/ |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
696 |
ARITY_MISMATCH("arg.length.mismatch", "infer.arg.length.mismatch"), |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
697 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
698 |
* An actual is incompatible with a formal. |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
699 |
*/ |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
700 |
ARG_MISMATCH("no.conforming.assignment.exists", "infer.no.conforming.assignment.exists"), |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
701 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
702 |
* An actual is incompatible with the varargs element type. |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
703 |
*/ |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
704 |
VARARG_MISMATCH("varargs.argument.mismatch", "infer.varargs.argument.mismatch"), |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
705 |
/** |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
706 |
* The varargs element type is inaccessible. |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
707 |
*/ |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
708 |
INACCESSIBLE_VARARGS("inaccessible.varargs.type", "inaccessible.varargs.type"); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
709 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
710 |
final String basicKey; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
711 |
final String inferKey; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
712 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
713 |
MethodCheckDiag(String basicKey, String inferKey) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
714 |
this.basicKey = basicKey; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
715 |
this.inferKey = inferKey; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
716 |
} |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
717 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
718 |
String regex() { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
719 |
return String.format("([a-z]*\\.)*(%s|%s)", basicKey, inferKey); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
720 |
} |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
721 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
722 |
|
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
723 |
/** |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
724 |
* Dummy method check object. All methods are deemed applicable, regardless |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
725 |
* of their formal parameter types. |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
726 |
*/ |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
727 |
MethodCheck nilMethodCheck = new MethodCheck() { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
728 |
public void argumentsAcceptable(Env<AttrContext> env, DeferredAttrContext deferredAttrContext, List<Type> argtypes, List<Type> formals, Warner warn) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
729 |
//do nothing - method always applicable regardless of actuals |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
730 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
731 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
732 |
public MethodCheck mostSpecificCheck(List<Type> actuals) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
733 |
return this; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
734 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
735 |
}; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
736 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
737 |
/** |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
738 |
* Base class for 'real' method checks. The class defines the logic for |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
739 |
* iterating through formals and actuals and provides and entry point |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
740 |
* that can be used by subclasses in order to define the actual check logic. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
741 |
*/ |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
742 |
abstract class AbstractMethodCheck implements MethodCheck { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
743 |
@Override |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
744 |
public void argumentsAcceptable(final Env<AttrContext> env, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
745 |
DeferredAttrContext deferredAttrContext, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
746 |
List<Type> argtypes, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
747 |
List<Type> formals, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
748 |
Warner warn) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
749 |
//should we expand formals? |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
750 |
boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); |
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
751 |
JCTree callTree = treeForDiagnostics(env); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
752 |
List<JCExpression> trees = TreeInfo.args(callTree); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
753 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
754 |
//inference context used during this method check |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
755 |
InferenceContext inferenceContext = deferredAttrContext.inferenceContext; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
756 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
757 |
Type varargsFormal = useVarargs ? formals.last() : null; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
758 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
759 |
if (varargsFormal == null && |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
760 |
argtypes.size() != formals.size()) { |
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
761 |
reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
762 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
763 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
764 |
while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
765 |
DiagnosticPosition pos = trees != null ? trees.head : null; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
766 |
checkArg(pos, false, argtypes.head, formals.head, deferredAttrContext, warn); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
767 |
argtypes = argtypes.tail; |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
768 |
formals = formals.tail; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
769 |
trees = trees != null ? trees.tail : trees; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
770 |
} |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
771 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
772 |
if (formals.head != varargsFormal) { |
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
773 |
reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
774 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
775 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
776 |
if (useVarargs) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
777 |
//note: if applicability check is triggered by most specific test, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
778 |
//the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
779 |
final Type elt = types.elemtype(varargsFormal); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
780 |
while (argtypes.nonEmpty()) { |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
781 |
DiagnosticPosition pos = trees != null ? trees.head : null; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
782 |
checkArg(pos, true, argtypes.head, elt, deferredAttrContext, warn); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
783 |
argtypes = argtypes.tail; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
784 |
trees = trees != null ? trees.tail : trees; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
785 |
} |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
786 |
} |
10 | 787 |
} |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
788 |
|
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
789 |
// where |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
790 |
private JCTree treeForDiagnostics(Env<AttrContext> env) { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
791 |
return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
792 |
} |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
793 |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
794 |
/** |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
795 |
* Does the actual argument conforms to the corresponding formal? |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
796 |
*/ |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
797 |
abstract void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
798 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
799 |
protected void reportMC(DiagnosticPosition pos, MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
800 |
boolean inferDiag = inferenceContext != infer.emptyContext; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
801 |
InapplicableMethodException ex = inferDiag ? |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
802 |
infer.inferenceException : inapplicableMethodException; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
803 |
if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
804 |
Object[] args2 = new Object[args.length + 1]; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
805 |
System.arraycopy(args, 0, args2, 1, args.length); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
806 |
args2[0] = inferenceContext.inferenceVars(); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
807 |
args = args2; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
808 |
} |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
809 |
String key = inferDiag ? diag.inferKey : diag.basicKey; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
810 |
throw ex.setMessage(diags.create(DiagnosticType.FRAGMENT, log.currentSource(), pos, key, args)); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
811 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
812 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
813 |
public MethodCheck mostSpecificCheck(List<Type> actuals) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
814 |
return nilMethodCheck; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
815 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
816 |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
817 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
818 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
819 |
/** |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
820 |
* Arity-based method check. A method is applicable if the number of actuals |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
821 |
* supplied conforms to the method signature. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
822 |
*/ |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
823 |
MethodCheck arityMethodCheck = new AbstractMethodCheck() { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
824 |
@Override |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
825 |
void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
826 |
//do nothing - actual always compatible to formals |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
827 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
828 |
|
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
829 |
@Override |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
830 |
public String toString() { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
831 |
return "arityMethodCheck"; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
832 |
} |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
833 |
}; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
834 |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
835 |
List<Type> dummyArgs(int length) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19940
diff
changeset
|
836 |
ListBuffer<Type> buf = new ListBuffer<>(); |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
837 |
for (int i = 0 ; i < length ; i++) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
838 |
buf.append(Type.noType); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
839 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
840 |
return buf.toList(); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
841 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
842 |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
843 |
/** |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
844 |
* Main method applicability routine. Given a list of actual types A, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
845 |
* a list of formal types F, determines whether the types in A are |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
846 |
* compatible (by method invocation conversion) with the types in F. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
847 |
* |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
848 |
* Since this routine is shared between overload resolution and method |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
849 |
* type-inference, a (possibly empty) inference context is used to convert |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
850 |
* formal types to the corresponding 'undet' form ahead of a compatibility |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
851 |
* check so that constraints can be propagated and collected. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
852 |
* |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
853 |
* Moreover, if one or more types in A is a deferred type, this routine uses |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
854 |
* DeferredAttr in order to perform deferred attribution. If one or more actual |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
855 |
* deferred types are stuck, they are placed in a queue and revisited later |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
856 |
* after the remainder of the arguments have been seen. If this is not sufficient |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
857 |
* to 'unstuck' the argument, a cyclic inference error is called out. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
858 |
* |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
859 |
* A method check handler (see above) is used in order to report errors. |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
860 |
*/ |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
861 |
MethodCheck resolveMethodCheck = new AbstractMethodCheck() { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
862 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
863 |
@Override |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
864 |
void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
865 |
ResultInfo mresult = methodCheckResult(varargs, formal, deferredAttrContext, warn); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
866 |
mresult.check(pos, actual); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
867 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
868 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
869 |
@Override |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
870 |
public void argumentsAcceptable(final Env<AttrContext> env, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
871 |
DeferredAttrContext deferredAttrContext, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
872 |
List<Type> argtypes, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
873 |
List<Type> formals, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
874 |
Warner warn) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
875 |
super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); |
29958
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
876 |
// should we check varargs element type accessibility? |
25435
928866794984
8049075: javac, wildcards and generic vararg method invocation not accepted
vromero
parents:
25279
diff
changeset
|
877 |
if (deferredAttrContext.phase.isVarargsRequired()) { |
29958
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
878 |
if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) { |
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
879 |
varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext); |
25435
928866794984
8049075: javac, wildcards and generic vararg method invocation not accepted
vromero
parents:
25279
diff
changeset
|
880 |
} |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
881 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
882 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
883 |
|
29958
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
884 |
/** |
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
885 |
* Test that the runtime array element type corresponding to 't' is accessible. 't' should be the |
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
886 |
* varargs element type of either the method invocation type signature (after inference completes) |
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
887 |
* or the method declaration signature (before inference completes). |
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
888 |
*/ |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
889 |
private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
890 |
if (inferenceContext.free(t)) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
891 |
inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
892 |
@Override |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
893 |
public void typesInferred(InferenceContext inferenceContext) { |
15705 | 894 |
varargsAccessible(env, inferenceContext.asInstType(t), inferenceContext); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
895 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
896 |
}); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
897 |
} else { |
29958
3463809fbb52
8075520: Varargs access check mishandles capture variables
dlsmith
parents:
29776
diff
changeset
|
898 |
if (!isAccessible(env, types.erasure(t))) { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
899 |
Symbol location = env.enclClass.sym; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
900 |
reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
901 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
902 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
903 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
904 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
905 |
private ResultInfo methodCheckResult(final boolean varargsCheck, Type to, |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
906 |
final DeferredAttr.DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
907 |
CheckContext checkContext = new MethodCheckContext(!deferredAttrContext.phase.isBoxingRequired(), deferredAttrContext, rsWarner) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
908 |
MethodCheckDiag methodDiag = varargsCheck ? |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
909 |
MethodCheckDiag.VARARG_MISMATCH : MethodCheckDiag.ARG_MISMATCH; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
910 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
911 |
@Override |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
912 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
913 |
reportMC(pos, methodDiag, deferredAttrContext.inferenceContext, details); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
914 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
915 |
}; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
916 |
return new MethodResultInfo(to, checkContext); |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
917 |
} |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
918 |
|
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
919 |
@Override |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
920 |
public MethodCheck mostSpecificCheck(List<Type> actuals) { |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
921 |
return new MostSpecificCheck(actuals); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
922 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
923 |
|
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
924 |
@Override |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
925 |
public String toString() { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
926 |
return "resolveMethodCheck"; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
927 |
} |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
928 |
}; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
929 |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
930 |
/** |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
931 |
* This class handles method reference applicability checks; since during |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
932 |
* these checks it's sometime possible to have inference variables on |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
933 |
* the actual argument types list, the method applicability check must be |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
934 |
* extended so that inference variables are 'opened' as needed. |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
935 |
*/ |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
936 |
class MethodReferenceCheck extends AbstractMethodCheck { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
937 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
938 |
InferenceContext pendingInferenceContext; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
939 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
940 |
MethodReferenceCheck(InferenceContext pendingInferenceContext) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
941 |
this.pendingInferenceContext = pendingInferenceContext; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
942 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
943 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
944 |
@Override |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
945 |
void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
946 |
ResultInfo mresult = methodCheckResult(varargs, formal, deferredAttrContext, warn); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
947 |
mresult.check(pos, actual); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
948 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
949 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
950 |
private ResultInfo methodCheckResult(final boolean varargsCheck, Type to, |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
951 |
final DeferredAttr.DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
952 |
CheckContext checkContext = new MethodCheckContext(!deferredAttrContext.phase.isBoxingRequired(), deferredAttrContext, rsWarner) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
953 |
MethodCheckDiag methodDiag = varargsCheck ? |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
954 |
MethodCheckDiag.VARARG_MISMATCH : MethodCheckDiag.ARG_MISMATCH; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
955 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
956 |
@Override |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
957 |
public boolean compatible(Type found, Type req, Warner warn) { |
23132
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
958 |
found = pendingInferenceContext.asUndetVar(found); |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
959 |
if (found.hasTag(UNDETVAR) && req.isPrimitive()) { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
960 |
req = types.boxedClass(req).type; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
961 |
} |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
962 |
return super.compatible(found, req, warn); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
963 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
964 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
965 |
@Override |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
966 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
967 |
reportMC(pos, methodDiag, deferredAttrContext.inferenceContext, details); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
968 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
969 |
}; |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
970 |
return new MethodResultInfo(to, checkContext); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
971 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
972 |
|
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
973 |
@Override |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
974 |
public MethodCheck mostSpecificCheck(List<Type> actuals) { |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
975 |
return new MostSpecificCheck(actuals); |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
976 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
977 |
|
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
978 |
@Override |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
979 |
public String toString() { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
980 |
return "MethodReferenceCheck"; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
981 |
} |
22163 | 982 |
} |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
983 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
984 |
/** |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
985 |
* Check context to be used during method applicability checks. A method check |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
986 |
* context might contain inference variables. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
987 |
*/ |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
988 |
abstract class MethodCheckContext implements CheckContext { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
989 |
|
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
990 |
boolean strict; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
991 |
DeferredAttrContext deferredAttrContext; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
992 |
Warner rsWarner; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
993 |
|
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
994 |
public MethodCheckContext(boolean strict, DeferredAttrContext deferredAttrContext, Warner rsWarner) { |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
995 |
this.strict = strict; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
996 |
this.deferredAttrContext = deferredAttrContext; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
997 |
this.rsWarner = rsWarner; |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
998 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
999 |
|
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1000 |
public boolean compatible(Type found, Type req, Warner warn) { |
25279 | 1001 |
InferenceContext inferenceContext = deferredAttrContext.inferenceContext; |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1002 |
return strict ? |
25279 | 1003 |
types.isSubtypeUnchecked(inferenceContext.asUndetVar(found), inferenceContext.asUndetVar(req), warn) : |
1004 |
types.isConvertible(inferenceContext.asUndetVar(found), inferenceContext.asUndetVar(req), warn); |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1005 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1006 |
|
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
1007 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1008 |
throw inapplicableMethodException.setMessage(details); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1009 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1010 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1011 |
public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1012 |
return rsWarner; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1013 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1014 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1015 |
public InferenceContext inferenceContext() { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1016 |
return deferredAttrContext.inferenceContext; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1017 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1018 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1019 |
public DeferredAttrContext deferredAttrContext() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1020 |
return deferredAttrContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1021 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1022 |
|
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1023 |
@Override |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1024 |
public String toString() { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1025 |
return "MethodCheckContext"; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1026 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1027 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1028 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1029 |
/** |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1030 |
* ResultInfo class to be used during method applicability checks. Check |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1031 |
* for deferred types goes through special path. |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1032 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1033 |
class MethodResultInfo extends ResultInfo { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1034 |
|
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1035 |
public MethodResultInfo(Type pt, CheckContext checkContext) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1036 |
attr.super(KindSelector.VAL, pt, checkContext); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1037 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1038 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1039 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1040 |
protected Type check(DiagnosticPosition pos, Type found) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
1041 |
if (found.hasTag(DEFERRED)) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1042 |
DeferredType dt = (DeferredType)found; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1043 |
return dt.check(this); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1044 |
} else { |
28336
9a6ae3c3efb5
8066871: java.lang.VerifyError: Bad local variable type - local final String
mcimadamore
parents:
28331
diff
changeset
|
1045 |
Type uResult = U(found); |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1046 |
Type capturedType = pos == null || pos.getTree() == null ? |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1047 |
types.capture(uResult) : |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1048 |
checkContext.inferenceContext() |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1049 |
.cachedCapture(pos.getTree(), uResult, true); |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
23132
diff
changeset
|
1050 |
return super.check(pos, chk.checkNonVoid(pos, capturedType)); |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
1051 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1052 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1053 |
|
18911 | 1054 |
/** |
1055 |
* javac has a long-standing 'simplification' (see 6391995): |
|
1056 |
* given an actual argument type, the method check is performed |
|
1057 |
* on its upper bound. This leads to inconsistencies when an |
|
1058 |
* argument type is checked against itself. For example, given |
|
1059 |
* a type-variable T, it is not true that {@code U(T) <: T}, |
|
1060 |
* so we need to guard against that. |
|
1061 |
*/ |
|
1062 |
private Type U(Type found) { |
|
1063 |
return found == pt ? |
|
24612
75dc732b45af
8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents:
24604
diff
changeset
|
1064 |
found : types.cvarUpperBound(found); |
18911 | 1065 |
} |
1066 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1067 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1068 |
protected MethodResultInfo dup(Type newPt) { |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1069 |
return new MethodResultInfo(newPt, checkContext); |
14547 | 1070 |
} |
1071 |
||
1072 |
@Override |
|
1073 |
protected ResultInfo dup(CheckContext newContext) { |
|
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1074 |
return new MethodResultInfo(pt, newContext); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
1075 |
} |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1076 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1077 |
@Override |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1078 |
protected ResultInfo dup(Type newPt, CheckContext newContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1079 |
return new MethodResultInfo(newPt, newContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1080 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1081 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1082 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1083 |
/** |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1084 |
* Most specific method applicability routine. Given a list of actual types A, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1085 |
* a list of formal types F1, and a list of formal types F2, the routine determines |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1086 |
* as to whether the types in F1 can be considered more specific than those in F2 w.r.t. |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1087 |
* argument types A. |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1088 |
*/ |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1089 |
class MostSpecificCheck implements MethodCheck { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1090 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1091 |
List<Type> actuals; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1092 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1093 |
MostSpecificCheck(List<Type> actuals) { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1094 |
this.actuals = actuals; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1095 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1096 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1097 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1098 |
public void argumentsAcceptable(final Env<AttrContext> env, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1099 |
DeferredAttrContext deferredAttrContext, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1100 |
List<Type> formals1, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1101 |
List<Type> formals2, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1102 |
Warner warn) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1103 |
formals2 = adjustArgs(formals2, deferredAttrContext.msym, formals1.length(), deferredAttrContext.phase.isVarargsRequired()); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1104 |
while (formals2.nonEmpty()) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1105 |
ResultInfo mresult = methodCheckResult(formals2.head, deferredAttrContext, warn, actuals.head); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1106 |
mresult.check(null, formals1.head); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1107 |
formals1 = formals1.tail; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1108 |
formals2 = formals2.tail; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1109 |
actuals = actuals.isEmpty() ? actuals : actuals.tail; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1110 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1111 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1112 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1113 |
/** |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1114 |
* Create a method check context to be used during the most specific applicability check |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1115 |
*/ |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1116 |
ResultInfo methodCheckResult(Type to, DeferredAttr.DeferredAttrContext deferredAttrContext, |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1117 |
Warner rsWarner, Type actual) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1118 |
return attr.new ResultInfo(KindSelector.VAL, to, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1119 |
new MostSpecificCheckContext(deferredAttrContext, rsWarner, actual)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1120 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1121 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1122 |
/** |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1123 |
* Subclass of method check context class that implements most specific |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1124 |
* method conversion. If the actual type under analysis is a deferred type |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1125 |
* a full blown structural analysis is carried out. |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1126 |
*/ |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1127 |
class MostSpecificCheckContext extends MethodCheckContext { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1128 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1129 |
Type actual; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1130 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1131 |
public MostSpecificCheckContext(DeferredAttrContext deferredAttrContext, Warner rsWarner, Type actual) { |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1132 |
super(true, deferredAttrContext, rsWarner); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1133 |
this.actual = actual; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1134 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1135 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1136 |
public boolean compatible(Type found, Type req, Warner warn) { |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1137 |
if (allowFunctionalInterfaceMostSpecific && |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1138 |
unrelatedFunctionalInterfaces(found, req) && |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1139 |
(actual != null && actual.getTag() == DEFERRED)) { |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1140 |
DeferredType dt = (DeferredType) actual; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1141 |
JCTree speculativeTree = dt.speculativeTree(deferredAttrContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1142 |
if (speculativeTree != deferredAttr.stuckTree) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1143 |
return functionalInterfaceMostSpecific(found, req, speculativeTree); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1144 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1145 |
} |
29146
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1146 |
return compatibleBySubtyping(found, req); |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1147 |
} |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1148 |
|
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1149 |
private boolean compatibleBySubtyping(Type found, Type req) { |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1150 |
if (!strict && found.isPrimitive() != req.isPrimitive()) { |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1151 |
found = found.isPrimitive() ? types.boxedClass(found).type : types.unboxedType(found); |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1152 |
} |
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1153 |
return types.isSubtypeNoCapture(found, deferredAttrContext.inferenceContext.asUndetVar(req)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1154 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1155 |
|
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1156 |
/** Whether {@code t} and {@code s} are unrelated functional interface types. */ |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1157 |
private boolean unrelatedFunctionalInterfaces(Type t, Type s) { |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1158 |
return types.isFunctionalInterface(t.tsym) && |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1159 |
types.isFunctionalInterface(s.tsym) && |
38914
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1160 |
unrelatedInterfaces(t, s); |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1161 |
} |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1162 |
|
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1163 |
/** Whether {@code t} and {@code s} are unrelated interface types; recurs on intersections. **/ |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1164 |
private boolean unrelatedInterfaces(Type t, Type s) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1165 |
if (t.isCompound()) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1166 |
for (Type ti : types.interfaces(t)) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1167 |
if (!unrelatedInterfaces(ti, s)) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1168 |
return false; |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1169 |
} |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1170 |
} |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1171 |
return true; |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1172 |
} else if (s.isCompound()) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1173 |
for (Type si : types.interfaces(s)) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1174 |
if (!unrelatedInterfaces(t, si)) { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1175 |
return false; |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1176 |
} |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1177 |
} |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1178 |
return true; |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1179 |
} else { |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1180 |
return types.asSuper(t, s.tsym) == null && types.asSuper(s, t.tsym) == null; |
2f652b30f1b0
8037804: Implement specified test for related functional interface types
dlsmith
parents:
38913
diff
changeset
|
1181 |
} |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1182 |
} |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1183 |
|
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1184 |
/** Parameters {@code t} and {@code s} are unrelated functional interface types. */ |
29146
7115a5967ed1
8039214: Inference should not map capture variables to their upper bounds
dlsmith
parents:
29051
diff
changeset
|
1185 |
private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree) { |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1186 |
Type tDesc = types.findDescriptorType(types.capture(t)); |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1187 |
Type tDescNoCapture = types.findDescriptorType(t); |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1188 |
Type sDesc = types.findDescriptorType(s); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1189 |
final List<Type> tTypeParams = tDesc.getTypeArguments(); |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1190 |
final List<Type> tTypeParamsNoCapture = tDescNoCapture.getTypeArguments(); |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1191 |
final List<Type> sTypeParams = sDesc.getTypeArguments(); |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1192 |
|
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1193 |
// compare type parameters |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1194 |
if (tDesc.hasTag(FORALL) && !types.hasSameBounds((ForAll) tDesc, (ForAll) tDescNoCapture)) { |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1195 |
return false; |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1196 |
} |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1197 |
// can't use Types.hasSameBounds on sDesc because bounds may have ivars |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1198 |
List<Type> tIter = tTypeParams; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1199 |
List<Type> sIter = sTypeParams; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1200 |
while (tIter.nonEmpty() && sIter.nonEmpty()) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1201 |
Type tBound = tIter.head.getUpperBound(); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1202 |
Type sBound = types.subst(sIter.head.getUpperBound(), sTypeParams, tTypeParams); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1203 |
if (tBound.containsAny(tTypeParams) && inferenceContext().free(sBound)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1204 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1205 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1206 |
if (!types.isSameType(tBound, inferenceContext().asUndetVar(sBound))) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1207 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1208 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1209 |
tIter = tIter.tail; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1210 |
sIter = sIter.tail; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1211 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1212 |
if (!tIter.isEmpty() || !sIter.isEmpty()) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1213 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1214 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1215 |
|
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1216 |
// compare parameters |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1217 |
List<Type> tParams = tDesc.getParameterTypes(); |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1218 |
List<Type> tParamsNoCapture = tDescNoCapture.getParameterTypes(); |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1219 |
List<Type> sParams = sDesc.getParameterTypes(); |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1220 |
while (tParams.nonEmpty() && tParamsNoCapture.nonEmpty() && sParams.nonEmpty()) { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1221 |
Type tParam = tParams.head; |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1222 |
Type tParamNoCapture = types.subst(tParamsNoCapture.head, tTypeParamsNoCapture, tTypeParams); |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1223 |
Type sParam = types.subst(sParams.head, sTypeParams, tTypeParams); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1224 |
if (tParam.containsAny(tTypeParams) && inferenceContext().free(sParam)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1225 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1226 |
} |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1227 |
if (!types.isSubtype(inferenceContext().asUndetVar(sParam), tParam)) { |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1228 |
return false; |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1229 |
} |
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1230 |
if (!types.isSameType(tParamNoCapture, inferenceContext().asUndetVar(sParam))) { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1231 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1232 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1233 |
tParams = tParams.tail; |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1234 |
tParamsNoCapture = tParamsNoCapture.tail; |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1235 |
sParams = sParams.tail; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1236 |
} |
38913
5b15a5ed3b0d
8144767: Fix handling of capture variables in most-specific test
dlsmith
parents:
36996
diff
changeset
|
1237 |
if (!tParams.isEmpty() || !tParamsNoCapture.isEmpty() || !sParams.isEmpty()) { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1238 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1239 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1240 |
|
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1241 |
// compare returns |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1242 |
Type tRet = tDesc.getReturnType(); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1243 |
Type sRet = types.subst(sDesc.getReturnType(), sTypeParams, tTypeParams); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1244 |
if (tRet.containsAny(tTypeParams) && inferenceContext().free(sRet)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1245 |
return false; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1246 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1247 |
MostSpecificFunctionReturnChecker msc = new MostSpecificFunctionReturnChecker(tRet, sRet); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1248 |
msc.scan(tree); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1249 |
return msc.result; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1250 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1251 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1252 |
/** |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1253 |
* Tests whether one functional interface type can be considered more specific |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1254 |
* than another unrelated functional interface type for the scanned expression. |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1255 |
*/ |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1256 |
class MostSpecificFunctionReturnChecker extends DeferredAttr.PolyScanner { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1257 |
|
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1258 |
final Type tRet; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1259 |
final Type sRet; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1260 |
boolean result; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1261 |
|
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1262 |
/** Parameters {@code t} and {@code s} are unrelated functional interface types. */ |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1263 |
MostSpecificFunctionReturnChecker(Type tRet, Type sRet) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1264 |
this.tRet = tRet; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1265 |
this.sRet = sRet; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1266 |
result = true; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1267 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1268 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1269 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1270 |
void skip(JCTree tree) { |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1271 |
result &= false; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1272 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1273 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1274 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1275 |
public void visitConditional(JCConditional tree) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1276 |
scan(asExpr(tree.truepart)); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1277 |
scan(asExpr(tree.falsepart)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1278 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1279 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1280 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1281 |
public void visitReference(JCMemberReference tree) { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1282 |
if (sRet.hasTag(VOID)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1283 |
result &= true; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1284 |
} else if (tRet.hasTag(VOID)) { |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1285 |
result &= false; |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1286 |
} else if (tRet.isPrimitive() != sRet.isPrimitive()) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1287 |
boolean retValIsPrimitive = |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1288 |
tree.refPolyKind == PolyKind.STANDALONE && |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1289 |
tree.sym.type.getReturnType().isPrimitive(); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1290 |
result &= (retValIsPrimitive == tRet.isPrimitive()) && |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1291 |
(retValIsPrimitive != sRet.isPrimitive()); |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1292 |
} else { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1293 |
result &= compatibleBySubtyping(tRet, sRet); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1294 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1295 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1296 |
|
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1297 |
@Override |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1298 |
public void visitParens(JCParens tree) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1299 |
scan(asExpr(tree.expr)); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1300 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1301 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1302 |
@Override |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1303 |
public void visitLambda(JCLambda tree) { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1304 |
if (sRet.hasTag(VOID)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1305 |
result &= true; |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1306 |
} else if (tRet.hasTag(VOID)) { |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1307 |
result &= false; |
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1308 |
} else { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1309 |
List<JCExpression> lambdaResults = lambdaResults(tree); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1310 |
if (!lambdaResults.isEmpty() && unrelatedFunctionalInterfaces(tRet, sRet)) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1311 |
for (JCExpression expr : lambdaResults) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1312 |
result &= functionalInterfaceMostSpecific(tRet, sRet, expr); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1313 |
} |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1314 |
} else if (!lambdaResults.isEmpty() && tRet.isPrimitive() != sRet.isPrimitive()) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1315 |
for (JCExpression expr : lambdaResults) { |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1316 |
boolean retValIsPrimitive = expr.isStandalone() && expr.type.isPrimitive(); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1317 |
result &= (retValIsPrimitive == tRet.isPrimitive()) && |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1318 |
(retValIsPrimitive != sRet.isPrimitive()); |
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1319 |
} |
34992
eaba62b5d8e2
8037789: Surprising more-specific results for lambda bodies with no return expressions
dlsmith
parents:
34854
diff
changeset
|
1320 |
} else { |
34995
e4e19f521ee7
8143852: Implement type variable renaming for functional interface most specific test
dlsmith
parents:
34992
diff
changeset
|
1321 |
result &= compatibleBySubtyping(tRet, sRet); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1322 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1323 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1324 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1325 |
//where |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1326 |
|
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1327 |
private List<JCExpression> lambdaResults(JCLambda lambda) { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1328 |
if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1329 |
return List.of(asExpr((JCExpression) lambda.body)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1330 |
} else { |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1331 |
final ListBuffer<JCExpression> buffer = new ListBuffer<>(); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1332 |
DeferredAttr.LambdaReturnScanner lambdaScanner = |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1333 |
new DeferredAttr.LambdaReturnScanner() { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1334 |
@Override |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1335 |
public void visitReturn(JCReturn tree) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1336 |
if (tree.expr != null) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1337 |
buffer.append(asExpr(tree.expr)); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1338 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1339 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1340 |
}; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1341 |
lambdaScanner.scan(lambda.body); |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1342 |
return buffer.toList(); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1343 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1344 |
} |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1345 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1346 |
private JCExpression asExpr(JCExpression expr) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1347 |
if (expr.type.hasTag(DEFERRED)) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1348 |
JCTree speculativeTree = ((DeferredType)expr.type).speculativeTree(deferredAttrContext); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1349 |
if (speculativeTree != deferredAttr.stuckTree) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1350 |
expr = (JCExpression)speculativeTree; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1351 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1352 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1353 |
return expr; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
32545
diff
changeset
|
1354 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1355 |
} |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24400
diff
changeset
|
1356 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1357 |
} |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1358 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1359 |
public MethodCheck mostSpecificCheck(List<Type> actuals) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1360 |
Assert.error("Cannot get here!"); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1361 |
return null; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1362 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1363 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1364 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1365 |
public static class InapplicableMethodException extends RuntimeException { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1366 |
private static final long serialVersionUID = 0; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1367 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1368 |
JCDiagnostic diagnostic; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1369 |
JCDiagnostic.Factory diags; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1370 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1371 |
InapplicableMethodException(JCDiagnostic.Factory diags) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1372 |
this.diagnostic = null; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1373 |
this.diags = diags; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1374 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1375 |
InapplicableMethodException setMessage() { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1376 |
return setMessage((JCDiagnostic)null); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1377 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1378 |
InapplicableMethodException setMessage(String key) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1379 |
return setMessage(key != null ? diags.fragment(key) : null); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1380 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1381 |
InapplicableMethodException setMessage(String key, Object... args) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
14045
diff
changeset
|
1382 |
return setMessage(key != null ? diags.fragment(key, args) : null); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1383 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1384 |
InapplicableMethodException setMessage(JCDiagnostic diag) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1385 |
this.diagnostic = diag; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1386 |
return this; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1387 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1388 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1389 |
public JCDiagnostic getDiagnostic() { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1390 |
return diagnostic; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1391 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1392 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
1393 |
private final InapplicableMethodException inapplicableMethodException; |
10 | 1394 |
|
1395 |
/* *************************************************************************** |
|
1396 |
* Symbol lookup |
|
1397 |
* the following naming conventions for arguments are used |
|
1398 |
* |
|
1399 |
* env is the environment where the symbol was mentioned |
|
1400 |
* site is the type of which the symbol is a member |
|
1401 |
* name is the symbol's name |
|
1402 |
* if no arguments are given |
|
1403 |
* argtypes are the value arguments, if we search for a method |
|
1404 |
* |
|
1405 |
* If no symbol was found, a ResolveError detailing the problem is returned. |
|
1406 |
****************************************************************************/ |
|
1407 |
||
1408 |
/** Find field. Synthetic fields are always skipped. |
|
1409 |
* @param env The current environment. |
|
1410 |
* @param site The original type from where the selection takes place. |
|
1411 |
* @param name The name of the field. |
|
1412 |
* @param c The class to search for the field. This is always |
|
1413 |
* a superclass or implemented interface of site's class. |
|
1414 |
*/ |
|
1415 |
Symbol findField(Env<AttrContext> env, |
|
1416 |
Type site, |
|
1417 |
Name name, |
|
1418 |
TypeSymbol c) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
1419 |
while (c.type.hasTag(TYPEVAR)) |
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
10
diff
changeset
|
1420 |
c = c.type.getUpperBound().tsym; |
10 | 1421 |
Symbol bestSoFar = varNotFound; |
1422 |
Symbol sym; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1423 |
for (Symbol s : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1424 |
if (s.kind == VAR && (s.flags_field & SYNTHETIC) == 0) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1425 |
return isAccessible(env, site, s) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1426 |
? s : new AccessError(env, site, s); |
10 | 1427 |
} |
1428 |
} |
|
1429 |
Type st = types.supertype(c.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
1430 |
if (st != null && (st.hasTag(CLASS) || st.hasTag(TYPEVAR))) { |
10 | 1431 |
sym = findField(env, site, name, st.tsym); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1432 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 1433 |
} |
1434 |
for (List<Type> l = types.interfaces(c.type); |
|
1435 |
bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); |
|
1436 |
l = l.tail) { |
|
1437 |
sym = findField(env, site, name, l.head.tsym); |
|
18378
00267721fe3a
6360970: javac erroneously accept ambiguous field reference
mcimadamore
parents:
17998
diff
changeset
|
1438 |
if (bestSoFar.exists() && sym.exists() && |
10 | 1439 |
sym.owner != bestSoFar.owner) |
1440 |
bestSoFar = new AmbiguityError(bestSoFar, sym); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1441 |
else |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1442 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 1443 |
} |
1444 |
return bestSoFar; |
|
1445 |
} |
|
1446 |
||
1447 |
/** Resolve a field identifier, throw a fatal error if not found. |
|
1448 |
* @param pos The position to use for error reporting. |
|
1449 |
* @param env The environment current at the method invocation. |
|
1450 |
* @param site The type of the qualifying expression, in which |
|
1451 |
* identifier is searched. |
|
1452 |
* @param name The identifier's name. |
|
1453 |
*/ |
|
1454 |
public VarSymbol resolveInternalField(DiagnosticPosition pos, Env<AttrContext> env, |
|
1455 |
Type site, Name name) { |
|
1456 |
Symbol sym = findField(env, site, name, site.tsym); |
|
1457 |
if (sym.kind == VAR) return (VarSymbol)sym; |
|
1458 |
else throw new FatalError( |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1459 |
diags.fragment("fatal.err.cant.locate.field", |
10 | 1460 |
name)); |
1461 |
} |
|
1462 |
||
1463 |
/** Find unqualified variable or field with given name. |
|
1464 |
* Synthetic fields always skipped. |
|
1465 |
* @param env The current environment. |
|
1466 |
* @param name The name of the variable or field. |
|
1467 |
*/ |
|
1468 |
Symbol findVar(Env<AttrContext> env, Name name) { |
|
1469 |
Symbol bestSoFar = varNotFound; |
|
1470 |
Env<AttrContext> env1 = env; |
|
1471 |
boolean staticOnly = false; |
|
1472 |
while (env1.outer != null) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1473 |
Symbol sym = null; |
10 | 1474 |
if (isStatic(env1)) staticOnly = true; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1475 |
for (Symbol s : env1.info.scope.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1476 |
if (s.kind == VAR && (s.flags_field & SYNTHETIC) == 0) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1477 |
sym = s; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1478 |
break; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1479 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1480 |
} |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1481 |
if (sym == null) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1482 |
sym = findField(env1, env1.enclClass.sym.type, name, env1.enclClass.sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1483 |
} |
10 | 1484 |
if (sym.exists()) { |
1485 |
if (staticOnly && |
|
1486 |
sym.kind == VAR && |
|
1487 |
sym.owner.kind == TYP && |
|
1488 |
(sym.flags() & STATIC) == 0) |
|
1489 |
return new StaticError(sym); |
|
1490 |
else |
|
1491 |
return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1492 |
} else { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1493 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 1494 |
} |
1495 |
||
1496 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
1497 |
env1 = env1.outer; |
|
1498 |
} |
|
1499 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1500 |
Symbol sym = findField(env, syms.predefClass.type, name, syms.predefClass); |
10 | 1501 |
if (sym.exists()) |
1502 |
return sym; |
|
1503 |
if (bestSoFar.exists()) |
|
1504 |
return bestSoFar; |
|
1505 |
||
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19129
diff
changeset
|
1506 |
Symbol origin = null; |
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19129
diff
changeset
|
1507 |
for (Scope sc : new Scope[] { env.toplevel.namedImportScope, env.toplevel.starImportScope }) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1508 |
for (Symbol currentSymbol : sc.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1509 |
if (currentSymbol.kind != VAR) |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19129
diff
changeset
|
1510 |
continue; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1511 |
// invariant: sym.kind == Symbol.Kind.VAR |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
1512 |
if (!bestSoFar.kind.isResolutionError() && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1513 |
currentSymbol.owner != bestSoFar.owner) |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1514 |
return new AmbiguityError(bestSoFar, currentSymbol); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1515 |
else if (!bestSoFar.kind.betterThan(VAR)) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1516 |
origin = sc.getOrigin(currentSymbol).owner; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1517 |
bestSoFar = isAccessible(env, origin.type, currentSymbol) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1518 |
? currentSymbol : new AccessError(env, origin.type, currentSymbol); |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19129
diff
changeset
|
1519 |
} |
10 | 1520 |
} |
19492
767d7330011f
6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents:
19129
diff
changeset
|
1521 |
if (bestSoFar.exists()) break; |
10 | 1522 |
} |
1523 |
if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type) |
|
1524 |
return bestSoFar.clone(origin); |
|
1525 |
else |
|
1526 |
return bestSoFar; |
|
1527 |
} |
|
1528 |
||
1529 |
Warner noteWarner = new Warner(); |
|
1530 |
||
1531 |
/** Select the best method for a call site among two choices. |
|
1532 |
* @param env The current environment. |
|
1533 |
* @param site The original type from where the |
|
1534 |
* selection takes place. |
|
1535 |
* @param argtypes The invocation's value arguments, |
|
1536 |
* @param typeargtypes The invocation's type arguments, |
|
1537 |
* @param sym Proposed new best match. |
|
1538 |
* @param bestSoFar Previously found best match. |
|
1539 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1540 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1541 |
*/ |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1542 |
@SuppressWarnings("fallthrough") |
10 | 1543 |
Symbol selectBest(Env<AttrContext> env, |
1544 |
Type site, |
|
1545 |
List<Type> argtypes, |
|
1546 |
List<Type> typeargtypes, |
|
1547 |
Symbol sym, |
|
1548 |
Symbol bestSoFar, |
|
1549 |
boolean allowBoxing, |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1550 |
boolean useVarargs) { |
14444 | 1551 |
if (sym.kind == ERR || |
16312
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
1552 |
!sym.isInheritedIn(site.tsym, types)) { |
14444 | 1553 |
return bestSoFar; |
16312
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
1554 |
} else if (useVarargs && (sym.flags() & VARARGS) == 0) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
1555 |
return bestSoFar.kind.isResolutionError() ? |
24400
f05df7f58567
8037379: fix for JDK-8029569 doesn't cover all possible cases
vromero
parents:
24396
diff
changeset
|
1556 |
new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) : |
16312
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
1557 |
bestSoFar; |
14444 | 1558 |
} |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
1559 |
Assert.check(!sym.kind.isResolutionError()); |
10 | 1560 |
try { |
32545
9c4c47640408
8073594: javac, before calling rawInstantiate from selectBest the warner should be cleared out
vromero
parents:
32544
diff
changeset
|
1561 |
types.noWarnings.clear(); |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
1562 |
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1563 |
allowBoxing, useVarargs, types.noWarnings); |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1564 |
currentResolutionContext.addApplicableCandidate(sym, mt); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1565 |
} catch (InapplicableMethodException ex) { |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1566 |
currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic()); |
10 | 1567 |
switch (bestSoFar.kind) { |
14444 | 1568 |
case ABSENT_MTH: |
1569 |
return new InapplicableSymbolError(currentResolutionContext); |
|
1570 |
case WRONG_MTH: |
|
1571 |
bestSoFar = new InapplicableSymbolsError(currentResolutionContext); |
|
1572 |
default: |
|
1573 |
return bestSoFar; |
|
10 | 1574 |
} |
1575 |
} |
|
1576 |
if (!isAccessible(env, site, sym)) { |
|
1577 |
return (bestSoFar.kind == ABSENT_MTH) |
|
1578 |
? new AccessError(env, site, sym) |
|
1579 |
: bestSoFar; |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1580 |
} |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
1581 |
return (bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS) |
10 | 1582 |
? sym |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1583 |
: mostSpecific(argtypes, sym, bestSoFar, env, site, useVarargs); |
10 | 1584 |
} |
1585 |
||
1586 |
/* Return the most specific of the two methods for a call, |
|
1587 |
* given that both are accessible and applicable. |
|
1588 |
* @param m1 A new candidate for most specific. |
|
1589 |
* @param m2 The previous most specific candidate. |
|
1590 |
* @param env The current environment. |
|
1591 |
* @param site The original type from where the selection |
|
1592 |
* takes place. |
|
1593 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1594 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1595 |
*/ |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1596 |
Symbol mostSpecific(List<Type> argtypes, Symbol m1, |
10 | 1597 |
Symbol m2, |
1598 |
Env<AttrContext> env, |
|
2511 | 1599 |
final Type site, |
10 | 1600 |
boolean useVarargs) { |
1601 |
switch (m2.kind) { |
|
1602 |
case MTH: |
|
1603 |
if (m1 == m2) return m1; |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1604 |
boolean m1SignatureMoreSpecific = |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1605 |
signatureMoreSpecific(argtypes, env, site, m1, m2, useVarargs); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1606 |
boolean m2SignatureMoreSpecific = |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1607 |
signatureMoreSpecific(argtypes, env, site, m2, m1, useVarargs); |
10 | 1608 |
if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) { |
7623 | 1609 |
Type mt1 = types.memberType(site, m1); |
1610 |
Type mt2 = types.memberType(site, m2); |
|
10 | 1611 |
if (!types.overrideEquivalent(mt1, mt2)) |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1612 |
return ambiguityError(m1, m2); |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1613 |
|
10 | 1614 |
// same signature; select (a) the non-bridge method, or |
1615 |
// (b) the one that overrides the other, or (c) the concrete |
|
1616 |
// one, or (d) merge both abstract signatures |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1617 |
if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE)) |
10 | 1618 |
return ((m1.flags() & BRIDGE) != 0) ? m2 : m1; |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1619 |
|
10 | 1620 |
// if one overrides or hides the other, use it |
1621 |
TypeSymbol m1Owner = (TypeSymbol)m1.owner; |
|
1622 |
TypeSymbol m2Owner = (TypeSymbol)m2.owner; |
|
1623 |
if (types.asSuper(m1Owner.type, m2Owner) != null && |
|
1624 |
((m1.owner.flags_field & INTERFACE) == 0 || |
|
1625 |
(m2.owner.flags_field & INTERFACE) != 0) && |
|
1626 |
m1.overrides(m2, m1Owner, types, false)) |
|
1627 |
return m1; |
|
1628 |
if (types.asSuper(m2Owner.type, m1Owner) != null && |
|
1629 |
((m2.owner.flags_field & INTERFACE) == 0 || |
|
1630 |
(m1.owner.flags_field & INTERFACE) != 0) && |
|
1631 |
m2.overrides(m1, m2Owner, types, false)) |
|
1632 |
return m2; |
|
1633 |
boolean m1Abstract = (m1.flags() & ABSTRACT) != 0; |
|
1634 |
boolean m2Abstract = (m2.flags() & ABSTRACT) != 0; |
|
1635 |
if (m1Abstract && !m2Abstract) return m2; |
|
1636 |
if (m2Abstract && !m1Abstract) return m1; |
|
1637 |
// both abstract or both concrete |
|
15038 | 1638 |
return ambiguityError(m1, m2); |
10 | 1639 |
} |
1640 |
if (m1SignatureMoreSpecific) return m1; |
|
1641 |
if (m2SignatureMoreSpecific) return m2; |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1642 |
return ambiguityError(m1, m2); |
10 | 1643 |
case AMBIGUOUS: |
24393
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1644 |
//compare m1 to ambiguous methods in m2 |
22161
d79fb23b5dca
8029569: internal javac cast exception when resolving varargs ambiguity
vromero
parents:
21718
diff
changeset
|
1645 |
AmbiguityError e = (AmbiguityError)m2.baseSymbol(); |
24393
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1646 |
boolean m1MoreSpecificThanAnyAmbiguous = true; |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1647 |
boolean allAmbiguousMoreSpecificThanM1 = true; |
15038 | 1648 |
for (Symbol s : e.ambiguousSyms) { |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1649 |
Symbol moreSpecific = mostSpecific(argtypes, m1, s, env, site, useVarargs); |
24393
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1650 |
m1MoreSpecificThanAnyAmbiguous &= moreSpecific == m1; |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1651 |
allAmbiguousMoreSpecificThanM1 &= moreSpecific == s; |
15038 | 1652 |
} |
24393
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1653 |
if (m1MoreSpecificThanAnyAmbiguous) |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1654 |
return m1; |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1655 |
//if m1 is more specific than some ambiguous methods, but other ambiguous methods are |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1656 |
//more specific than m1, add it as a new ambiguous method: |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1657 |
if (!allAmbiguousMoreSpecificThanM1) |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1658 |
e.addAmbiguousSymbol(m1); |
381ade32a034
8041663: Sensitive dependence on location of nested interface
jlahoda
parents:
24293
diff
changeset
|
1659 |
return e; |
10 | 1660 |
default: |
1661 |
throw new AssertionError(); |
|
1662 |
} |
|
1663 |
} |
|
7623 | 1664 |
//where |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1665 |
private boolean signatureMoreSpecific(List<Type> actuals, Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean useVarargs) { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1666 |
noteWarner.clear(); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1667 |
int maxLength = Math.max( |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1668 |
Math.max(m1.type.getParameterTypes().length(), actuals.length()), |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1669 |
m2.type.getParameterTypes().length()); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1670 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1671 |
try { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1672 |
currentResolutionContext = new MethodResolutionContext(); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1673 |
currentResolutionContext.step = prevResolutionContext.step; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1674 |
currentResolutionContext.methodCheck = |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1675 |
prevResolutionContext.methodCheck.mostSpecificCheck(actuals); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1676 |
Type mst = instantiate(env, site, m2, null, |
24293
0d889f759fac
8033718: Inference ignores capture variable as upper bound
dlsmith
parents:
24226
diff
changeset
|
1677 |
adjustArgs(types.cvarLowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1678 |
false, useVarargs, noteWarner); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1679 |
return mst != null && |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1680 |
!noteWarner.hasLint(Lint.LintCategory.UNCHECKED); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1681 |
} finally { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1682 |
currentResolutionContext = prevResolutionContext; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
1683 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1684 |
} |
19914 | 1685 |
|
1686 |
List<Type> adjustArgs(List<Type> args, Symbol msym, int length, boolean allowVarargs) { |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1687 |
if ((msym.flags() & VARARGS) != 0 && allowVarargs) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1688 |
Type varargsElem = types.elemtype(args.last()); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1689 |
if (varargsElem == null) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1690 |
Assert.error("Bad varargs = " + args.last() + " " + msym); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1691 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1692 |
List<Type> newArgs = args.reverse().tail.prepend(varargsElem).reverse(); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1693 |
while (newArgs.length() < length) { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1694 |
newArgs = newArgs.append(newArgs.last()); |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1695 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1696 |
return newArgs; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1697 |
} else { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15362
diff
changeset
|
1698 |
return args; |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
1699 |
} |
7623 | 1700 |
} |
1701 |
//where |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1702 |
Symbol ambiguityError(Symbol m1, Symbol m2) { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1703 |
if (((m1.flags() | m2.flags()) & CLASH) != 0) { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1704 |
return (m1.flags() & CLASH) == 0 ? m1 : m2; |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1705 |
} else { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1706 |
return new AmbiguityError(m1, m2); |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1707 |
} |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1708 |
} |
10 | 1709 |
|
14444 | 1710 |
Symbol findMethodInScope(Env<AttrContext> env, |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1711 |
Type site, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1712 |
Name name, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1713 |
List<Type> argtypes, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1714 |
List<Type> typeargtypes, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1715 |
Scope sc, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1716 |
Symbol bestSoFar, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1717 |
boolean allowBoxing, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1718 |
boolean useVarargs, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1719 |
boolean abstractok) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1720 |
for (Symbol s : sc.getSymbolsByName(name, new LookupFilter(abstractok))) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1721 |
bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1722 |
bestSoFar, allowBoxing, useVarargs); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1723 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1724 |
return bestSoFar; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1725 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1726 |
//where |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1727 |
class LookupFilter implements Filter<Symbol> { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1728 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1729 |
boolean abstractOk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1730 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1731 |
LookupFilter(boolean abstractOk) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1732 |
this.abstractOk = abstractOk; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1733 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1734 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1735 |
public boolean accepts(Symbol s) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1736 |
long flags = s.flags(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1737 |
return s.kind == MTH && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1738 |
(flags & SYNTHETIC) == 0 && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1739 |
(abstractOk || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1740 |
(flags & DEFAULT) != 0 || |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1741 |
(flags & ABSTRACT) == 0); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1742 |
} |
22163 | 1743 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1744 |
|
10 | 1745 |
/** Find best qualified method matching given name, type and value |
1746 |
* arguments. |
|
1747 |
* @param env The current environment. |
|
1748 |
* @param site The original type from where the selection |
|
1749 |
* takes place. |
|
1750 |
* @param name The method's name. |
|
1751 |
* @param argtypes The method's value arguments. |
|
1752 |
* @param typeargtypes The method's type arguments |
|
1753 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1754 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1755 |
*/ |
|
1756 |
Symbol findMethod(Env<AttrContext> env, |
|
1757 |
Type site, |
|
1758 |
Name name, |
|
1759 |
List<Type> argtypes, |
|
1760 |
List<Type> typeargtypes, |
|
1761 |
boolean allowBoxing, |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1762 |
boolean useVarargs) { |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
1763 |
Symbol bestSoFar = methodNotFound; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
1764 |
bestSoFar = findMethod(env, |
10 | 1765 |
site, |
1766 |
name, |
|
1767 |
argtypes, |
|
1768 |
typeargtypes, |
|
1769 |
site.tsym.type, |
|
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
1770 |
bestSoFar, |
10 | 1771 |
allowBoxing, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1772 |
useVarargs); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
1773 |
return bestSoFar; |
10 | 1774 |
} |
1775 |
// where |
|
1776 |
private Symbol findMethod(Env<AttrContext> env, |
|
1777 |
Type site, |
|
1778 |
Name name, |
|
1779 |
List<Type> argtypes, |
|
1780 |
List<Type> typeargtypes, |
|
1781 |
Type intype, |
|
1782 |
Symbol bestSoFar, |
|
1783 |
boolean allowBoxing, |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1784 |
boolean useVarargs) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1785 |
@SuppressWarnings({"unchecked","rawtypes"}) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1786 |
List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() }; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1787 |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1788 |
InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK; |
14045 | 1789 |
for (TypeSymbol s : superclasses(intype)) { |
14444 | 1790 |
bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1791 |
s.members(), bestSoFar, allowBoxing, useVarargs, true); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1792 |
if (name == names.init) return bestSoFar; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1793 |
iphase = (iphase == null) ? null : iphase.update(s, this); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1794 |
if (iphase != null) { |
14045 | 1795 |
for (Type itype : types.interfaces(s.type)) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1796 |
itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]); |
10 | 1797 |
} |
1798 |
} |
|
14045 | 1799 |
} |
1800 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1801 |
Symbol concrete = bestSoFar.kind.isValid() && |
14045 | 1802 |
(bestSoFar.flags() & ABSTRACT) == 0 ? |
1803 |
bestSoFar : methodNotFound; |
|
1804 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1805 |
for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) { |
14045 | 1806 |
//keep searching for abstract methods |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1807 |
for (Type itype : itypes[iphase2.ordinal()]) { |
14045 | 1808 |
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1809 |
if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1810 |
(itype.tsym.flags() & DEFAULT) == 0) continue; |
14444 | 1811 |
bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1812 |
itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, true); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1813 |
if (concrete != bestSoFar && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1814 |
concrete.kind.isValid() && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
1815 |
bestSoFar.kind.isValid() && |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1816 |
types.isSubSignature(concrete.type, bestSoFar.type)) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1817 |
//this is an hack - as javac does not do full membership checks |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1818 |
//most specific ends up comparing abstract methods that might have |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1819 |
//been implemented by some concrete method in a subclass and, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1820 |
//because of raw override, it is possible for an abstract method |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1821 |
//to be more specific than the concrete method - so we need |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1822 |
//to explicitly call that out (see CR 6178365) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1823 |
bestSoFar = concrete; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1824 |
} |
10 | 1825 |
} |
1826 |
} |
|
1827 |
return bestSoFar; |
|
1828 |
} |
|
1829 |
||
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1830 |
enum InterfaceLookupPhase { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1831 |
ABSTRACT_OK() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1832 |
@Override |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1833 |
InterfaceLookupPhase update(Symbol s, Resolve rs) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1834 |
//We should not look for abstract methods if receiver is a concrete class |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1835 |
//(as concrete classes are expected to implement all abstracts coming |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1836 |
//from superinterfaces) |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1837 |
if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1838 |
return this; |
23105
1d1ea26a10ae
8030855: Default methods should be visible under source previous to 8
vromero
parents:
22442
diff
changeset
|
1839 |
} else { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1840 |
return DEFAULT_OK; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1841 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1842 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1843 |
}, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1844 |
DEFAULT_OK() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1845 |
@Override |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1846 |
InterfaceLookupPhase update(Symbol s, Resolve rs) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1847 |
return this; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1848 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1849 |
}; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1850 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1851 |
abstract InterfaceLookupPhase update(Symbol s, Resolve rs); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1852 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
1853 |
|
14045 | 1854 |
/** |
1855 |
* Return an Iterable object to scan the superclasses of a given type. |
|
1856 |
* It's crucial that the scan is done lazily, as we don't want to accidentally |
|
1857 |
* access more supertypes than strictly needed (as this could trigger completion |
|
1858 |
* errors if some of the not-needed supertypes are missing/ill-formed). |
|
1859 |
*/ |
|
1860 |
Iterable<TypeSymbol> superclasses(final Type intype) { |
|
1861 |
return new Iterable<TypeSymbol>() { |
|
1862 |
public Iterator<TypeSymbol> iterator() { |
|
1863 |
return new Iterator<TypeSymbol>() { |
|
1864 |
||
1865 |
List<TypeSymbol> seen = List.nil(); |
|
14052 | 1866 |
TypeSymbol currentSym = symbolFor(intype); |
1867 |
TypeSymbol prevSym = null; |
|
14045 | 1868 |
|
1869 |
public boolean hasNext() { |
|
14052 | 1870 |
if (currentSym == syms.noSymbol) { |
1871 |
currentSym = symbolFor(types.supertype(prevSym.type)); |
|
1872 |
} |
|
14045 | 1873 |
return currentSym != null; |
1874 |
} |
|
1875 |
||
1876 |
public TypeSymbol next() { |
|
14052 | 1877 |
prevSym = currentSym; |
1878 |
currentSym = syms.noSymbol; |
|
1879 |
Assert.check(prevSym != null || prevSym != syms.noSymbol); |
|
14045 | 1880 |
return prevSym; |
1881 |
} |
|
1882 |
||
1883 |
public void remove() { |
|
14052 | 1884 |
throw new UnsupportedOperationException(); |
14045 | 1885 |
} |
1886 |
||
14052 | 1887 |
TypeSymbol symbolFor(Type t) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
1888 |
if (!t.hasTag(CLASS) && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
1889 |
!t.hasTag(TYPEVAR)) { |
14045 | 1890 |
return null; |
1891 |
} |
|
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
1892 |
t = types.skipTypeVars(t, false); |
14052 | 1893 |
if (seen.contains(t.tsym)) { |
14045 | 1894 |
//degenerate case in which we have a circular |
1895 |
//class hierarchy - because of ill-formed classfiles |
|
1896 |
return null; |
|
1897 |
} |
|
14052 | 1898 |
seen = seen.prepend(t.tsym); |
1899 |
return t.tsym; |
|
14045 | 1900 |
} |
1901 |
}; |
|
1902 |
} |
|
1903 |
}; |
|
1904 |
} |
|
1905 |
||
10 | 1906 |
/** Find unqualified method matching given name, type and value arguments. |
1907 |
* @param env The current environment. |
|
1908 |
* @param name The method's name. |
|
1909 |
* @param argtypes The method's value arguments. |
|
1910 |
* @param typeargtypes The method's type arguments. |
|
1911 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1912 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1913 |
*/ |
|
1914 |
Symbol findFun(Env<AttrContext> env, Name name, |
|
1915 |
List<Type> argtypes, List<Type> typeargtypes, |
|
1916 |
boolean allowBoxing, boolean useVarargs) { |
|
1917 |
Symbol bestSoFar = methodNotFound; |
|
1918 |
Env<AttrContext> env1 = env; |
|
1919 |
boolean staticOnly = false; |
|
1920 |
while (env1.outer != null) { |
|
1921 |
if (isStatic(env1)) staticOnly = true; |
|
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1922 |
Assert.check(env1.info.preferredTreeForDiagnostics == null); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1923 |
env1.info.preferredTreeForDiagnostics = env.tree; |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1924 |
try { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1925 |
Symbol sym = findMethod( |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1926 |
env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1927 |
allowBoxing, useVarargs); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1928 |
if (sym.exists()) { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1929 |
if (staticOnly && |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1930 |
sym.kind == MTH && |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1931 |
sym.owner.kind == TYP && |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1932 |
(sym.flags() & STATIC) == 0) return new StaticError(sym); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1933 |
else return sym; |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1934 |
} else { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1935 |
bestSoFar = bestOf(bestSoFar, sym); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1936 |
} |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1937 |
} finally { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
1938 |
env1.info.preferredTreeForDiagnostics = null; |
10 | 1939 |
} |
1940 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
1941 |
env1 = env1.outer; |
|
1942 |
} |
|
1943 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1944 |
Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1945 |
typeargtypes, allowBoxing, useVarargs); |
10 | 1946 |
if (sym.exists()) |
1947 |
return sym; |
|
1948 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1949 |
for (Symbol currentSym : env.toplevel.namedImportScope.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1950 |
Symbol origin = env.toplevel.namedImportScope.getOrigin(currentSym).owner; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1951 |
if (currentSym.kind == MTH) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1952 |
if (currentSym.owner.type != origin.type) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1953 |
currentSym = currentSym.clone(origin); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1954 |
if (!isAccessible(env, origin.type, currentSym)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1955 |
currentSym = new AccessError(env, origin.type, currentSym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1956 |
bestSoFar = selectBest(env, origin.type, |
10 | 1957 |
argtypes, typeargtypes, |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1958 |
currentSym, bestSoFar, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1959 |
allowBoxing, useVarargs); |
10 | 1960 |
} |
1961 |
} |
|
1962 |
if (bestSoFar.exists()) |
|
1963 |
return bestSoFar; |
|
1964 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1965 |
for (Symbol currentSym : env.toplevel.starImportScope.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1966 |
Symbol origin = env.toplevel.starImportScope.getOrigin(currentSym).owner; |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1967 |
if (currentSym.kind == MTH) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1968 |
if (currentSym.owner.type != origin.type) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1969 |
currentSym = currentSym.clone(origin); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1970 |
if (!isAccessible(env, origin.type, currentSym)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1971 |
currentSym = new AccessError(env, origin.type, currentSym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1972 |
bestSoFar = selectBest(env, origin.type, |
10 | 1973 |
argtypes, typeargtypes, |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
1974 |
currentSym, bestSoFar, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
1975 |
allowBoxing, useVarargs); |
10 | 1976 |
} |
1977 |
} |
|
1978 |
return bestSoFar; |
|
1979 |
} |
|
1980 |
||
1981 |
/** Load toplevel or member class with given fully qualified name and |
|
1982 |
* verify that it is accessible. |
|
1983 |
* @param env The current environment. |
|
1984 |
* @param name The fully qualified name of the class to be loaded. |
|
1985 |
*/ |
|
1986 |
Symbol loadClass(Env<AttrContext> env, Name name) { |
|
1987 |
try { |
|
36526 | 1988 |
ClassSymbol c = finder.loadClass(env.toplevel.modle, name); |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1989 |
return isAccessible(env, c) ? c : new AccessError(env, null, c); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24404
diff
changeset
|
1990 |
} catch (ClassFinder.BadClassFile err) { |
10 | 1991 |
throw err; |
1992 |
} catch (CompletionFailure ex) { |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1993 |
if (allowModules) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1994 |
Scope importScope = env.toplevel.namedImportScope; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1995 |
Symbol existing = importScope.findFirst(Convert.shortName(name), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1996 |
sym -> sym.kind == TYP && sym.flatName() == name); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1997 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1998 |
if (existing != null) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
1999 |
return new InvisibleSymbolError(env, true, existing); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2000 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2001 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2002 |
return lookupInvisibleSymbol(env, name, syms::getClass, (ms, n) -> { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2003 |
try { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2004 |
return finder.loadClass(ms, n); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2005 |
} catch (CompletionFailure cf) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2006 |
//ignore |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2007 |
return null; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2008 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2009 |
}, sym -> sym.kind == Kind.TYP, false, typeNotFound); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2010 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2011 |
return typeNotFound; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2012 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2013 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2014 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2015 |
Symbol lookupPackage(Env<AttrContext> env, Name name) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2016 |
PackageSymbol pack = syms.lookupPackage(env.toplevel.modle, name); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2017 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2018 |
pack.complete(); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2019 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2020 |
if (!pack.exists() && allowModules && isImportOnDemand(env, name)) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2021 |
Name nameAndDot = name.append('.', names.empty); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2022 |
boolean prefixOfKnown = |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2023 |
env.toplevel.modle.visiblePackages.values() |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2024 |
.stream() |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2025 |
.anyMatch(p -> p.fullname.startsWith(nameAndDot)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2026 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2027 |
return lookupInvisibleSymbol(env, name, syms::getPackage, syms::enterPackage, sym -> { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2028 |
sym.complete(); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2029 |
return sym.exists(); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2030 |
}, prefixOfKnown, pack); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2031 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2032 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2033 |
return pack; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2034 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2035 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2036 |
private boolean isImportOnDemand(Env<AttrContext> env, Name name) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2037 |
if (!env.tree.hasTag(IMPORT)) |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2038 |
return false; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2039 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2040 |
JCTree qualid = ((JCImport) env.tree).qualid; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2041 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2042 |
if (!qualid.hasTag(SELECT)) |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2043 |
return false; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2044 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2045 |
if (TreeInfo.name(qualid) != names.asterisk) |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2046 |
return false; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2047 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2048 |
return TreeInfo.fullName(((JCFieldAccess) qualid).selected) == name; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2049 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2050 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2051 |
private Symbol lookupInvisibleSymbol(Env<AttrContext> env, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2052 |
Name name, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2053 |
BiFunction<ModuleSymbol, Name, Symbol> get, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2054 |
BiFunction<ModuleSymbol, Name, Symbol> load, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2055 |
Predicate<Symbol> validate, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2056 |
boolean suppressError, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2057 |
Symbol defaultResult) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2058 |
//even if a class/package cannot be found in the current module and among packages in modules |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2059 |
//it depends on that are exported for any or this module, the class/package may exist internally |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2060 |
//in some of these modules, or may exist in a module on which this module does not depend. |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2061 |
//Provide better diagnostic in such cases by looking for the class in any module: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2062 |
Set<ModuleSymbol> recoverableModules = new HashSet<>(syms.getAllModules()); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2063 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2064 |
recoverableModules.remove(env.toplevel.modle); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2065 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2066 |
for (ModuleSymbol ms : recoverableModules) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2067 |
Symbol sym = get.apply(ms, name); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2068 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2069 |
//avoid overly eager completing classes from source-based modules, as those |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2070 |
//may not be completable with the current compiler settings: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2071 |
if (sym == null && (ms.sourceLocation == null)) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2072 |
if (ms.classLocation == null) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2073 |
ms = moduleFinder.findModule(ms); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2074 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2075 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2076 |
if (ms.kind != ERR) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2077 |
sym = load.apply(ms, name); |
36526 | 2078 |
} |
2079 |
} |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2080 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2081 |
if (sym == null) |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2082 |
continue; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2083 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2084 |
if (validate.test(sym)) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2085 |
return new InvisibleSymbolError(env, suppressError, sym); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2086 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2087 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2088 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2089 |
return defaultResult; |
10 | 2090 |
} |
2091 |
||
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2092 |
/** |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2093 |
* Find a type declared in a scope (not inherited). Return null |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2094 |
* if none is found. |
10 | 2095 |
* @param env The current environment. |
2096 |
* @param site The original type from where the selection takes |
|
2097 |
* place. |
|
2098 |
* @param name The type's name. |
|
2099 |
* @param c The class to search for the member type. This is |
|
2100 |
* always a superclass or implemented interface of |
|
2101 |
* site's class. |
|
2102 |
*/ |
|
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2103 |
Symbol findImmediateMemberType(Env<AttrContext> env, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2104 |
Type site, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2105 |
Name name, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2106 |
TypeSymbol c) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2107 |
for (Symbol sym : c.members().getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2108 |
if (sym.kind == TYP) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2109 |
return isAccessible(env, site, sym) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2110 |
? sym |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2111 |
: new AccessError(env, site, sym); |
10 | 2112 |
} |
2113 |
} |
|
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2114 |
return typeNotFound; |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2115 |
} |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2116 |
|
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2117 |
/** Find a member type inherited from a superclass or interface. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2118 |
* @param env The current environment. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2119 |
* @param site The original type from where the selection takes |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2120 |
* place. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2121 |
* @param name The type's name. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2122 |
* @param c The class to search for the member type. This is |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2123 |
* always a superclass or implemented interface of |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2124 |
* site's class. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2125 |
*/ |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2126 |
Symbol findInheritedMemberType(Env<AttrContext> env, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2127 |
Type site, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2128 |
Name name, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2129 |
TypeSymbol c) { |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2130 |
Symbol bestSoFar = typeNotFound; |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2131 |
Symbol sym; |
10 | 2132 |
Type st = types.supertype(c.type); |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
2133 |
if (st != null && st.hasTag(CLASS)) { |
10 | 2134 |
sym = findMemberType(env, site, name, st.tsym); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2135 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 2136 |
} |
2137 |
for (List<Type> l = types.interfaces(c.type); |
|
2138 |
bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); |
|
2139 |
l = l.tail) { |
|
2140 |
sym = findMemberType(env, site, name, l.head.tsym); |
|
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
2141 |
if (!bestSoFar.kind.isResolutionError() && |
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
2142 |
!sym.kind.isResolutionError() && |
10 | 2143 |
sym.owner != bestSoFar.owner) |
2144 |
bestSoFar = new AmbiguityError(bestSoFar, sym); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2145 |
else |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2146 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 2147 |
} |
2148 |
return bestSoFar; |
|
2149 |
} |
|
2150 |
||
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2151 |
/** Find qualified member type. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2152 |
* @param env The current environment. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2153 |
* @param site The original type from where the selection takes |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2154 |
* place. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2155 |
* @param name The type's name. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2156 |
* @param c The class to search for the member type. This is |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2157 |
* always a superclass or implemented interface of |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2158 |
* site's class. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2159 |
*/ |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2160 |
Symbol findMemberType(Env<AttrContext> env, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2161 |
Type site, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2162 |
Name name, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2163 |
TypeSymbol c) { |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2164 |
Symbol sym = findImmediateMemberType(env, site, name, c); |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2165 |
|
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2166 |
if (sym != typeNotFound) |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2167 |
return sym; |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2168 |
|
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2169 |
return findInheritedMemberType(env, site, name, c); |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2170 |
|
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2171 |
} |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2172 |
|
10 | 2173 |
/** Find a global type in given scope and load corresponding class. |
2174 |
* @param env The current environment. |
|
2175 |
* @param scope The scope in which to look for the type. |
|
2176 |
* @param name The type's name. |
|
2177 |
*/ |
|
2178 |
Symbol findGlobalType(Env<AttrContext> env, Scope scope, Name name) { |
|
2179 |
Symbol bestSoFar = typeNotFound; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2180 |
for (Symbol s : scope.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2181 |
Symbol sym = loadClass(env, s.flatName()); |
10 | 2182 |
if (bestSoFar.kind == TYP && sym.kind == TYP && |
2183 |
bestSoFar != sym) |
|
2184 |
return new AmbiguityError(bestSoFar, sym); |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2185 |
else |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2186 |
bestSoFar = bestOf(bestSoFar, sym); |
10 | 2187 |
} |
2188 |
return bestSoFar; |
|
2189 |
} |
|
2190 |
||
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2191 |
Symbol findTypeVar(Env<AttrContext> env, Name name, boolean staticOnly) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2192 |
for (Symbol sym : env.info.scope.getSymbolsByName(name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2193 |
if (sym.kind == TYP) { |
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2194 |
if (staticOnly && |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2195 |
sym.type.hasTag(TYPEVAR) && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2196 |
sym.owner.kind == TYP) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2197 |
return new StaticError(sym); |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2198 |
return sym; |
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2199 |
} |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2200 |
} |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2201 |
return typeNotFound; |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2202 |
} |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2203 |
|
10 | 2204 |
/** Find an unqualified type symbol. |
2205 |
* @param env The current environment. |
|
2206 |
* @param name The type's name. |
|
2207 |
*/ |
|
2208 |
Symbol findType(Env<AttrContext> env, Name name) { |
|
30404
952a476681b2
8078473: javac diamond finder crashes when used to build java.base module.
sadayapalam
parents:
29958
diff
changeset
|
2209 |
if (name == names.empty) |
952a476681b2
8078473: javac diamond finder crashes when used to build java.base module.
sadayapalam
parents:
29958
diff
changeset
|
2210 |
return typeNotFound; // do not allow inadvertent "lookup" of anonymous types |
10 | 2211 |
Symbol bestSoFar = typeNotFound; |
2212 |
Symbol sym; |
|
2213 |
boolean staticOnly = false; |
|
2214 |
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) { |
|
2215 |
if (isStatic(env1)) staticOnly = true; |
|
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2216 |
// First, look for a type variable and the first member type |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2217 |
final Symbol tyvar = findTypeVar(env1, name, staticOnly); |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2218 |
sym = findImmediateMemberType(env1, env1.enclClass.sym.type, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2219 |
name, env1.enclClass.sym); |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2220 |
|
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2221 |
// Return the type variable if we have it, and have no |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2222 |
// immediate member, OR the type variable is for a method. |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2223 |
if (tyvar != typeNotFound) { |
27386
784414cffd9a
8035259: javac, incorrect shadowing of classes vs type parameters
emc
parents:
27224
diff
changeset
|
2224 |
if (env.baseClause || sym == typeNotFound || |
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2225 |
(tyvar.kind == TYP && tyvar.exists() && |
27386
784414cffd9a
8035259: javac, incorrect shadowing of classes vs type parameters
emc
parents:
27224
diff
changeset
|
2226 |
tyvar.owner.kind == MTH)) { |
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2227 |
return tyvar; |
27386
784414cffd9a
8035259: javac, incorrect shadowing of classes vs type parameters
emc
parents:
27224
diff
changeset
|
2228 |
} |
10 | 2229 |
} |
2230 |
||
19652
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2231 |
// If the environment is a class def, finish up, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2232 |
// otherwise, do the entire findMemberType |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2233 |
if (sym == typeNotFound) |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2234 |
sym = findInheritedMemberType(env1, env1.enclClass.sym.type, |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2235 |
name, env1.enclClass.sym); |
1186c404a994
7118412: Shadowing of type-variables vs. member types
emc
parents:
19492
diff
changeset
|
2236 |
|
10 | 2237 |
if (staticOnly && sym.kind == TYP && |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
2238 |
sym.type.hasTag(CLASS) && |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
2239 |
sym.type.getEnclosingType().hasTag(CLASS) && |
10 | 2240 |
env1.enclClass.sym.type.isParameterized() && |
2241 |
sym.type.getEnclosingType().isParameterized()) |
|
2242 |
return new StaticError(sym); |
|
2243 |
else if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2244 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2245 |
|
2246 |
JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass; |
|
2247 |
if ((encl.sym.flags() & STATIC) != 0) |
|
2248 |
staticOnly = true; |
|
2249 |
} |
|
2250 |
||
10950 | 2251 |
if (!env.tree.hasTag(IMPORT)) { |
10 | 2252 |
sym = findGlobalType(env, env.toplevel.namedImportScope, name); |
2253 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2254 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2255 |
|
2256 |
sym = findGlobalType(env, env.toplevel.packge.members(), name); |
|
2257 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2258 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2259 |
|
2260 |
sym = findGlobalType(env, env.toplevel.starImportScope, name); |
|
2261 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2262 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2263 |
} |
2264 |
||
2265 |
return bestSoFar; |
|
2266 |
} |
|
2267 |
||
2268 |
/** Find an unqualified identifier which matches a specified kind set. |
|
2269 |
* @param env The current environment. |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14446
diff
changeset
|
2270 |
* @param name The identifier's name. |
10 | 2271 |
* @param kind Indicates the possible symbol kinds |
2272 |
* (a subset of VAL, TYP, PCK). |
|
2273 |
*/ |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2274 |
Symbol findIdent(Env<AttrContext> env, Name name, KindSelector kind) { |
10 | 2275 |
Symbol bestSoFar = typeNotFound; |
2276 |
Symbol sym; |
|
2277 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2278 |
if (kind.contains(KindSelector.VAL)) { |
10 | 2279 |
sym = findVar(env, name); |
2280 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2281 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2282 |
} |
2283 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2284 |
if (kind.contains(KindSelector.TYP)) { |
10 | 2285 |
sym = findType(env, name); |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2286 |
|
10 | 2287 |
if (sym.exists()) return sym; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2288 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2289 |
} |
2290 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2291 |
if (kind.contains(KindSelector.PCK)) |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2292 |
return lookupPackage(env, name); |
10 | 2293 |
else return bestSoFar; |
2294 |
} |
|
2295 |
||
2296 |
/** Find an identifier in a package which matches a specified kind set. |
|
2297 |
* @param env The current environment. |
|
2298 |
* @param name The identifier's name. |
|
2299 |
* @param kind Indicates the possible symbol kinds |
|
2300 |
* (a nonempty subset of TYP, PCK). |
|
2301 |
*/ |
|
2302 |
Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck, |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2303 |
Name name, KindSelector kind) { |
10 | 2304 |
Name fullname = TypeSymbol.formFullName(name, pck); |
2305 |
Symbol bestSoFar = typeNotFound; |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2306 |
Symbol pack = null; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2307 |
if (kind.contains(KindSelector.PCK)) { |
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
2308 |
pack = lookupPackage(env, fullname); |
10 | 2309 |
if (pack.exists()) return pack; |
2310 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2311 |
if (kind.contains(KindSelector.TYP)) { |
10 | 2312 |
Symbol sym = loadClass(env, fullname); |
2313 |
if (sym.exists()) { |
|
2314 |
// don't allow programs to use flatnames |
|
2315 |
if (name == sym.name) return sym; |
|
2316 |
} |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2317 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2318 |
} |
2319 |
return (pack != null) ? pack : bestSoFar; |
|
2320 |
} |
|
2321 |
||
2322 |
/** Find an identifier among the members of a given type `site'. |
|
2323 |
* @param env The current environment. |
|
2324 |
* @param site The type containing the symbol to be found. |
|
2325 |
* @param name The identifier's name. |
|
2326 |
* @param kind Indicates the possible symbol kinds |
|
2327 |
* (a subset of VAL, TYP). |
|
2328 |
*/ |
|
2329 |
Symbol findIdentInType(Env<AttrContext> env, Type site, |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2330 |
Name name, KindSelector kind) { |
10 | 2331 |
Symbol bestSoFar = typeNotFound; |
2332 |
Symbol sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2333 |
if (kind.contains(KindSelector.VAL)) { |
10 | 2334 |
sym = findField(env, site, name, site.tsym); |
2335 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2336 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2337 |
} |
2338 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2339 |
if (kind.contains(KindSelector.TYP)) { |
10 | 2340 |
sym = findMemberType(env, site, name, site.tsym); |
2341 |
if (sym.exists()) return sym; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2342 |
else bestSoFar = bestOf(bestSoFar, sym); |
10 | 2343 |
} |
2344 |
return bestSoFar; |
|
2345 |
} |
|
2346 |
||
2347 |
/* *************************************************************************** |
|
2348 |
* Access checking |
|
2349 |
* The following methods convert ResolveErrors to ErrorSymbols, issuing |
|
2350 |
* an error message in the process |
|
2351 |
****************************************************************************/ |
|
2352 |
||
2353 |
/** If `sym' is a bad symbol: report error and return errSymbol |
|
2354 |
* else pass through unchanged, |
|
2355 |
* additional arguments duplicate what has been used in trying to find the |
|
13844 | 2356 |
* symbol {@literal (--> flyweight pattern)}. This improves performance since we |
10 | 2357 |
* expect misses to happen frequently. |
2358 |
* |
|
2359 |
* @param sym The symbol that was found, or a ResolveError. |
|
2360 |
* @param pos The position to use for error reporting. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2361 |
* @param location The symbol the served as a context for this lookup |
10 | 2362 |
* @param site The original type from where the selection took place. |
2363 |
* @param name The symbol's name. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2364 |
* @param qualified Did we get here through a qualified expression resolution? |
10 | 2365 |
* @param argtypes The invocation's value arguments, |
2366 |
* if we looked for a method. |
|
2367 |
* @param typeargtypes The invocation's type arguments, |
|
2368 |
* if we looked for a method. |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2369 |
* @param logResolveHelper helper class used to log resolve errors |
10 | 2370 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2371 |
Symbol accessInternal(Symbol sym, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2372 |
DiagnosticPosition pos, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2373 |
Symbol location, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2374 |
Type site, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2375 |
Name name, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2376 |
boolean qualified, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2377 |
List<Type> argtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2378 |
List<Type> typeargtypes, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2379 |
LogResolveHelper logResolveHelper) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
2380 |
if (sym.kind.isResolutionError()) { |
24400
f05df7f58567
8037379: fix for JDK-8029569 doesn't cover all possible cases
vromero
parents:
24396
diff
changeset
|
2381 |
ResolveError errSym = (ResolveError)sym.baseSymbol(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2382 |
sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2383 |
argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2384 |
if (logResolveHelper.resolveDiagnosticNeeded(site, argtypes, typeargtypes)) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2385 |
logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2386 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2387 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2388 |
return sym; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2389 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2390 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2391 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2392 |
* Variant of the generalized access routine, to be used for generating method |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2393 |
* resolution diagnostics |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2394 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2395 |
Symbol accessMethod(Symbol sym, |
10 | 2396 |
DiagnosticPosition pos, |
8045 | 2397 |
Symbol location, |
10 | 2398 |
Type site, |
2399 |
Name name, |
|
2400 |
boolean qualified, |
|
2401 |
List<Type> argtypes, |
|
2402 |
List<Type> typeargtypes) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2403 |
return accessInternal(sym, pos, location, site, name, qualified, argtypes, typeargtypes, methodLogResolveHelper); |
10 | 2404 |
} |
2405 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2406 |
/** Same as original accessMethod(), but without location. |
8045 | 2407 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2408 |
Symbol accessMethod(Symbol sym, |
8045 | 2409 |
DiagnosticPosition pos, |
2410 |
Type site, |
|
2411 |
Name name, |
|
2412 |
boolean qualified, |
|
2413 |
List<Type> argtypes, |
|
2414 |
List<Type> typeargtypes) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2415 |
return accessMethod(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); |
8045 | 2416 |
} |
2417 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2418 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2419 |
* Variant of the generalized access routine, to be used for generating variable, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2420 |
* type resolution diagnostics |
8045 | 2421 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2422 |
Symbol accessBase(Symbol sym, |
8045 | 2423 |
DiagnosticPosition pos, |
2424 |
Symbol location, |
|
2425 |
Type site, |
|
2426 |
Name name, |
|
2427 |
boolean qualified) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2428 |
return accessInternal(sym, pos, location, site, name, qualified, List.<Type>nil(), null, basicLogResolveHelper); |
8045 | 2429 |
} |
2430 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2431 |
/** Same as original accessBase(), but without location. |
10 | 2432 |
*/ |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2433 |
Symbol accessBase(Symbol sym, |
10 | 2434 |
DiagnosticPosition pos, |
2435 |
Type site, |
|
2436 |
Name name, |
|
2437 |
boolean qualified) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2438 |
return accessBase(sym, pos, site.tsym, site, name, qualified); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2439 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2440 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2441 |
interface LogResolveHelper { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2442 |
boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2443 |
List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes); |
10 | 2444 |
} |
2445 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2446 |
LogResolveHelper basicLogResolveHelper = new LogResolveHelper() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2447 |
public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2448 |
return !site.isErroneous(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2449 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2450 |
public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2451 |
return argtypes; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2452 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2453 |
}; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2454 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2455 |
LogResolveHelper methodLogResolveHelper = new LogResolveHelper() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2456 |
public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2457 |
return !site.isErroneous() && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2458 |
!Type.isErroneous(argtypes) && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2459 |
(typeargtypes == null || !Type.isErroneous(typeargtypes)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2460 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2461 |
public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
2462 |
return argtypes.map(new ResolveDeferredRecoveryMap(AttrMode.SPECULATIVE, accessedSym, currentResolutionContext.step)); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2463 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2464 |
}; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2465 |
|
19914 | 2466 |
class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap { |
2467 |
||
2468 |
public ResolveDeferredRecoveryMap(AttrMode mode, Symbol msym, MethodResolutionPhase step) { |
|
2469 |
deferredAttr.super(mode, msym, step); |
|
2470 |
} |
|
2471 |
||
2472 |
@Override |
|
2473 |
protected Type typeOf(DeferredType dt) { |
|
2474 |
Type res = super.typeOf(dt); |
|
2475 |
if (!res.isErroneous()) { |
|
2476 |
switch (TreeInfo.skipParens(dt.tree).getTag()) { |
|
2477 |
case LAMBDA: |
|
2478 |
case REFERENCE: |
|
2479 |
return dt; |
|
2480 |
case CONDEXPR: |
|
2481 |
return res == Type.recoveryType ? |
|
2482 |
dt : res; |
|
2483 |
} |
|
2484 |
} |
|
2485 |
return res; |
|
2486 |
} |
|
2487 |
} |
|
2488 |
||
10 | 2489 |
/** Check that sym is not an abstract method. |
2490 |
*/ |
|
2491 |
void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
2492 |
if ((sym.flags() & ABSTRACT) != 0 && (sym.flags() & DEFAULT) == 0) |
10 | 2493 |
log.error(pos, "abstract.cant.be.accessed.directly", |
2494 |
kindName(sym), sym, sym.location()); |
|
2495 |
} |
|
2496 |
||
2497 |
/* *************************************************************************** |
|
2498 |
* Name resolution |
|
2499 |
* Naming conventions are as for symbol lookup |
|
2500 |
* Unlike the find... methods these methods will report access errors |
|
2501 |
****************************************************************************/ |
|
2502 |
||
2503 |
/** Resolve an unqualified (non-method) identifier. |
|
2504 |
* @param pos The position to use for error reporting. |
|
2505 |
* @param env The environment current at the identifier use. |
|
2506 |
* @param name The identifier's name. |
|
2507 |
* @param kind The set of admissible symbol kinds for the identifier. |
|
2508 |
*/ |
|
2509 |
Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env, |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2510 |
Name name, KindSelector kind) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2511 |
return accessBase( |
10 | 2512 |
findIdent(env, name, kind), |
2513 |
pos, env.enclClass.sym.type, name, false); |
|
2514 |
} |
|
2515 |
||
2516 |
/** Resolve an unqualified method identifier. |
|
2517 |
* @param pos The position to use for error reporting. |
|
2518 |
* @param env The environment current at the method invocation. |
|
2519 |
* @param name The identifier's name. |
|
2520 |
* @param argtypes The types of the invocation's value arguments. |
|
2521 |
* @param typeargtypes The types of the invocation's type arguments. |
|
2522 |
*/ |
|
2523 |
Symbol resolveMethod(DiagnosticPosition pos, |
|
2524 |
Env<AttrContext> env, |
|
2525 |
Name name, |
|
2526 |
List<Type> argtypes, |
|
2527 |
List<Type> typeargtypes) { |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2528 |
return lookupMethod(env, pos, env.enclClass.sym, resolveMethodCheck, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2529 |
new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2530 |
@Override |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
2531 |
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2532 |
return findFun(env, name, argtypes, typeargtypes, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2533 |
phase.isBoxingRequired(), |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2534 |
phase.isVarargsRequired()); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2535 |
}}); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2536 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2537 |
|
10 | 2538 |
/** Resolve a qualified method identifier |
2539 |
* @param pos The position to use for error reporting. |
|
2540 |
* @param env The environment current at the method invocation. |
|
2541 |
* @param site The type of the qualifying expression, in which |
|
2542 |
* identifier is searched. |
|
2543 |
* @param name The identifier's name. |
|
2544 |
* @param argtypes The types of the invocation's value arguments. |
|
2545 |
* @param typeargtypes The types of the invocation's type arguments. |
|
2546 |
*/ |
|
2547 |
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
2548 |
Type site, Name name, List<Type> argtypes, |
|
2549 |
List<Type> typeargtypes) { |
|
8045 | 2550 |
return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes); |
2551 |
} |
|
2552 |
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
2553 |
Symbol location, Type site, Name name, List<Type> argtypes, |
|
2554 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2555 |
return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2556 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2557 |
private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2558 |
DiagnosticPosition pos, Env<AttrContext> env, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2559 |
Symbol location, Type site, Name name, List<Type> argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2560 |
List<Type> typeargtypes) { |
14444 | 2561 |
return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) { |
2562 |
@Override |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
2563 |
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
14444 | 2564 |
return findMethod(env, site, name, argtypes, typeargtypes, |
2565 |
phase.isBoxingRequired(), |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
2566 |
phase.isVarargsRequired()); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2567 |
} |
14444 | 2568 |
@Override |
2569 |
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { |
|
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
2570 |
if (sym.kind.isResolutionError()) { |
14444 | 2571 |
sym = super.access(env, pos, location, sym); |
2572 |
} else if (allowMethodHandles) { |
|
2573 |
MethodSymbol msym = (MethodSymbol)sym; |
|
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
18378
diff
changeset
|
2574 |
if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) { |
14444 | 2575 |
return findPolymorphicSignatureInstance(env, sym, argtypes); |
2576 |
} |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2577 |
} |
14444 | 2578 |
return sym; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2579 |
} |
14444 | 2580 |
}); |
10 | 2581 |
} |
2582 |
||
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2583 |
/** Find or create an implicit method of exactly the given type (after erasure). |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2584 |
* Searches in a side table, not the main scope of the site. |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2585 |
* This emulates the lookup process required by JSR 292 in JVM. |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2586 |
* @param env Attribution environment |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
2587 |
* @param spMethod signature polymorphic method - i.e. MH.invokeExact |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
2588 |
* @param argtypes The required argument types |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2589 |
*/ |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
2590 |
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, |
14547 | 2591 |
final Symbol spMethod, |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
2592 |
List<Type> argtypes) { |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2593 |
Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
2594 |
(MethodSymbol)spMethod, currentResolutionContext, argtypes); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2595 |
for (Symbol sym : polymorphicSignatureScope.getSymbolsByName(spMethod.name)) { |
36995 | 2596 |
// Check that there is already a method symbol for the method |
2597 |
// type and owner |
|
2598 |
if (types.isSameType(mtype, sym.type) && |
|
2599 |
spMethod.owner == sym.owner) { |
|
2600 |
return sym; |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2601 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2602 |
} |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
2603 |
|
36995 | 2604 |
// Create the desired method |
2605 |
// Retain static modifier is to support invocations to |
|
2606 |
// MethodHandle.linkTo* methods |
|
2607 |
long flags = ABSTRACT | HYPOTHETICAL | |
|
2608 |
spMethod.flags() & (Flags.AccessFlags | Flags.STATIC); |
|
14547 | 2609 |
Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) { |
2610 |
@Override |
|
2611 |
public Symbol baseSymbol() { |
|
2612 |
return spMethod; |
|
2613 |
} |
|
2614 |
}; |
|
32949
7e0f345e64a8
8130506: javac AssertionError when invoking MethodHandle.invoke with lambda paramter
sadayapalam
parents:
32709
diff
changeset
|
2615 |
if (!mtype.isErroneous()) { // Cache only if kosher. |
7e0f345e64a8
8130506: javac AssertionError when invoking MethodHandle.invoke with lambda paramter
sadayapalam
parents:
32709
diff
changeset
|
2616 |
polymorphicSignatureScope.enter(msym); |
7e0f345e64a8
8130506: javac AssertionError when invoking MethodHandle.invoke with lambda paramter
sadayapalam
parents:
32709
diff
changeset
|
2617 |
} |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
2618 |
return msym; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2619 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
2620 |
|
10 | 2621 |
/** Resolve a qualified method identifier, throw a fatal error if not |
2622 |
* found. |
|
2623 |
* @param pos The position to use for error reporting. |
|
2624 |
* @param env The environment current at the method invocation. |
|
2625 |
* @param site The type of the qualifying expression, in which |
|
2626 |
* identifier is searched. |
|
2627 |
* @param name The identifier's name. |
|
2628 |
* @param argtypes The types of the invocation's value arguments. |
|
2629 |
* @param typeargtypes The types of the invocation's type arguments. |
|
2630 |
*/ |
|
2631 |
public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
2632 |
Type site, Name name, |
|
2633 |
List<Type> argtypes, |
|
2634 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2635 |
MethodResolutionContext resolveContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2636 |
resolveContext.internalResolution = true; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2637 |
Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2638 |
site, name, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2639 |
if (sym.kind == MTH) return (MethodSymbol)sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2640 |
else throw new FatalError( |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2641 |
diags.fragment("fatal.err.cant.locate.meth", |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2642 |
name)); |
10 | 2643 |
} |
2644 |
||
2645 |
/** Resolve constructor. |
|
2646 |
* @param pos The position to use for error reporting. |
|
2647 |
* @param env The environment current at the constructor invocation. |
|
2648 |
* @param site The type of class for which a constructor is searched. |
|
2649 |
* @param argtypes The types of the constructor invocation's value |
|
2650 |
* arguments. |
|
2651 |
* @param typeargtypes The types of the constructor invocation's type |
|
2652 |
* arguments. |
|
2653 |
*/ |
|
2654 |
Symbol resolveConstructor(DiagnosticPosition pos, |
|
2655 |
Env<AttrContext> env, |
|
2656 |
Type site, |
|
2657 |
List<Type> argtypes, |
|
2658 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2659 |
return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2660 |
} |
14444 | 2661 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2662 |
private Symbol resolveConstructor(MethodResolutionContext resolveContext, |
14444 | 2663 |
final DiagnosticPosition pos, |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2664 |
Env<AttrContext> env, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2665 |
Type site, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2666 |
List<Type> argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2667 |
List<Type> typeargtypes) { |
14444 | 2668 |
return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { |
2669 |
@Override |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
2670 |
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
14444 | 2671 |
return findConstructor(pos, env, site, argtypes, typeargtypes, |
2672 |
phase.isBoxingRequired(), |
|
2673 |
phase.isVarargsRequired()); |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2674 |
} |
14444 | 2675 |
}); |
2676 |
} |
|
2677 |
||
2678 |
/** Resolve a constructor, throw a fatal error if not found. |
|
2679 |
* @param pos The position to use for error reporting. |
|
2680 |
* @param env The environment current at the method invocation. |
|
2681 |
* @param site The type to be constructed. |
|
2682 |
* @param argtypes The types of the invocation's value arguments. |
|
2683 |
* @param typeargtypes The types of the invocation's type arguments. |
|
2684 |
*/ |
|
2685 |
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env, |
|
2686 |
Type site, |
|
2687 |
List<Type> argtypes, |
|
2688 |
List<Type> typeargtypes) { |
|
2689 |
MethodResolutionContext resolveContext = new MethodResolutionContext(); |
|
2690 |
resolveContext.internalResolution = true; |
|
2691 |
Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes); |
|
2692 |
if (sym.kind == MTH) return (MethodSymbol)sym; |
|
2693 |
else throw new FatalError( |
|
2694 |
diags.fragment("fatal.err.cant.locate.ctor", site)); |
|
2695 |
} |
|
2696 |
||
2697 |
Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env, |
|
2698 |
Type site, List<Type> argtypes, |
|
2699 |
List<Type> typeargtypes, |
|
2700 |
boolean allowBoxing, |
|
2701 |
boolean useVarargs) { |
|
2702 |
Symbol sym = findMethod(env, site, |
|
2703 |
names.init, argtypes, |
|
2704 |
typeargtypes, allowBoxing, |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
2705 |
useVarargs); |
14444 | 2706 |
chk.checkDeprecated(pos, env.info.scope.owner, sym); |
2707 |
return sym; |
|
10 | 2708 |
} |
2709 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2710 |
/** Resolve constructor using diamond inference. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2711 |
* @param pos The position to use for error reporting. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2712 |
* @param env The environment current at the constructor invocation. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2713 |
* @param site The type of class for which a constructor is searched. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2714 |
* The scope of this class has been touched in attribution. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2715 |
* @param argtypes The types of the constructor invocation's value |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2716 |
* arguments. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2717 |
* @param typeargtypes The types of the constructor invocation's type |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2718 |
* arguments. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2719 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2720 |
Symbol resolveDiamond(DiagnosticPosition pos, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2721 |
Env<AttrContext> env, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2722 |
Type site, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2723 |
List<Type> argtypes, |
6344
f190fb7fdd2d
6975275: diamond implementation needs some cleanup
mcimadamore
parents:
6151
diff
changeset
|
2724 |
List<Type> typeargtypes) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2725 |
return lookupMethod(env, pos, site.tsym, resolveMethodCheck, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2726 |
new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2727 |
@Override |
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
2728 |
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2729 |
return findDiamond(env, site, argtypes, typeargtypes, |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2730 |
phase.isBoxingRequired(), |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2731 |
phase.isVarargsRequired()); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2732 |
} |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2733 |
@Override |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2734 |
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
2735 |
if (sym.kind.isResolutionError()) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2736 |
if (sym.kind != WRONG_MTH && |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
2737 |
sym.kind != WRONG_MTHS) { |
19917
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2738 |
sym = super.access(env, pos, location, sym); |
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2739 |
} else { |
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2740 |
final JCDiagnostic details = sym.kind == WRONG_MTH ? |
24400
f05df7f58567
8037379: fix for JDK-8029569 doesn't cover all possible cases
vromero
parents:
24396
diff
changeset
|
2741 |
((InapplicableSymbolError)sym.baseSymbol()).errCandidate().snd : |
19917
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2742 |
null; |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
2743 |
sym = new DiamondError(sym, currentResolutionContext); |
19917
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2744 |
sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); |
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2745 |
env.info.pendingResolutionPhase = currentResolutionContext.step; |
ebb957ba7b07
8023545: Misleading error message when using diamond operator with private constructor
vromero
parents:
19914
diff
changeset
|
2746 |
} |
14444 | 2747 |
} |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2748 |
return sym; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
2749 |
}}); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2750 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
2751 |
|
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2752 |
/** This method scans all the constructor symbol in a given class scope - |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2753 |
* assuming that the original scope contains a constructor of the kind: |
13844 | 2754 |
* {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo, |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2755 |
* a method check is executed against the modified constructor type: |
13844 | 2756 |
* {@code <X,Y>Foo<X,Y>(X x, Y y)}. This is crucial in order to enable diamond |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2757 |
* inference. The inferred return type of the synthetic constructor IS |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2758 |
* the inferred type for the diamond operator. |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2759 |
*/ |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2760 |
private Symbol findDiamond(Env<AttrContext> env, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2761 |
Type site, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2762 |
List<Type> argtypes, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2763 |
List<Type> typeargtypes, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2764 |
boolean allowBoxing, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2765 |
boolean useVarargs) { |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2766 |
Symbol bestSoFar = methodNotFound; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2767 |
TypeSymbol tsym = site.tsym.isInterface() ? syms.objectType.tsym : site.tsym; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
2768 |
for (final Symbol sym : tsym.members().getSymbolsByName(names.init)) { |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2769 |
//- System.out.println(" e " + e.sym); |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2770 |
if (sym.kind == MTH && |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2771 |
(sym.flags_field & SYNTHETIC) == 0) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
2772 |
List<Type> oldParams = sym.type.hasTag(FORALL) ? |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2773 |
((ForAll)sym.type).tvars : |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2774 |
List.<Type>nil(); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2775 |
Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams), |
24396 | 2776 |
types.createMethodTypeWithReturn(sym.type.asMethodType(), site)); |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2777 |
MethodSymbol newConstr = new MethodSymbol(sym.flags(), names.init, constrType, site.tsym) { |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2778 |
@Override |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2779 |
public Symbol baseSymbol() { |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2780 |
return sym; |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2781 |
} |
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2782 |
}; |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2783 |
bestSoFar = selectBest(env, site, argtypes, typeargtypes, |
14051
9097cec96212
7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents:
14048
diff
changeset
|
2784 |
newConstr, |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2785 |
bestSoFar, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2786 |
allowBoxing, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
2787 |
useVarargs); |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2788 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2789 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2790 |
return bestSoFar; |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2791 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2792 |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2793 |
Symbol getMemberReference(DiagnosticPosition pos, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2794 |
Env<AttrContext> env, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2795 |
JCMemberReference referenceTree, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2796 |
Type site, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2797 |
Name name) { |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2798 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2799 |
site = types.capture(site); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2800 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2801 |
ReferenceLookupHelper lookupHelper = makeReferenceLookupHelper( |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2802 |
referenceTree, site, name, List.<Type>nil(), null, VARARITY); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2803 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2804 |
Env<AttrContext> newEnv = env.dup(env.tree, env.info.dup()); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2805 |
Symbol sym = lookupMethod(newEnv, env.tree.pos(), site.tsym, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2806 |
nilMethodCheck, lookupHelper); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2807 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2808 |
env.info.pendingResolutionPhase = newEnv.info.pendingResolutionPhase; |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2809 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2810 |
return sym; |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2811 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2812 |
|
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2813 |
ReferenceLookupHelper makeReferenceLookupHelper(JCMemberReference referenceTree, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2814 |
Type site, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2815 |
Name name, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2816 |
List<Type> argtypes, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2817 |
List<Type> typeargtypes, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2818 |
MethodResolutionPhase maxPhase) { |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2819 |
if (!name.equals(names.init)) { |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2820 |
//method reference |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2821 |
return new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2822 |
} else if (site.hasTag(ARRAY)) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2823 |
//array constructor reference |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2824 |
return new ArrayConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase); |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2825 |
} else { |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2826 |
//class constructor reference |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2827 |
return new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase); |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2828 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2829 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2830 |
|
10 | 2831 |
/** |
14444 | 2832 |
* Resolution of member references is typically done as a single |
2833 |
* overload resolution step, where the argument types A are inferred from |
|
2834 |
* the target functional descriptor. |
|
2835 |
* |
|
2836 |
* If the member reference is a method reference with a type qualifier, |
|
2837 |
* a two-step lookup process is performed. The first step uses the |
|
2838 |
* expected argument list A, while the second step discards the first |
|
2839 |
* type from A (which is treated as a receiver type). |
|
2840 |
* |
|
2841 |
* There are two cases in which inference is performed: (i) if the member |
|
2842 |
* reference is a constructor reference and the qualifier type is raw - in |
|
2843 |
* which case diamond inference is used to infer a parameterization for the |
|
2844 |
* type qualifier; (ii) if the member reference is an unbound reference |
|
2845 |
* where the type qualifier is raw - in that case, during the unbound lookup |
|
2846 |
* the receiver argument type is used to infer an instantiation for the raw |
|
2847 |
* qualifier type. |
|
2848 |
* |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2849 |
* When a multi-step resolution process is exploited, the process of picking |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2850 |
* the resulting symbol is delegated to an helper class {@link com.sun.tools.javac.comp.Resolve.ReferenceChooser}. |
14444 | 2851 |
* |
2852 |
* This routine returns a pair (T,S), where S is the member reference symbol, |
|
2853 |
* and T is the type of the class in which S is defined. This is necessary as |
|
2854 |
* the type T might be dynamically inferred (i.e. if constructor reference |
|
2855 |
* has a raw qualifier). |
|
2856 |
*/ |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2857 |
Pair<Symbol, ReferenceLookupHelper> resolveMemberReference(Env<AttrContext> env, |
14444 | 2858 |
JCMemberReference referenceTree, |
2859 |
Type site, |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2860 |
Name name, |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2861 |
List<Type> argtypes, |
14444 | 2862 |
List<Type> typeargtypes, |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
2863 |
MethodCheck methodCheck, |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2864 |
InferenceContext inferenceContext, |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2865 |
ReferenceChooser referenceChooser) { |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
2866 |
|
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
2867 |
//step 1 - bound lookup |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2868 |
ReferenceLookupHelper boundLookupHelper = makeReferenceLookupHelper( |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2869 |
referenceTree, site, name, argtypes, typeargtypes, VARARITY); |
14444 | 2870 |
Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup()); |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2871 |
MethodResolutionContext boundSearchResolveContext = new MethodResolutionContext(); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2872 |
boundSearchResolveContext.methodCheck = methodCheck; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2873 |
Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2874 |
site.tsym, boundSearchResolveContext, boundLookupHelper); |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2875 |
ReferenceLookupResult boundRes = new ReferenceLookupResult(boundSym, boundSearchResolveContext); |
14444 | 2876 |
|
2877 |
//step 2 - unbound lookup |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2878 |
Symbol unboundSym = methodNotFound; |
14444 | 2879 |
Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup()); |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2880 |
ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup(inferenceContext); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2881 |
ReferenceLookupResult unboundRes = referenceNotFound; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2882 |
if (unboundLookupHelper != null) { |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2883 |
MethodResolutionContext unboundSearchResolveContext = |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2884 |
new MethodResolutionContext(); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2885 |
unboundSearchResolveContext.methodCheck = methodCheck; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2886 |
unboundSym = lookupMethod(unboundEnv, env.tree.pos(), |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2887 |
site.tsym, unboundSearchResolveContext, unboundLookupHelper); |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2888 |
unboundRes = new ReferenceLookupResult(unboundSym, unboundSearchResolveContext); |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2889 |
} |
14444 | 2890 |
|
2891 |
//merge results |
|
2892 |
Pair<Symbol, ReferenceLookupHelper> res; |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2893 |
Symbol bestSym = referenceChooser.result(boundRes, unboundRes); |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2894 |
res = new Pair<>(bestSym, |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2895 |
bestSym == unboundSym ? unboundLookupHelper : boundLookupHelper); |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2896 |
env.info.pendingResolutionPhase = bestSym == unboundSym ? |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2897 |
unboundEnv.info.pendingResolutionPhase : |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2898 |
boundEnv.info.pendingResolutionPhase; |
14444 | 2899 |
|
2900 |
return res; |
|
2901 |
} |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2902 |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2903 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2904 |
* This class is used to represent a method reference lookup result. It keeps track of two |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2905 |
* things: (i) the symbol found during a method reference lookup and (ii) the static kind |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2906 |
* of the lookup (see {@link com.sun.tools.javac.comp.Resolve.ReferenceLookupResult.StaticKind}). |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2907 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2908 |
static class ReferenceLookupResult { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2909 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2910 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2911 |
* Static kind associated with a method reference lookup. Erroneous lookups end up with |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2912 |
* the UNDEFINED kind; successful lookups will end up with either STATIC, NON_STATIC, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2913 |
* depending on whether all applicable candidates are static or non-static methods, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2914 |
* respectively. If a successful lookup has both static and non-static applicable methods, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2915 |
* its kind is set to BOTH. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2916 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2917 |
enum StaticKind { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2918 |
STATIC, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2919 |
NON_STATIC, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2920 |
BOTH, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2921 |
UNDEFINED; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2922 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2923 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2924 |
* Retrieve the static kind associated with a given (method) symbol. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2925 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2926 |
static StaticKind from(Symbol s) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2927 |
return s.isStatic() ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2928 |
STATIC : NON_STATIC; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2929 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2930 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2931 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2932 |
* Merge two static kinds together. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2933 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2934 |
static StaticKind reduce(StaticKind sk1, StaticKind sk2) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2935 |
if (sk1 == UNDEFINED) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2936 |
return sk2; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2937 |
} else if (sk2 == UNDEFINED) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2938 |
return sk1; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2939 |
} else { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2940 |
return sk1 == sk2 ? sk1 : BOTH; |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2941 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2942 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
2943 |
} |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2944 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2945 |
/** The static kind. */ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2946 |
StaticKind staticKind; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2947 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2948 |
/** The lookup result. */ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2949 |
Symbol sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2950 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2951 |
ReferenceLookupResult(Symbol sym, MethodResolutionContext resolutionContext) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2952 |
this.staticKind = staticKind(sym, resolutionContext); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2953 |
this.sym = sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2954 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2955 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2956 |
private StaticKind staticKind(Symbol sym, MethodResolutionContext resolutionContext) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2957 |
switch (sym.kind) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2958 |
case MTH: |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2959 |
case AMBIGUOUS: |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2960 |
return resolutionContext.candidates.stream() |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2961 |
.filter(c -> c.isApplicable() && c.step == resolutionContext.step) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2962 |
.map(c -> StaticKind.from(c.sym)) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2963 |
.reduce(StaticKind::reduce) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2964 |
.orElse(StaticKind.UNDEFINED); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2965 |
default: |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2966 |
return StaticKind.UNDEFINED; |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2967 |
} |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2968 |
} |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2969 |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2970 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2971 |
* Does this result corresponds to a successful lookup (i.e. one where a method has been found?) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2972 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2973 |
boolean isSuccess() { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2974 |
return staticKind != StaticKind.UNDEFINED; |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15706
diff
changeset
|
2975 |
} |
14444 | 2976 |
|
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2977 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2978 |
* Does this result have given static kind? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2979 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2980 |
boolean hasKind(StaticKind sk) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2981 |
return this.staticKind == sk; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2982 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2983 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2984 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2985 |
* Error recovery helper: can this lookup result be ignored (for the purpose of returning |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2986 |
* some 'better' result) ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2987 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2988 |
boolean canIgnore() { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2989 |
switch (sym.kind) { |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2990 |
case ABSENT_MTH: |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2991 |
return true; |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2992 |
case WRONG_MTH: |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2993 |
InapplicableSymbolError errSym = |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2994 |
(InapplicableSymbolError)sym.baseSymbol(); |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2995 |
return new Template(MethodCheckDiag.ARITY_MISMATCH.regex()) |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2996 |
.matches(errSym.errCandidate().snd); |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2997 |
case WRONG_MTHS: |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
2998 |
InapplicableSymbolsError errSyms = |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
2999 |
(InapplicableSymbolsError)sym.baseSymbol(); |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3000 |
return errSyms.filterCandidates(errSyms.mapCandidates()).isEmpty(); |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3001 |
default: |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3002 |
return false; |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3003 |
} |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3004 |
} |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3005 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3006 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3007 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3008 |
* This abstract class embodies the logic that converts one (bound lookup) or two (unbound lookup) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3009 |
* {@code ReferenceLookupResult} objects into a (@code Symbol), which is then regarded as the |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3010 |
* result of method reference resolution. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3011 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3012 |
abstract class ReferenceChooser { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3013 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3014 |
* Generate a result from a pair of lookup result objects. This method delegates to the |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3015 |
* appropriate result generation routine. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3016 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3017 |
Symbol result(ReferenceLookupResult boundRes, ReferenceLookupResult unboundRes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3018 |
return unboundRes != referenceNotFound ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3019 |
unboundResult(boundRes, unboundRes) : |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3020 |
boundResult(boundRes); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3021 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3022 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3023 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3024 |
* Generate a symbol from a given bound lookup result. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3025 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3026 |
abstract Symbol boundResult(ReferenceLookupResult boundRes); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3027 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3028 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3029 |
* Generate a symbol from a pair of bound/unbound lookup results. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3030 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3031 |
abstract Symbol unboundResult(ReferenceLookupResult boundRes, ReferenceLookupResult unboundRes); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3032 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3033 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3034 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3035 |
* This chooser implements the selection strategy used during a full lookup; this logic |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3036 |
* is described in JLS SE 8 (15.3.2). |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3037 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3038 |
ReferenceChooser basicReferenceChooser = new ReferenceChooser() { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3039 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3040 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3041 |
Symbol boundResult(ReferenceLookupResult boundRes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3042 |
return !boundRes.isSuccess() || boundRes.hasKind(StaticKind.NON_STATIC) ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3043 |
boundRes.sym : //the search produces a non-static method |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3044 |
new BadMethodReferenceError(boundRes.sym, false); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3045 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3046 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3047 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3048 |
Symbol unboundResult(ReferenceLookupResult boundRes, ReferenceLookupResult unboundRes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3049 |
if (boundRes.hasKind(StaticKind.STATIC) && |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3050 |
(!unboundRes.isSuccess() || unboundRes.hasKind(StaticKind.STATIC))) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3051 |
//the first search produces a static method and no non-static method is applicable |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3052 |
//during the second search |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3053 |
return boundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3054 |
} else if (unboundRes.hasKind(StaticKind.NON_STATIC) && |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3055 |
(!boundRes.isSuccess() || boundRes.hasKind(StaticKind.NON_STATIC))) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3056 |
//the second search produces a non-static method and no static method is applicable |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3057 |
//during the first search |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3058 |
return unboundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3059 |
} else if (boundRes.isSuccess() && unboundRes.isSuccess()) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3060 |
//both searches produce some result; ambiguity (error recovery) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3061 |
return ambiguityError(boundRes.sym, unboundRes.sym); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3062 |
} else if (boundRes.isSuccess() || unboundRes.isSuccess()) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3063 |
//Both searches failed to produce a result with correct staticness (i.e. first search |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3064 |
//produces an non-static method). Alternatively, a given search produced a result |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3065 |
//with the right staticness, but the other search has applicable methods with wrong |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3066 |
//staticness (error recovery) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3067 |
return new BadMethodReferenceError(boundRes.isSuccess() ? boundRes.sym : unboundRes.sym, true); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3068 |
} else { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3069 |
//both searches fail to produce a result - pick 'better' error using heuristics (error recovery) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3070 |
return (boundRes.canIgnore() && !unboundRes.canIgnore()) ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3071 |
unboundRes.sym : boundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3072 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3073 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3074 |
}; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3075 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3076 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3077 |
* This chooser implements the selection strategy used during an arity-based lookup; this logic |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3078 |
* is described in JLS SE 8 (15.12.2.1). |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3079 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3080 |
ReferenceChooser structuralReferenceChooser = new ReferenceChooser() { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3081 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3082 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3083 |
Symbol boundResult(ReferenceLookupResult boundRes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3084 |
return (!boundRes.isSuccess() || !boundRes.hasKind(StaticKind.STATIC)) ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3085 |
boundRes.sym : //the search has at least one applicable non-static method |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3086 |
new BadMethodReferenceError(boundRes.sym, false); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3087 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3088 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3089 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3090 |
Symbol unboundResult(ReferenceLookupResult boundRes, ReferenceLookupResult unboundRes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3091 |
if (boundRes.isSuccess() && !boundRes.hasKind(StaticKind.NON_STATIC)) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3092 |
//the first serach has at least one applicable static method |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3093 |
return boundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3094 |
} else if (unboundRes.isSuccess() && !unboundRes.hasKind(StaticKind.STATIC)) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3095 |
//the second search has at least one applicable non-static method |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3096 |
return unboundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3097 |
} else if (boundRes.isSuccess() || unboundRes.isSuccess()) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3098 |
//either the first search produces a non-static method, or second search produces |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3099 |
//a non-static method (error recovery) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3100 |
return new BadMethodReferenceError(boundRes.isSuccess() ? boundRes.sym : unboundRes.sym, true); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3101 |
} else { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3102 |
//both searches fail to produce a result - pick 'better' error using heuristics (error recovery) |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3103 |
return (boundRes.canIgnore() && !unboundRes.canIgnore()) ? |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3104 |
unboundRes.sym : boundRes.sym; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3105 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3106 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3107 |
}; |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3108 |
|
14444 | 3109 |
/** |
3110 |
* Helper for defining custom method-like lookup logic; a lookup helper |
|
3111 |
* provides hooks for (i) the actual lookup logic and (ii) accessing the |
|
3112 |
* lookup result (this step might result in compiler diagnostics to be generated) |
|
3113 |
*/ |
|
3114 |
abstract class LookupHelper { |
|
3115 |
||
3116 |
/** name of the symbol to lookup */ |
|
3117 |
Name name; |
|
3118 |
||
3119 |
/** location in which the lookup takes place */ |
|
3120 |
Type site; |
|
3121 |
||
3122 |
/** actual types used during the lookup */ |
|
3123 |
List<Type> argtypes; |
|
3124 |
||
3125 |
/** type arguments used during the lookup */ |
|
3126 |
List<Type> typeargtypes; |
|
3127 |
||
3128 |
/** Max overload resolution phase handled by this helper */ |
|
3129 |
MethodResolutionPhase maxPhase; |
|
3130 |
||
3131 |
LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
|
3132 |
this.name = name; |
|
3133 |
this.site = site; |
|
3134 |
this.argtypes = argtypes; |
|
3135 |
this.typeargtypes = typeargtypes; |
|
3136 |
this.maxPhase = maxPhase; |
|
3137 |
} |
|
3138 |
||
3139 |
/** |
|
3140 |
* Should lookup stop at given phase with given result |
|
3141 |
*/ |
|
26533
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
3142 |
final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) { |
14444 | 3143 |
return phase.ordinal() > maxPhase.ordinal() || |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3144 |
!sym.kind.isResolutionError() || sym.kind == AMBIGUOUS; |
14444 | 3145 |
} |
3146 |
||
3147 |
/** |
|
3148 |
* Search for a symbol under a given overload resolution phase - this method |
|
3149 |
* is usually called several times, once per each overload resolution phase |
|
3150 |
*/ |
|
3151 |
abstract Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase); |
|
3152 |
||
3153 |
/** |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3154 |
* Dump overload resolution info |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3155 |
*/ |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3156 |
void debug(DiagnosticPosition pos, Symbol sym) { |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3157 |
//do nothing |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3158 |
} |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3159 |
|
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3160 |
/** |
14444 | 3161 |
* Validate the result of the lookup |
3162 |
*/ |
|
3163 |
abstract Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym); |
|
3164 |
} |
|
3165 |
||
3166 |
abstract class BasicLookupHelper extends LookupHelper { |
|
3167 |
||
3168 |
BasicLookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) { |
|
17804
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
17582
diff
changeset
|
3169 |
this(name, site, argtypes, typeargtypes, MethodResolutionPhase.VARARITY); |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
17582
diff
changeset
|
3170 |
} |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
17582
diff
changeset
|
3171 |
|
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
17582
diff
changeset
|
3172 |
BasicLookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
6bed8a263318
8014649: Regression: bug in Resolve.resolveOperator
mcimadamore
parents:
17582
diff
changeset
|
3173 |
super(name, site, argtypes, typeargtypes, maxPhase); |
14444 | 3174 |
} |
3175 |
||
3176 |
@Override |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3177 |
final Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3178 |
Symbol sym = doLookup(env, phase); |
15038 | 3179 |
if (sym.kind == AMBIGUOUS) { |
22161
d79fb23b5dca
8029569: internal javac cast exception when resolving varargs ambiguity
vromero
parents:
21718
diff
changeset
|
3180 |
AmbiguityError a_err = (AmbiguityError)sym.baseSymbol(); |
15038 | 3181 |
sym = a_err.mergeAbstracts(site); |
3182 |
} |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3183 |
return sym; |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3184 |
} |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3185 |
|
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3186 |
abstract Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3187 |
|
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3188 |
@Override |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3189 |
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3190 |
if (sym.kind.isResolutionError()) { |
14444 | 3191 |
//if nothing is found return the 'first' error |
3192 |
sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes); |
|
3193 |
} |
|
3194 |
return sym; |
|
3195 |
} |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3196 |
|
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3197 |
@Override |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3198 |
void debug(DiagnosticPosition pos, Symbol sym) { |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3199 |
reportVerboseResolutionDiagnostic(pos, name, site, argtypes, typeargtypes, sym); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3200 |
} |
14444 | 3201 |
} |
3202 |
||
3203 |
/** |
|
3204 |
* Helper class for member reference lookup. A reference lookup helper |
|
3205 |
* defines the basic logic for member reference lookup; a method gives |
|
3206 |
* access to an 'unbound' helper used to perform an unbound member |
|
3207 |
* reference lookup. |
|
3208 |
*/ |
|
3209 |
abstract class ReferenceLookupHelper extends LookupHelper { |
|
3210 |
||
3211 |
/** The member reference tree */ |
|
3212 |
JCMemberReference referenceTree; |
|
3213 |
||
3214 |
ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, |
|
3215 |
List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
|
3216 |
super(name, site, argtypes, typeargtypes, maxPhase); |
|
3217 |
this.referenceTree = referenceTree; |
|
3218 |
} |
|
3219 |
||
3220 |
/** |
|
3221 |
* Returns an unbound version of this lookup helper. By default, this |
|
3222 |
* method returns an dummy lookup helper. |
|
3223 |
*/ |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
3224 |
ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) { |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3225 |
return null; |
14444 | 3226 |
} |
3227 |
||
3228 |
/** |
|
3229 |
* Get the kind of the member reference |
|
3230 |
*/ |
|
3231 |
abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym); |
|
3232 |
||
3233 |
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { |
|
15038 | 3234 |
if (sym.kind == AMBIGUOUS) { |
22161
d79fb23b5dca
8029569: internal javac cast exception when resolving varargs ambiguity
vromero
parents:
21718
diff
changeset
|
3235 |
AmbiguityError a_err = (AmbiguityError)sym.baseSymbol(); |
15038 | 3236 |
sym = a_err.mergeAbstracts(site); |
3237 |
} |
|
14444 | 3238 |
//skip error reporting |
3239 |
return sym; |
|
3240 |
} |
|
3241 |
} |
|
3242 |
||
3243 |
/** |
|
3244 |
* Helper class for method reference lookup. The lookup logic is based |
|
3245 |
* upon Resolve.findMethod; in certain cases, this helper class has a |
|
3246 |
* corresponding unbound helper class (see UnboundMethodReferenceLookupHelper). |
|
3247 |
* In such cases, non-static lookup results are thrown away. |
|
3248 |
*/ |
|
3249 |
class MethodReferenceLookupHelper extends ReferenceLookupHelper { |
|
3250 |
||
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3251 |
/** The original method reference lookup site. */ |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3252 |
Type originalSite; |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3253 |
|
14444 | 3254 |
MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, |
3255 |
List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
|
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3256 |
super(referenceTree, name, types.skipTypeVars(site, true), argtypes, typeargtypes, maxPhase); |
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3257 |
this.originalSite = site; |
14444 | 3258 |
} |
3259 |
||
16323
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16322
diff
changeset
|
3260 |
@Override |
c4409c235642
8008537: Missing method reference lookup error when unbound search finds a static method
mcimadamore
parents:
16322
diff
changeset
|
3261 |
final Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
14444 | 3262 |
return findMethod(env, site, name, argtypes, typeargtypes, |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3263 |
phase.isBoxingRequired(), phase.isVarargsRequired()); |
14444 | 3264 |
} |
3265 |
||
3266 |
@Override |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
3267 |
ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) { |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3268 |
if (TreeInfo.isStaticSelector(referenceTree.expr, names)) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3269 |
if (argtypes.nonEmpty() && |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3270 |
(argtypes.head.hasTag(NONE) || |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3271 |
types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), site))) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3272 |
return new UnboundMethodReferenceLookupHelper(referenceTree, name, |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3273 |
originalSite, argtypes, typeargtypes, maxPhase); |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3274 |
} else { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3275 |
return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3276 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3277 |
ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3278 |
return this; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3279 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3280 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3281 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3282 |
Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3283 |
return methodNotFound; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3284 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3285 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3286 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3287 |
ReferenceKind referenceKind(Symbol sym) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3288 |
Assert.error(); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3289 |
return null; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3290 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3291 |
}; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3292 |
} |
14444 | 3293 |
} else { |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
3294 |
return super.unboundLookup(inferenceContext); |
14444 | 3295 |
} |
3296 |
} |
|
3297 |
||
3298 |
@Override |
|
3299 |
ReferenceKind referenceKind(Symbol sym) { |
|
3300 |
if (sym.isStatic()) { |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14547
diff
changeset
|
3301 |
return ReferenceKind.STATIC; |
14444 | 3302 |
} else { |
3303 |
Name selName = TreeInfo.name(referenceTree.getQualifierExpression()); |
|
3304 |
return selName != null && selName == names._super ? |
|
3305 |
ReferenceKind.SUPER : |
|
3306 |
ReferenceKind.BOUND; |
|
3307 |
} |
|
3308 |
} |
|
3309 |
} |
|
3310 |
||
3311 |
/** |
|
3312 |
* Helper class for unbound method reference lookup. Essentially the same |
|
3313 |
* as the basic method reference lookup helper; main difference is that static |
|
3314 |
* lookup results are thrown away. If qualifier type is raw, an attempt to |
|
3315 |
* infer a parameterized type is made using the first actual argument (that |
|
3316 |
* would otherwise be ignored during the lookup). |
|
3317 |
*/ |
|
3318 |
class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper { |
|
3319 |
||
3320 |
UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, |
|
3321 |
List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
|
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15706
diff
changeset
|
3322 |
super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase); |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3323 |
if (site.isRaw() && !argtypes.head.hasTag(NONE)) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3324 |
Type asSuperSite = types.asSuper(argtypes.head, site.tsym); |
29292
c10d63c667cd
8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents:
29146
diff
changeset
|
3325 |
this.site = types.skipTypeVars(asSuperSite, true); |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15706
diff
changeset
|
3326 |
} |
14444 | 3327 |
} |
3328 |
||
3329 |
@Override |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18668
diff
changeset
|
3330 |
ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) { |
14444 | 3331 |
return this; |
3332 |
} |
|
3333 |
||
3334 |
@Override |
|
3335 |
ReferenceKind referenceKind(Symbol sym) { |
|
3336 |
return ReferenceKind.UNBOUND; |
|
3337 |
} |
|
3338 |
} |
|
3339 |
||
3340 |
/** |
|
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3341 |
* Helper class for array constructor lookup; an array constructor lookup |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3342 |
* is simulated by looking up a method that returns the array type specified |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3343 |
* as qualifier, and that accepts a single int parameter (size of the array). |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3344 |
*/ |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3345 |
class ArrayConstructorReferenceLookupHelper extends ReferenceLookupHelper { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3346 |
|
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3347 |
ArrayConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes, |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3348 |
List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3349 |
super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3350 |
} |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3351 |
|
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3352 |
@Override |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3353 |
protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
3354 |
WriteableScope sc = WriteableScope.create(syms.arrayClass); |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3355 |
MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18389
diff
changeset
|
3356 |
arrayConstr.type = new MethodType(List.<Type>of(syms.intType), site, List.<Type>nil(), syms.methodClass); |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3357 |
sc.enter(arrayConstr); |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3358 |
return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false); |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3359 |
} |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3360 |
|
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3361 |
@Override |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3362 |
ReferenceKind referenceKind(Symbol sym) { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3363 |
return ReferenceKind.ARRAY_CTOR; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3364 |
} |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3365 |
} |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3366 |
|
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
15038
diff
changeset
|
3367 |
/** |
14444 | 3368 |
* Helper class for constructor reference lookup. The lookup logic is based |
3369 |
* upon either Resolve.findMethod or Resolve.findDiamond - depending on |
|
3370 |
* whether the constructor reference needs diamond inference (this is the case |
|
3371 |
* if the qualifier type is raw). A special erroneous symbol is returned |
|
3372 |
* if the lookup returns the constructor of an inner class and there's no |
|
3373 |
* enclosing instance in scope. |
|
3374 |
*/ |
|
3375 |
class ConstructorReferenceLookupHelper extends ReferenceLookupHelper { |
|
3376 |
||
3377 |
boolean needsInference; |
|
3378 |
||
3379 |
ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes, |
|
3380 |
List<Type> typeargtypes, MethodResolutionPhase maxPhase) { |
|
3381 |
super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase); |
|
3382 |
if (site.isRaw()) { |
|
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26533
diff
changeset
|
3383 |
this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym, site.getMetadata()); |
14444 | 3384 |
needsInference = true; |
3385 |
} |
|
3386 |
} |
|
3387 |
||
3388 |
@Override |
|
3389 |
protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { |
|
3390 |
Symbol sym = needsInference ? |
|
3391 |
findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) : |
|
3392 |
findMethod(env, site, name, argtypes, typeargtypes, |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3393 |
phase.isBoxingRequired(), phase.isVarargsRequired()); |
33019
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3394 |
return enclosingInstanceMissing(env, site) ? new BadConstructorReferenceError(sym) : sym; |
14444 | 3395 |
} |
3396 |
||
3397 |
@Override |
|
3398 |
ReferenceKind referenceKind(Symbol sym) { |
|
3399 |
return site.getEnclosingType().hasTag(NONE) ? |
|
3400 |
ReferenceKind.TOPLEVEL : ReferenceKind.IMPLICIT_INNER; |
|
3401 |
} |
|
3402 |
} |
|
3403 |
||
3404 |
/** |
|
3405 |
* Main overload resolution routine. On each overload resolution step, a |
|
3406 |
* lookup helper class is used to perform the method/constructor lookup; |
|
3407 |
* at the end of the lookup, the helper is used to validate the results |
|
3408 |
* (this last step might trigger overload resolution diagnostics). |
|
3409 |
*/ |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3410 |
Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, MethodCheck methodCheck, LookupHelper lookupHelper) { |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3411 |
MethodResolutionContext resolveContext = new MethodResolutionContext(); |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3412 |
resolveContext.methodCheck = methodCheck; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
3413 |
return lookupMethod(env, pos, location, resolveContext, lookupHelper); |
14444 | 3414 |
} |
3415 |
||
3416 |
Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, |
|
3417 |
MethodResolutionContext resolveContext, LookupHelper lookupHelper) { |
|
3418 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
|
3419 |
try { |
|
3420 |
Symbol bestSoFar = methodNotFound; |
|
3421 |
currentResolutionContext = resolveContext; |
|
3422 |
for (MethodResolutionPhase phase : methodResolutionSteps) { |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
3423 |
if (lookupHelper.shouldStop(bestSoFar, phase)) |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
3424 |
break; |
14444 | 3425 |
MethodResolutionPhase prevPhase = currentResolutionContext.step; |
3426 |
Symbol prevBest = bestSoFar; |
|
3427 |
currentResolutionContext.step = phase; |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3428 |
Symbol sym = lookupHelper.lookup(env, phase); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3429 |
lookupHelper.debug(pos, sym); |
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
3430 |
bestSoFar = phase.mergeResults(bestSoFar, sym); |
14444 | 3431 |
env.info.pendingResolutionPhase = (prevBest == bestSoFar) ? prevPhase : phase; |
3432 |
} |
|
3433 |
return lookupHelper.access(env, pos, location, bestSoFar); |
|
3434 |
} finally { |
|
3435 |
currentResolutionContext = prevResolutionContext; |
|
3436 |
} |
|
3437 |
} |
|
3438 |
||
3439 |
/** |
|
10 | 3440 |
* Resolve `c.name' where name == this or name == super. |
3441 |
* @param pos The position to use for error reporting. |
|
3442 |
* @param env The environment current at the expression. |
|
3443 |
* @param c The qualifier. |
|
3444 |
* @param name The identifier's name. |
|
3445 |
*/ |
|
3446 |
Symbol resolveSelf(DiagnosticPosition pos, |
|
3447 |
Env<AttrContext> env, |
|
3448 |
TypeSymbol c, |
|
3449 |
Name name) { |
|
3450 |
Env<AttrContext> env1 = env; |
|
3451 |
boolean staticOnly = false; |
|
3452 |
while (env1.outer != null) { |
|
3453 |
if (isStatic(env1)) staticOnly = true; |
|
3454 |
if (env1.enclClass.sym == c) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
3455 |
Symbol sym = env1.info.scope.findFirst(name); |
10 | 3456 |
if (sym != null) { |
3457 |
if (staticOnly) sym = new StaticError(sym); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
3458 |
return accessBase(sym, pos, env.enclClass.sym.type, |
10 | 3459 |
name, true); |
3460 |
} |
|
3461 |
} |
|
3462 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
3463 |
env1 = env1.outer; |
|
3464 |
} |
|
23105
1d1ea26a10ae
8030855: Default methods should be visible under source previous to 8
vromero
parents:
22442
diff
changeset
|
3465 |
if (c.isInterface() && |
1d1ea26a10ae
8030855: Default methods should be visible under source previous to 8
vromero
parents:
22442
diff
changeset
|
3466 |
name == names._super && !isStatic(env) && |
1d1ea26a10ae
8030855: Default methods should be visible under source previous to 8
vromero
parents:
22442
diff
changeset
|
3467 |
types.isDirectSuperInterface(c, env.enclClass.sym)) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3468 |
//this might be a default super call if one of the superinterfaces is 'c' |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3469 |
for (Type t : pruneInterfaces(env.enclClass.type)) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3470 |
if (t.tsym == c) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3471 |
env.info.defaultSuperCallSite = t; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3472 |
return new VarSymbol(0, names._super, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3473 |
types.asSuper(env.enclClass.type, c), env.enclClass.sym); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3474 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3475 |
} |
39092
399acd370763
8058244: missing error in qualified default super call
vromero
parents:
38914
diff
changeset
|
3476 |
//find a direct super type that is a subtype of 'c' |
399acd370763
8058244: missing error in qualified default super call
vromero
parents:
38914
diff
changeset
|
3477 |
for (Type i : types.directSupertypes(env.enclClass.type)) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3478 |
if (i.tsym.isSubClass(c, types) && i.tsym != c) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3479 |
log.error(pos, "illegal.default.super.call", c, |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3480 |
diags.fragment("redundant.supertype", c, i)); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3481 |
return syms.errSymbol; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3482 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3483 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3484 |
Assert.error(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3485 |
} |
10 | 3486 |
log.error(pos, "not.encl.class", c); |
3487 |
return syms.errSymbol; |
|
3488 |
} |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3489 |
//where |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3490 |
private List<Type> pruneInterfaces(Type t) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19940
diff
changeset
|
3491 |
ListBuffer<Type> result = new ListBuffer<>(); |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3492 |
for (Type t1 : types.interfaces(t)) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3493 |
boolean shouldAdd = true; |
39092
399acd370763
8058244: missing error in qualified default super call
vromero
parents:
38914
diff
changeset
|
3494 |
for (Type t2 : types.directSupertypes(t)) { |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3495 |
if (t1 != t2 && types.isSubtypeNoCapture(t2, t1)) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3496 |
shouldAdd = false; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3497 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3498 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3499 |
if (shouldAdd) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3500 |
result.append(t1); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3501 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3502 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3503 |
return result.toList(); |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3504 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14359
diff
changeset
|
3505 |
|
10 | 3506 |
|
3507 |
/** |
|
3508 |
* Resolve `c.this' for an enclosing class c that contains the |
|
3509 |
* named member. |
|
3510 |
* @param pos The position to use for error reporting. |
|
3511 |
* @param env The environment current at the expression. |
|
3512 |
* @param member The member that must be contained in the result. |
|
3513 |
*/ |
|
3514 |
Symbol resolveSelfContaining(DiagnosticPosition pos, |
|
3515 |
Env<AttrContext> env, |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3516 |
Symbol member, |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3517 |
boolean isSuperCall) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3518 |
Symbol sym = resolveSelfContainingInternal(env, member, isSuperCall); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3519 |
if (sym == null) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3520 |
log.error(pos, "encl.class.required", member); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3521 |
return syms.errSymbol; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3522 |
} else { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3523 |
return accessBase(sym, pos, env.enclClass.sym.type, sym.name, true); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3524 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3525 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3526 |
|
33019
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3527 |
boolean enclosingInstanceMissing(Env<AttrContext> env, Type type) { |
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3528 |
if (type.hasTag(CLASS) && type.getEnclosingType().hasTag(CLASS)) { |
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3529 |
Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); |
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3530 |
return encl == null || encl.kind.isResolutionError(); |
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3531 |
} |
2dc64d1f5e18
8139245: compiler crashes with exception on int:new method reference and generic method inference
sadayapalam
parents:
32951
diff
changeset
|
3532 |
return false; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3533 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3534 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3535 |
private Symbol resolveSelfContainingInternal(Env<AttrContext> env, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3536 |
Symbol member, |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3537 |
boolean isSuperCall) { |
10 | 3538 |
Name name = names._this; |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3539 |
Env<AttrContext> env1 = isSuperCall ? env.outer : env; |
10 | 3540 |
boolean staticOnly = false; |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3541 |
if (env1 != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3542 |
while (env1 != null && env1.outer != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3543 |
if (isStatic(env1)) staticOnly = true; |
34561
79c436257611
8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents:
33019
diff
changeset
|
3544 |
if (env1.enclClass.sym.isSubClass(member.owner.enclClass(), types)) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25435
diff
changeset
|
3545 |
Symbol sym = env1.info.scope.findFirst(name); |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3546 |
if (sym != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3547 |
if (staticOnly) sym = new StaticError(sym); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3548 |
return sym; |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3549 |
} |
10 | 3550 |
} |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3551 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3552 |
staticOnly = true; |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3553 |
env1 = env1.outer; |
10 | 3554 |
} |
3555 |
} |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3556 |
return null; |
10 | 3557 |
} |
3558 |
||
3559 |
/** |
|
3560 |
* Resolve an appropriate implicit this instance for t's container. |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9302
diff
changeset
|
3561 |
* JLS 8.8.5.1 and 15.9.2 |
10 | 3562 |
*/ |
3563 |
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) { |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3564 |
return resolveImplicitThis(pos, env, t, false); |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3565 |
} |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3566 |
|
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3567 |
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3568 |
Type thisType = (t.tsym.owner.kind.matches(KindSelector.VAL_MTH) |
10 | 3569 |
? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
3570 |
: resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type; |
10 | 3571 |
if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) |
3572 |
log.error(pos, "cant.ref.before.ctor.called", "this"); |
|
3573 |
return thisType; |
|
3574 |
} |
|
3575 |
||
3576 |
/* *************************************************************************** |
|
3577 |
* ResolveError classes, indicating error situations when accessing symbols |
|
3578 |
****************************************************************************/ |
|
3579 |
||
12082
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
3580 |
//used by TransTypes when checking target type of synthetic cast |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
3581 |
public void logAccessErrorInternal(Env<AttrContext> env, JCTree tree, Type type) { |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
3582 |
AccessError error = new AccessError(env, env.enclClass.type, type.tsym); |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
3583 |
logResolveError(error, tree.pos(), env.enclClass.sym, env.enclClass.type, null, null, null); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3584 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3585 |
//where |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3586 |
private void logResolveError(ResolveError error, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3587 |
DiagnosticPosition pos, |
8045 | 3588 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3589 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3590 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3591 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3592 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3593 |
JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, |
8045 | 3594 |
pos, location, site, name, argtypes, typeargtypes); |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
3595 |
if (d != null) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
3596 |
d.setFlag(DiagnosticFlag.RESOLVE_ERROR); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3597 |
log.report(d); |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
3598 |
} |
10 | 3599 |
} |
3600 |
||
1534
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
3601 |
private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); |
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
3602 |
|
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
3603 |
public Object methodArguments(List<Type> argtypes) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3604 |
if (argtypes == null || argtypes.isEmpty()) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3605 |
return noArgs; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3606 |
} else { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19940
diff
changeset
|
3607 |
ListBuffer<Object> diagArgs = new ListBuffer<>(); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3608 |
for (Type t : argtypes) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
3609 |
if (t.hasTag(DEFERRED)) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3610 |
diagArgs.append(((DeferredAttr.DeferredType)t).tree); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3611 |
} else { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3612 |
diagArgs.append(t); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3613 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3614 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3615 |
return diagArgs; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
3616 |
} |
1534
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
3617 |
} |
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
3618 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3619 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3620 |
* Root class for resolution errors. Subclass of ResolveError |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3621 |
* represent a different kinds of resolution error - as such they must |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3622 |
* specify how they map into concrete compiler diagnostics. |
10 | 3623 |
*/ |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3624 |
abstract class ResolveError extends Symbol { |
10 | 3625 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3626 |
/** The name of the kind of error, for debugging only. */ |
10 | 3627 |
final String debugName; |
3628 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3629 |
ResolveError(Kind kind, String debugName) { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3630 |
super(kind, 0, null, null, null); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3631 |
this.debugName = debugName; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3632 |
} |
10 | 3633 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
3634 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 3635 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
3636 |
throw new AssertionError(); |
|
3637 |
} |
|
3638 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3639 |
@Override |
10 | 3640 |
public String toString() { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3641 |
return debugName; |
10 | 3642 |
} |
3643 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3644 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3645 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3646 |
return false; |
10 | 3647 |
} |
3648 |
||
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3649 |
@Override |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3650 |
public boolean isStatic() { |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3651 |
return false; |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3652 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3653 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3654 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3655 |
* Create an external representation for this erroneous symbol to be |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3656 |
* used during attribution - by default this returns the symbol of a |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3657 |
* brand new error type which stores the original type found |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3658 |
* during resolution. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3659 |
* |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3660 |
* @param name the name used during resolution |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3661 |
* @param location the location from which the symbol is accessed |
10 | 3662 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3663 |
protected Symbol access(Name name, TypeSymbol location) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3664 |
return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
10 | 3665 |
} |
3666 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3667 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3668 |
* Create a diagnostic representing this resolution error. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3669 |
* |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3670 |
* @param dkind The kind of the diagnostic to be created (e.g error). |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3671 |
* @param pos The position to be used for error reporting. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3672 |
* @param site The original type from where the selection took place. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3673 |
* @param name The name of the symbol to be resolved. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3674 |
* @param argtypes The invocation's value arguments, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3675 |
* if we looked for a method. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3676 |
* @param typeargtypes The invocation's type arguments, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3677 |
* if we looked for a method. |
10 | 3678 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3679 |
abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3680 |
DiagnosticPosition pos, |
8045 | 3681 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3682 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3683 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3684 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3685 |
List<Type> typeargtypes); |
10 | 3686 |
} |
3687 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3688 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3689 |
* This class is the root class of all resolution errors caused by |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3690 |
* an invalid symbol being found during resolution. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3691 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3692 |
abstract class InvalidSymbolError extends ResolveError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3693 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3694 |
/** The invalid symbol found during resolution */ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3695 |
Symbol sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3696 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3697 |
InvalidSymbolError(Kind kind, Symbol sym, String debugName) { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3698 |
super(kind, debugName); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3699 |
this.sym = sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3700 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3701 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3702 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3703 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3704 |
return true; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3705 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3706 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3707 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3708 |
public String toString() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3709 |
return super.toString() + " wrongSym=" + sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3710 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3711 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3712 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3713 |
public Symbol access(Name name, TypeSymbol location) { |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
3714 |
if (!sym.kind.isResolutionError() && sym.kind.matches(KindSelector.TYP)) |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3715 |
return types.createErrorType(name, location, sym.type).tsym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3716 |
else |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3717 |
return sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3718 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3719 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3720 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3721 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3722 |
* InvalidSymbolError error class indicating that a symbol matching a |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3723 |
* given name does not exists in a given site. |
10 | 3724 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3725 |
class SymbolNotFoundError extends ResolveError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3726 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3727 |
SymbolNotFoundError(Kind kind) { |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3728 |
this(kind, "symbol not found error"); |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3729 |
} |
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3730 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3731 |
SymbolNotFoundError(Kind kind, String debugName) { |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
21024
diff
changeset
|
3732 |
super(kind, debugName); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3733 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3734 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3735 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3736 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3737 |
DiagnosticPosition pos, |
8045 | 3738 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3739 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3740 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3741 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3742 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3743 |
argtypes = argtypes == null ? List.<Type>nil() : argtypes; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3744 |
typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3745 |
if (name == names.error) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3746 |
return null; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3747 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3748 |
boolean hasLocation = false; |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3749 |
if (location == null) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3750 |
location = site.tsym; |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3751 |
} |
8045 | 3752 |
if (!location.name.isEmpty()) { |
3753 |
if (location.kind == PCK && !site.tsym.exists()) { |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
3754 |
return diags.create(dkind, log.currentSource(), pos, |
8045 | 3755 |
"doesnt.exist", location); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3756 |
} |
8045 | 3757 |
hasLocation = !location.name.equals(names._this) && |
3758 |
!location.name.equals(names._super); |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3759 |
} |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
3760 |
boolean isConstructor = name == names.init; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3761 |
KindName kindname = isConstructor ? KindName.CONSTRUCTOR : kind.absentKind(); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3762 |
Name idname = isConstructor ? site.tsym.name : name; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3763 |
String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3764 |
if (hasLocation) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
3765 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3766 |
errKey, kindname, idname, //symbol kindname, name |
14953
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3767 |
typeargtypes, args(argtypes), //type parameters and arguments (if any) |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3768 |
getLocationDiag(location, site)); //location kindname, type |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3769 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3770 |
else { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
3771 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3772 |
errKey, kindname, idname, //symbol kindname, name |
14953
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3773 |
typeargtypes, args(argtypes)); //type parameters and arguments (if any) |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3774 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3775 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3776 |
//where |
14953
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3777 |
private Object args(List<Type> args) { |
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3778 |
return args.isEmpty() ? args : methodArguments(args); |
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3779 |
} |
89a34297b198
8004099: Bad compiler diagnostic generated when poly expression is passed to non-existent method
mcimadamore
parents:
14801
diff
changeset
|
3780 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3781 |
private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3782 |
String key = "cant.resolve"; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3783 |
String suffix = hasLocation ? ".location" : ""; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3784 |
switch (kindname) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3785 |
case METHOD: |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3786 |
case CONSTRUCTOR: { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3787 |
suffix += ".args"; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3788 |
suffix += hasTypeArgs ? ".params" : ""; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3789 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3790 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3791 |
return key + suffix; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3792 |
} |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3793 |
private JCDiagnostic getLocationDiag(Symbol location, Type site) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3794 |
if (location.kind == VAR) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3795 |
return diags.fragment("location.1", |
8045 | 3796 |
kindName(location), |
3797 |
location, |
|
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3798 |
location.type); |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3799 |
} else { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3800 |
return diags.fragment("location", |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3801 |
typeKindName(site), |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3802 |
site, |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3803 |
null); |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3804 |
} |
8045 | 3805 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3806 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3807 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3808 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3809 |
* InvalidSymbolError error class indicating that a given symbol |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3810 |
* (either a method, a constructor or an operand) is not applicable |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3811 |
* given an actual arguments/type argument list. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3812 |
*/ |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3813 |
class InapplicableSymbolError extends ResolveError { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3814 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3815 |
protected MethodResolutionContext resolveContext; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3816 |
|
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3817 |
InapplicableSymbolError(MethodResolutionContext context) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3818 |
this(WRONG_MTH, "inapplicable symbol error", context); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3819 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3820 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3821 |
protected InapplicableSymbolError(Kind kind, String debugName, MethodResolutionContext context) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3822 |
super(kind, debugName); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3823 |
this.resolveContext = context; |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3824 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3825 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3826 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3827 |
public String toString() { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3828 |
return super.toString(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3829 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3830 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3831 |
@Override |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3832 |
public boolean exists() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3833 |
return true; |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3834 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3835 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3836 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3837 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3838 |
DiagnosticPosition pos, |
8045 | 3839 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3840 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3841 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3842 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3843 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3844 |
if (name == names.error) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3845 |
return null; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3846 |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3847 |
Pair<Symbol, JCDiagnostic> c = errCandidate(); |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3848 |
if (compactMethodDiags) { |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3849 |
JCDiagnostic simpleDiag = |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3850 |
MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd); |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3851 |
if (simpleDiag != null) { |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3852 |
return simpleDiag; |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3853 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3854 |
} |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3855 |
Symbol ws = c.fst.asMemberOf(site, types); |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3856 |
return diags.create(dkind, log.currentSource(), pos, |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3857 |
"cant.apply.symbol", |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3858 |
kindName(ws), |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3859 |
ws.name == names.init ? ws.owner.name : ws.name, |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3860 |
methodArguments(ws.type.getParameterTypes()), |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3861 |
methodArguments(argtypes), |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3862 |
kindName(ws.owner), |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3863 |
ws.owner.type, |
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28456
diff
changeset
|
3864 |
c.snd); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3865 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3866 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3867 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3868 |
public Symbol access(Name name, TypeSymbol location) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3869 |
return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3870 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3871 |
|
18913 | 3872 |
protected Pair<Symbol, JCDiagnostic> errCandidate() { |
14444 | 3873 |
Candidate bestSoFar = null; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3874 |
for (Candidate c : resolveContext.candidates) { |
14444 | 3875 |
if (c.isApplicable()) continue; |
3876 |
bestSoFar = c; |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3877 |
} |
14444 | 3878 |
Assert.checkNonNull(bestSoFar); |
22163 | 3879 |
return new Pair<>(bestSoFar.sym, bestSoFar.details); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3880 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3881 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3882 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3883 |
/** |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3884 |
* ResolveError error class indicating that a symbol (either methods, constructors or operand) |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3885 |
* is not applicable given an actual arguments/type argument list. |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3886 |
*/ |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3887 |
class InapplicableSymbolsError extends InapplicableSymbolError { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3888 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3889 |
InapplicableSymbolsError(MethodResolutionContext context) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
3890 |
super(WRONG_MTHS, "inapplicable symbols", context); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3891 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3892 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3893 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3894 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3895 |
DiagnosticPosition pos, |
8045 | 3896 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3897 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3898 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3899 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3900 |
List<Type> typeargtypes) { |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3901 |
Map<Symbol, JCDiagnostic> candidatesMap = mapCandidates(); |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3902 |
Map<Symbol, JCDiagnostic> filteredCandidates = compactMethodDiags ? |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3903 |
filterCandidates(candidatesMap) : |
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3904 |
mapCandidates(); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3905 |
if (filteredCandidates.isEmpty()) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3906 |
filteredCandidates = candidatesMap; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3907 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3908 |
boolean truncatedDiag = candidatesMap.size() != filteredCandidates.size(); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3909 |
if (filteredCandidates.size() > 1) { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3910 |
JCDiagnostic err = diags.create(dkind, |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3911 |
null, |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3912 |
truncatedDiag ? |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3913 |
EnumSet.of(DiagnosticFlag.COMPRESSED) : |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3914 |
EnumSet.noneOf(DiagnosticFlag.class), |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3915 |
log.currentSource(), |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3916 |
pos, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3917 |
"cant.apply.symbols", |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26991
diff
changeset
|
3918 |
name == names.init ? KindName.CONSTRUCTOR : kind.absentKind(), |
14444 | 3919 |
name == names.init ? site.tsym.name : name, |
14547 | 3920 |
methodArguments(argtypes)); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3921 |
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site)); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3922 |
} else if (filteredCandidates.size() == 1) { |
18913 | 3923 |
Map.Entry<Symbol, JCDiagnostic> _e = |
3924 |
filteredCandidates.entrySet().iterator().next(); |
|
22163 | 3925 |
final Pair<Symbol, JCDiagnostic> p = new Pair<>(_e.getKey(), _e.getValue()); |
18913 | 3926 |
JCDiagnostic d = new InapplicableSymbolError(resolveContext) { |
3927 |
@Override |
|
3928 |
protected Pair<Symbol, JCDiagnostic> errCandidate() { |
|
3929 |
return p; |
|
3930 |
} |
|
3931 |
}.getDiagnostic(dkind, pos, |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3932 |
location, site, name, argtypes, typeargtypes); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3933 |
if (truncatedDiag) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3934 |
d.setFlag(DiagnosticFlag.COMPRESSED); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3935 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3936 |
return d; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3937 |
} else { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3938 |
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, |
8045 | 3939 |
location, site, name, argtypes, typeargtypes); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3940 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3941 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
3942 |
//where |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3943 |
private Map<Symbol, JCDiagnostic> mapCandidates() { |
22163 | 3944 |
Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>(); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3945 |
for (Candidate c : resolveContext.candidates) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3946 |
if (c.isApplicable()) continue; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3947 |
candidates.put(c.sym, c.details); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3948 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3949 |
return candidates; |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
3950 |
} |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3951 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3952 |
Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol, JCDiagnostic> candidatesMap) { |
22163 | 3953 |
Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>(); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3954 |
for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3955 |
JCDiagnostic d = _entry.getValue(); |
19129
b1409ae675f8
8020843: javac crashes on accessibility check with method reference with typevar receiver
mcimadamore
parents:
18914
diff
changeset
|
3956 |
if (!new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) { |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3957 |
candidates.put(_entry.getKey(), d); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3958 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3959 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3960 |
return candidates; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3961 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3962 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3963 |
private List<JCDiagnostic> candidateDetails(Map<Symbol, JCDiagnostic> candidatesMap, Type site) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3964 |
List<JCDiagnostic> details = List.nil(); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3965 |
for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3966 |
Symbol sym = _entry.getKey(); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3967 |
JCDiagnostic detailDiag = diags.fragment("inapplicable.method", |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3968 |
Kinds.kindName(sym), |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3969 |
sym.location(site, types), |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3970 |
sym.asMemberOf(site, types), |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3971 |
_entry.getValue()); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3972 |
details = details.prepend(detailDiag); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3973 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3974 |
//typically members are visited in reverse order (see Scope) |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3975 |
//so we need to reverse the candidate list so that candidates |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3976 |
//conform to source order |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3977 |
return details; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
3978 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3979 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3980 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
3981 |
/** |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3982 |
* DiamondError error class indicating that a constructor symbol is not applicable |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3983 |
* given an actual arguments/type argument list using diamond inference. |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3984 |
*/ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3985 |
class DiamondError extends InapplicableSymbolError { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3986 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3987 |
Symbol sym; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3988 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3989 |
public DiamondError(Symbol sym, MethodResolutionContext context) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3990 |
super(sym.kind, "diamondError", context); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3991 |
this.sym = sym; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3992 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3993 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3994 |
JCDiagnostic getDetails() { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3995 |
return (sym.kind == WRONG_MTH) ? |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3996 |
((InapplicableSymbolError)sym.baseSymbol()).errCandidate().snd : |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3997 |
null; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3998 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
3999 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4000 |
@Override |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4001 |
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4002 |
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4003 |
JCDiagnostic details = getDetails(); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4004 |
if (details != null && compactMethodDiags) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4005 |
JCDiagnostic simpleDiag = |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4006 |
MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, details); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4007 |
if (simpleDiag != null) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4008 |
return simpleDiag; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4009 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4010 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4011 |
String key = details == null ? |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4012 |
"cant.apply.diamond" : |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4013 |
"cant.apply.diamond.1"; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4014 |
return diags.create(dkind, log.currentSource(), pos, key, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4015 |
diags.fragment("diamond", site.tsym), details); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4016 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4017 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4018 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4019 |
/** |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4020 |
* An InvalidSymbolError error class indicating that a symbol is not |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4021 |
* accessible from a given site |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4022 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4023 |
class AccessError extends InvalidSymbolError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4024 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4025 |
private Env<AttrContext> env; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4026 |
private Type site; |
10 | 4027 |
|
4028 |
AccessError(Env<AttrContext> env, Type site, Symbol sym) { |
|
4029 |
super(HIDDEN, sym, "access error"); |
|
4030 |
this.env = env; |
|
4031 |
this.site = site; |
|
4032 |
} |
|
4033 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4034 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4035 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4036 |
return false; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4037 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4038 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4039 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4040 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4041 |
DiagnosticPosition pos, |
8045 | 4042 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4043 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4044 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4045 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4046 |
List<Type> typeargtypes) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
4047 |
if (sym.owner.type.hasTag(ERROR)) |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4048 |
return null; |
10 | 4049 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4050 |
if (sym.name == names.init && sym.owner != site.tsym) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4051 |
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, |
8045 | 4052 |
pos, location, site, name, argtypes, typeargtypes); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4053 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4054 |
else if ((sym.flags() & PUBLIC) != 0 |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4055 |
|| (env != null && this.site != null |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4056 |
&& !isAccessible(env, this.site))) { |
36526 | 4057 |
if (sym.owner.kind == PCK) { |
4058 |
return diags.create(dkind, log.currentSource(), |
|
4059 |
pos, "not.def.access.package.cant.access", |
|
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4060 |
sym, sym.location(), inaccessiblePackageReason(env, sym.packge())); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4061 |
} else if ( sym.packge() != syms.rootPackage |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4062 |
&& sym.packge().modle != env.toplevel.modle |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4063 |
&& !isAccessible(env, sym.outermostClass())) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4064 |
return diags.create(dkind, log.currentSource(), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4065 |
pos, "not.def.access.class.intf.cant.access.reason", |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4066 |
sym, sym.location(), sym.location().packge(), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4067 |
inaccessiblePackageReason(env, sym.packge())); |
36526 | 4068 |
} else { |
4069 |
return diags.create(dkind, log.currentSource(), |
|
4070 |
pos, "not.def.access.class.intf.cant.access", |
|
4071 |
sym, sym.location()); |
|
4072 |
} |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4073 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4074 |
else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
4075 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4076 |
pos, "report.access", sym, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4077 |
asFlagSet(sym.flags() & (PRIVATE | PROTECTED)), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4078 |
sym.location()); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4079 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4080 |
else { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
4081 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4082 |
pos, "not.def.public.cant.access", sym, sym.location()); |
10 | 4083 |
} |
4084 |
} |
|
36526 | 4085 |
|
4086 |
private String toString(Type type) { |
|
4087 |
StringBuilder sb = new StringBuilder(); |
|
4088 |
sb.append(type); |
|
4089 |
if (type != null) { |
|
4090 |
sb.append("[tsym:").append(type.tsym); |
|
4091 |
if (type.tsym != null) |
|
4092 |
sb.append("packge:").append(type.tsym.packge()); |
|
4093 |
sb.append("]"); |
|
4094 |
} |
|
4095 |
return sb.toString(); |
|
4096 |
} |
|
10 | 4097 |
} |
4098 |
||
41931
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4099 |
class InvisibleSymbolError extends InvalidSymbolError { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4100 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4101 |
private final Env<AttrContext> env; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4102 |
private final boolean suppressError; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4103 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4104 |
InvisibleSymbolError(Env<AttrContext> env, boolean suppressError, Symbol sym) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4105 |
super(HIDDEN, sym, "invisible class error"); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4106 |
this.env = env; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4107 |
this.suppressError = suppressError; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4108 |
this.name = sym.name; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4109 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4110 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4111 |
@Override |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4112 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4113 |
DiagnosticPosition pos, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4114 |
Symbol location, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4115 |
Type site, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4116 |
Name name, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4117 |
List<Type> argtypes, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4118 |
List<Type> typeargtypes) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4119 |
if (suppressError) |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4120 |
return null; |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4121 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4122 |
if (sym.kind == PCK) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4123 |
JCDiagnostic details = inaccessiblePackageReason(env, sym.packge()); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4124 |
return diags.create(dkind, log.currentSource(), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4125 |
pos, "package.not.visible", sym, details); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4126 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4127 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4128 |
JCDiagnostic details = inaccessiblePackageReason(env, sym.packge()); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4129 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4130 |
if (pos.getTree() != null && pos.getTree().hasTag(SELECT) && sym.owner.kind == PCK) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4131 |
pos = ((JCFieldAccess) pos.getTree()).selected.pos(); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4132 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4133 |
return diags.create(dkind, log.currentSource(), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4134 |
pos, "package.not.visible", sym.packge(), details); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4135 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4136 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4137 |
return diags.create(dkind, log.currentSource(), |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4138 |
pos, "not.def.access.package.cant.access", sym, sym.packge(), details); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4139 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4140 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4141 |
|
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4142 |
JCDiagnostic inaccessiblePackageReason(Env<AttrContext> env, PackageSymbol sym) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4143 |
//no dependency: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4144 |
if (!env.toplevel.modle.readModules.contains(sym.modle)) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4145 |
//does not read: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4146 |
if (sym.modle != syms.unnamedModule) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4147 |
if (env.toplevel.modle != syms.unnamedModule) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4148 |
return diags.fragment(Fragments.NotDefAccessDoesNotRead(env.toplevel.modle, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4149 |
sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4150 |
sym.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4151 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4152 |
return diags.fragment(Fragments.NotDefAccessDoesNotReadFromUnnamed(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4153 |
sym.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4154 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4155 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4156 |
return diags.fragment(Fragments.NotDefAccessDoesNotReadUnnamed(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4157 |
env.toplevel.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4158 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4159 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4160 |
if (sym.packge().modle.exports.stream().anyMatch(e -> e.packge == sym)) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4161 |
//not exported to this module: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4162 |
if (env.toplevel.modle != syms.unnamedModule) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4163 |
return diags.fragment(Fragments.NotDefAccessNotExportedToModule(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4164 |
sym.modle, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4165 |
env.toplevel.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4166 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4167 |
return diags.fragment(Fragments.NotDefAccessNotExportedToModuleFromUnnamed(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4168 |
sym.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4169 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4170 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4171 |
//not exported: |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4172 |
if (env.toplevel.modle != syms.unnamedModule) { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4173 |
return diags.fragment(Fragments.NotDefAccessNotExported(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4174 |
sym.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4175 |
} else { |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4176 |
return diags.fragment(Fragments.NotDefAccessNotExportedFromUnnamed(sym, |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4177 |
sym.modle)); |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4178 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4179 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4180 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4181 |
} |
d7c9720c4223
8166538: Improve error reporting for compiling against unexported package
jlahoda
parents:
41526
diff
changeset
|
4182 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4183 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4184 |
* InvalidSymbolError error class indicating that an instance member |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4185 |
* has erroneously been accessed from a static context. |
10 | 4186 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4187 |
class StaticError extends InvalidSymbolError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4188 |
|
10 | 4189 |
StaticError(Symbol sym) { |
4190 |
super(STATICERR, sym, "static error"); |
|
4191 |
} |
|
4192 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4193 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4194 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4195 |
DiagnosticPosition pos, |
8045 | 4196 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4197 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4198 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4199 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4200 |
List<Type> typeargtypes) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14062
diff
changeset
|
4201 |
Symbol errSym = ((sym.kind == TYP && sym.type.hasTag(CLASS)) |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
4202 |
? types.erasure(sym.type).tsym |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
4203 |
: sym); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
4204 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4205 |
"non-static.cant.be.ref", kindName(sym), errSym); |
10 | 4206 |
} |
4207 |
} |
|
4208 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4209 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4210 |
* InvalidSymbolError error class indicating that a pair of symbols |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4211 |
* (either methods, constructors or operands) are ambiguous |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4212 |
* given an actual arguments/type argument list. |
10 | 4213 |
*/ |
15038 | 4214 |
class AmbiguityError extends ResolveError { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4215 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4216 |
/** The other maximally specific symbol */ |
15038 | 4217 |
List<Symbol> ambiguousSyms = List.nil(); |
4218 |
||
4219 |
@Override |
|
4220 |
public boolean exists() { |
|
4221 |
return true; |
|
4222 |
} |
|
10 | 4223 |
|
4224 |
AmbiguityError(Symbol sym1, Symbol sym2) { |
|
15038 | 4225 |
super(AMBIGUOUS, "ambiguity error"); |
4226 |
ambiguousSyms = flatten(sym2).appendList(flatten(sym1)); |
|
4227 |
} |
|
4228 |
||
4229 |
private List<Symbol> flatten(Symbol sym) { |
|
4230 |
if (sym.kind == AMBIGUOUS) { |
|
22161
d79fb23b5dca
8029569: internal javac cast exception when resolving varargs ambiguity
vromero
parents:
21718
diff
changeset
|
4231 |
return ((AmbiguityError)sym.baseSymbol()).ambiguousSyms; |
15038 | 4232 |
} else { |
4233 |
return List.of(sym); |
|
4234 |
} |
|
4235 |
} |
|
4236 |
||
4237 |
AmbiguityError addAmbiguousSymbol(Symbol s) { |
|
4238 |
ambiguousSyms = ambiguousSyms.prepend(s); |
|
4239 |
return this; |
|
10 | 4240 |
} |
4241 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4242 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4243 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4244 |
DiagnosticPosition pos, |
8045 | 4245 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4246 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4247 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4248 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
4249 |
List<Type> typeargtypes) { |
15038 | 4250 |
List<Symbol> diagSyms = ambiguousSyms.reverse(); |
4251 |
Symbol s1 = diagSyms.head; |
|
4252 |
Symbol s2 = diagSyms.tail.head; |
|
4253 |
Name sname = s1.name; |
|
4254 |
if (sname == names.init) sname = s1.owner.name; |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
4255 |
return diags.create(dkind, log.currentSource(), |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4256 |
pos, "ref.ambiguous", sname, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4257 |
kindName(s1), |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4258 |
s1, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4259 |
s1.location(site, types), |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4260 |
kindName(s2), |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4261 |
s2, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4262 |
s2.location(site, types)); |
15038 | 4263 |
} |
4264 |
||
4265 |
/** |
|
4266 |
* If multiple applicable methods are found during overload and none of them |
|
4267 |
* is more specific than the others, attempt to merge their signatures. |
|
4268 |
*/ |
|
4269 |
Symbol mergeAbstracts(Type site) { |
|
18668
1f99c1b43ab2
7034798: Ambiguity error for abstract method call is too eager
mcimadamore
parents:
18646
diff
changeset
|
4270 |
List<Symbol> ambiguousInOrder = ambiguousSyms.reverse(); |
41526
265017792980
8167000: Refine handling of multiple maximally specific abstract methods
mcimadamore
parents:
39599
diff
changeset
|
4271 |
return types.mergeAbstracts(ambiguousInOrder, site, true).orElse(this); |
15038 | 4272 |
} |
4273 |
||
4274 |
@Override |
|
4275 |
protected Symbol access(Name name, TypeSymbol location) { |
|
15362
f564dcca5525
8005964: Regression: difference in error recovery after ambiguity causes JCK test failure
mcimadamore
parents:
15360
diff
changeset
|
4276 |
Symbol firstAmbiguity = ambiguousSyms.last(); |
f564dcca5525
8005964: Regression: difference in error recovery after ambiguity causes JCK test failure
mcimadamore
parents:
15360
diff
changeset
|
4277 |
return firstAmbiguity.kind == TYP ? |
f564dcca5525
8005964: Regression: difference in error recovery after ambiguity causes JCK test failure
mcimadamore
parents:
15360
diff
changeset
|
4278 |
types.createErrorType(name, location, firstAmbiguity.type).tsym : |
f564dcca5525
8005964: Regression: difference in error recovery after ambiguity causes JCK test failure
mcimadamore
parents:
15360
diff
changeset
|
4279 |
firstAmbiguity; |
10 | 4280 |
} |
4281 |
} |
|
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4282 |
|
16312
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4283 |
class BadVarargsMethod extends ResolveError { |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4284 |
|
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4285 |
ResolveError delegatedError; |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4286 |
|
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4287 |
BadVarargsMethod(ResolveError delegatedError) { |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4288 |
super(delegatedError.kind, "badVarargs"); |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4289 |
this.delegatedError = delegatedError; |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4290 |
} |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4291 |
|
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4292 |
@Override |
16975
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
4293 |
public Symbol baseSymbol() { |
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
4294 |
return delegatedError.baseSymbol(); |
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
4295 |
} |
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
4296 |
|
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
4297 |
@Override |
16312
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4298 |
protected Symbol access(Name name, TypeSymbol location) { |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4299 |
return delegatedError.access(name, location); |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4300 |
} |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4301 |
|
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4302 |
@Override |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4303 |
public boolean exists() { |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4304 |
return true; |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4305 |
} |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4306 |
|
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4307 |
@Override |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4308 |
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4309 |
return delegatedError.getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes); |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4310 |
} |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4311 |
} |
7fb570abcb54
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
mcimadamore
parents:
16301
diff
changeset
|
4312 |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4313 |
/** |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4314 |
* BadMethodReferenceError error class indicating that a method reference symbol has been found, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4315 |
* but with the wrong staticness. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4316 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4317 |
class BadMethodReferenceError extends StaticError { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4318 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4319 |
boolean unboundLookup; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4320 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4321 |
public BadMethodReferenceError(Symbol sym, boolean unboundLookup) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4322 |
super(sym); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4323 |
this.unboundLookup = unboundLookup; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4324 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4325 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4326 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4327 |
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4328 |
final String key; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4329 |
if (!unboundLookup) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4330 |
key = "bad.static.method.in.bound.lookup"; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4331 |
} else if (sym.isStatic()) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4332 |
key = "bad.static.method.in.unbound.lookup"; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4333 |
} else { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4334 |
key = "bad.instance.method.in.unbound.lookup"; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4335 |
} |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
4336 |
return sym.kind.isResolutionError() ? |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4337 |
((ResolveError)sym).getDiagnostic(dkind, pos, location, site, name, argtypes, typeargtypes) : |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4338 |
diags.create(dkind, log.currentSource(), pos, key, Kinds.kindName(sym), sym); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4339 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4340 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4341 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4342 |
/** |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4343 |
* BadConstructorReferenceError error class indicating that a constructor reference symbol has been found, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4344 |
* but pointing to a class for which an enclosing instance is not available. |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4345 |
*/ |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4346 |
class BadConstructorReferenceError extends InvalidSymbolError { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4347 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4348 |
public BadConstructorReferenceError(Symbol sym) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4349 |
super(MISSING_ENCL, sym, "BadConstructorReferenceError"); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4350 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4351 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4352 |
@Override |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4353 |
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4354 |
return diags.create(dkind, log.currentSource(), pos, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4355 |
"cant.access.inner.cls.constr", site.tsym.name, argtypes, site.getEnclosingType()); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4356 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4357 |
} |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4358 |
|
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28336
diff
changeset
|
4359 |
/** |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4360 |
* Helper class for method resolution diagnostic simplification. |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4361 |
* Certain resolution diagnostic are rewritten as simpler diagnostic |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4362 |
* where the enclosing resolution diagnostic (i.e. 'inapplicable method') |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4363 |
* is stripped away, as it doesn't carry additional info. The logic |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4364 |
* for matching a given diagnostic is given in terms of a template |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4365 |
* hierarchy: a diagnostic template can be specified programmatically, |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4366 |
* so that only certain diagnostics are matched. Each templete is then |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4367 |
* associated with a rewriter object that carries out the task of rewtiting |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4368 |
* the diagnostic to a simpler one. |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4369 |
*/ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4370 |
static class MethodResolutionDiagHelper { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4371 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4372 |
/** |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4373 |
* A diagnostic rewriter transforms a method resolution diagnostic |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4374 |
* into a simpler one |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4375 |
*/ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4376 |
interface DiagnosticRewriter { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4377 |
JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4378 |
DiagnosticPosition preferedPos, DiagnosticSource preferredSource, |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4379 |
DiagnosticType preferredKind, JCDiagnostic d); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4380 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4381 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4382 |
/** |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4383 |
* A diagnostic template is made up of two ingredients: (i) a regular |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4384 |
* expression for matching a diagnostic key and (ii) a list of sub-templates |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4385 |
* for matching diagnostic arguments. |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4386 |
*/ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4387 |
static class Template { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4388 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4389 |
/** regex used to match diag key */ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4390 |
String regex; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4391 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4392 |
/** templates used to match diagnostic args */ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4393 |
Template[] subTemplates; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4394 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4395 |
Template(String key, Template... subTemplates) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4396 |
this.regex = key; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4397 |
this.subTemplates = subTemplates; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4398 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4399 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4400 |
/** |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4401 |
* Returns true if the regex matches the diagnostic key and if |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4402 |
* all diagnostic arguments are matches by corresponding sub-templates. |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4403 |
*/ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4404 |
boolean matches(Object o) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4405 |
JCDiagnostic d = (JCDiagnostic)o; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4406 |
Object[] args = d.getArgs(); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4407 |
if (!d.getCode().matches(regex) || |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4408 |
subTemplates.length != d.getArgs().length) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4409 |
return false; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4410 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4411 |
for (int i = 0; i < args.length ; i++) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4412 |
if (!subTemplates[i].matches(args[i])) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4413 |
return false; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4414 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4415 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4416 |
return true; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4417 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4418 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4419 |
|
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4420 |
/** |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4421 |
* Common rewriter for all argument mismatch simplifications. |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4422 |
*/ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4423 |
static class ArgMismatchRewriter implements DiagnosticRewriter { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4424 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4425 |
/** the index of the subdiagnostic to be used as primary. */ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4426 |
int causeIndex; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4427 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4428 |
public ArgMismatchRewriter(int causeIndex) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4429 |
this.causeIndex = causeIndex; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4430 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4431 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4432 |
@Override |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4433 |
public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4434 |
DiagnosticPosition preferedPos, DiagnosticSource preferredSource, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4435 |
DiagnosticType preferredKind, JCDiagnostic d) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4436 |
JCDiagnostic cause = (JCDiagnostic)d.getArgs()[causeIndex]; |
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
4437 |
DiagnosticPosition pos = d.getDiagnosticPosition(); |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
4438 |
if (pos == null) { |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
4439 |
pos = preferedPos; |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
4440 |
} |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
34566
diff
changeset
|
4441 |
return diags.create(preferredKind, preferredSource, pos, |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4442 |
"prob.found.req", cause); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4443 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4444 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4445 |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4446 |
/** a dummy template that match any diagnostic argument */ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4447 |
static final Template skip = new Template("") { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4448 |
@Override |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4449 |
boolean matches(Object d) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4450 |
return true; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4451 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4452 |
}; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4453 |
|
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4454 |
/** template for matching inference-free arguments mismatch failures */ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4455 |
static final Template argMismatchTemplate = new Template(MethodCheckDiag.ARG_MISMATCH.regex(), skip); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4456 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4457 |
/** template for matching inference related arguments mismatch failures */ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4458 |
static final Template inferArgMismatchTemplate = new Template(MethodCheckDiag.ARG_MISMATCH.regex(), skip, skip) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4459 |
@Override |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4460 |
boolean matches(Object o) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4461 |
if (!super.matches(o)) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4462 |
return false; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4463 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4464 |
JCDiagnostic d = (JCDiagnostic)o; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4465 |
@SuppressWarnings("unchecked") |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4466 |
List<Type> tvars = (List<Type>)d.getArgs()[0]; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4467 |
return !containsAny(d, tvars); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4468 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4469 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4470 |
BiPredicate<Object, List<Type>> containsPredicate = (o, ts) -> { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4471 |
if (o instanceof Type) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4472 |
return ((Type)o).containsAny(ts); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4473 |
} else if (o instanceof JCDiagnostic) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4474 |
return containsAny((JCDiagnostic)o, ts); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4475 |
} else { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4476 |
return false; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4477 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4478 |
}; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4479 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4480 |
boolean containsAny(JCDiagnostic d, List<Type> ts) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4481 |
return Stream.of(d.getArgs()) |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4482 |
.anyMatch(o -> containsPredicate.test(o, ts)); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4483 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4484 |
}; |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4485 |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4486 |
/** rewriter map used for method resolution simplification */ |
22163 | 4487 |
static final Map<Template, DiagnosticRewriter> rewriters = new LinkedHashMap<>(); |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4488 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4489 |
static { |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4490 |
rewriters.put(argMismatchTemplate, new ArgMismatchRewriter(0)); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4491 |
rewriters.put(inferArgMismatchTemplate, new ArgMismatchRewriter(1)); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4492 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4493 |
|
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4494 |
/** |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4495 |
* Main entry point for diagnostic rewriting - given a diagnostic, see if any templates matches it, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4496 |
* and rewrite it accordingly. |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4497 |
*/ |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4498 |
static JCDiagnostic rewrite(JCDiagnostic.Factory diags, DiagnosticPosition pos, DiagnosticSource source, |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4499 |
DiagnosticType dkind, JCDiagnostic d) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4500 |
for (Map.Entry<Template, DiagnosticRewriter> _entry : rewriters.entrySet()) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4501 |
if (_entry.getKey().matches(d)) { |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4502 |
JCDiagnostic simpleDiag = |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4503 |
_entry.getValue().rewriteDiagnostic(diags, pos, source, dkind, d); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4504 |
simpleDiag.setFlag(DiagnosticFlag.COMPRESSED); |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4505 |
return simpleDiag; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4506 |
} |
28331
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4507 |
} |
43ed6b2e0e3b
8067883: Javac misses some opportunities for diagnostic simplification
mcimadamore
parents:
27849
diff
changeset
|
4508 |
return null; |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4509 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4510 |
} |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16975
diff
changeset
|
4511 |
|
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4512 |
enum MethodResolutionPhase { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4513 |
BASIC(false, false), |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4514 |
BOX(true, false), |
14444 | 4515 |
VARARITY(true, true) { |
4516 |
@Override |
|
4517 |
public Symbol mergeResults(Symbol bestSoFar, Symbol sym) { |
|
26533
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4518 |
//Check invariants (see {@code LookupHelper.shouldStop}) |
29774
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
4519 |
Assert.check(bestSoFar.kind.isResolutionError() && bestSoFar.kind != AMBIGUOUS); |
9d438163db79
8075184: javac is mistakenly considering an missing enclosing instance error as an overload error
vromero
parents:
29554
diff
changeset
|
4520 |
if (!sym.kind.isResolutionError()) { |
26533
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4521 |
//varargs resolution successful |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4522 |
return sym; |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4523 |
} else { |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4524 |
//pick best error |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4525 |
switch (bestSoFar.kind) { |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4526 |
case WRONG_MTH: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4527 |
case WRONG_MTHS: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4528 |
//Override previous errors if they were caused by argument mismatch. |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4529 |
//This generally means preferring current symbols - but we need to pay |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4530 |
//attention to the fact that the varargs lookup returns 'less' candidates |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4531 |
//than the previous rounds, and adjust that accordingly. |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4532 |
switch (sym.kind) { |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4533 |
case WRONG_MTH: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4534 |
//if the previous round matched more than one method, return that |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4535 |
//result instead |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4536 |
return bestSoFar.kind == WRONG_MTHS ? |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4537 |
bestSoFar : sym; |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4538 |
case ABSENT_MTH: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4539 |
//do not override erroneous symbol if the arity lookup did not |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4540 |
//match any method |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4541 |
return bestSoFar; |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4542 |
case WRONG_MTHS: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4543 |
default: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4544 |
//safe to override |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4545 |
return sym; |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4546 |
} |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4547 |
default: |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4548 |
//otherwise, return first error |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4549 |
return bestSoFar; |
8fba085fbdbf
8055514: Wrong, confusing error when non-static varargs referenced in static context
mcimadamore
parents:
26266
diff
changeset
|
4550 |
} |
14444 | 4551 |
} |
4552 |
} |
|
4553 |
}; |
|
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4554 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14724
diff
changeset
|
4555 |
final boolean isBoxingRequired; |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14724
diff
changeset
|
4556 |
final boolean isVarargsRequired; |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4557 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4558 |
MethodResolutionPhase(boolean isBoxingRequired, boolean isVarargsRequired) { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4559 |
this.isBoxingRequired = isBoxingRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4560 |
this.isVarargsRequired = isVarargsRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4561 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4562 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4563 |
public boolean isBoxingRequired() { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4564 |
return isBoxingRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4565 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4566 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4567 |
public boolean isVarargsRequired() { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4568 |
return isVarargsRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4569 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4570 |
|
14444 | 4571 |
public Symbol mergeResults(Symbol prev, Symbol sym) { |
4572 |
return sym; |
|
4573 |
} |
|
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4574 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4575 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4576 |
final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY); |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4577 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4578 |
/** |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4579 |
* A resolution context is used to keep track of intermediate results of |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4580 |
* overload resolution, such as list of method that are not applicable |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4581 |
* (used to generate more precise diagnostics) and so on. Resolution contexts |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4582 |
* can be nested - this means that when each overload resolution routine should |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4583 |
* work within the resolution context it created. |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4584 |
*/ |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4585 |
class MethodResolutionContext { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4586 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4587 |
private List<Candidate> candidates = List.nil(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4588 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4589 |
MethodResolutionPhase step = null; |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4590 |
|
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
4591 |
MethodCheck methodCheck = resolveMethodCheck; |
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16323
diff
changeset
|
4592 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4593 |
private boolean internalResolution = false; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4594 |
private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
4595 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4596 |
void addInapplicableCandidate(Symbol sym, JCDiagnostic details) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4597 |
Candidate c = new Candidate(currentResolutionContext.step, sym, details, null); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4598 |
candidates = candidates.append(c); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4599 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4600 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4601 |
void addApplicableCandidate(Symbol sym, Type mtype) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4602 |
Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4603 |
candidates = candidates.append(c); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4604 |
} |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
4605 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
4606 |
DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) { |
23132
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
4607 |
DeferredAttrContext parent = (pendingResult == null) |
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
4608 |
? deferredAttr.emptyDeferredAttrContext |
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
4609 |
: pendingResult.checkContext.deferredAttrContext(); |
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
4610 |
return deferredAttr.new DeferredAttrContext(attrMode, sym, step, |
00a059740d87
8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents:
23105
diff
changeset
|
4611 |
inferenceContext, parent, warn); |
15037
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
4612 |
} |
8ba16ac61b1a
8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents:
14957
diff
changeset
|
4613 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4614 |
/** |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4615 |
* This class represents an overload resolution candidate. There are two |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4616 |
* kinds of candidates: applicable methods and inapplicable methods; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4617 |
* applicable methods have a pointer to the instantiated method type, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4618 |
* while inapplicable candidates contain further details about the |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4619 |
* reason why the method has been considered inapplicable. |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4620 |
*/ |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
16294
diff
changeset
|
4621 |
@SuppressWarnings("overrides") |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4622 |
class Candidate { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4623 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4624 |
final MethodResolutionPhase step; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4625 |
final Symbol sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4626 |
final JCDiagnostic details; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4627 |
final Type mtype; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4628 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4629 |
private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details, Type mtype) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4630 |
this.step = step; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4631 |
this.sym = sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4632 |
this.details = details; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4633 |
this.mtype = mtype; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4634 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4635 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4636 |
@Override |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4637 |
public boolean equals(Object o) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4638 |
if (o instanceof Candidate) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4639 |
Symbol s1 = this.sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4640 |
Symbol s2 = ((Candidate)o).sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4641 |
if ((s1 != s2 && |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4642 |
(s1.overrides(s2, s1.owner.type.tsym, types, false) || |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4643 |
(s2.overrides(s1, s2.owner.type.tsym, types, false)))) || |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
4644 |
((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner)) |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4645 |
return true; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4646 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4647 |
return false; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4648 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4649 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4650 |
boolean isApplicable() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4651 |
return mtype != null; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4652 |
} |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4653 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4654 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4655 |
DeferredAttr.AttrMode attrMode() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4656 |
return attrMode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4657 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4658 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4659 |
boolean internal() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4660 |
return internalResolution; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14056
diff
changeset
|
4661 |
} |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
4662 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4663 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
4664 |
MethodResolutionContext currentResolutionContext = null; |
10 | 4665 |
} |