author | mcimadamore |
Tue, 25 Sep 2012 11:52:37 +0100 | |
changeset 14045 | c66c0a81c4ab |
parent 13844 | 56339cf983a3 |
child 14047 | 7c7a5611cf76 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
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.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
30 |
import com.sun.tools.javac.code.Type.*; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
31 |
import com.sun.tools.javac.code.Symbol.*; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
32 |
import com.sun.tools.javac.comp.Attr.ResultInfo; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
33 |
import com.sun.tools.javac.comp.Check.CheckContext; |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
34 |
import com.sun.tools.javac.comp.Resolve.MethodResolutionContext.Candidate; |
10 | 35 |
import com.sun.tools.javac.jvm.*; |
36 |
import com.sun.tools.javac.tree.*; |
|
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
37 |
import com.sun.tools.javac.tree.JCTree.*; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
38 |
import com.sun.tools.javac.util.*; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
39 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
40 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
41 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
10 | 42 |
|
14045 | 43 |
import java.util.ArrayList; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
44 |
import java.util.Arrays; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
45 |
import java.util.Collection; |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
46 |
import java.util.EnumMap; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
47 |
import java.util.EnumSet; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
48 |
import java.util.HashSet; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
49 |
import java.util.Map; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
50 |
import java.util.Set; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
51 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
52 |
import javax.lang.model.element.ElementVisitor; |
10 | 53 |
|
54 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 55 |
import static com.sun.tools.javac.code.Flags.BLOCK; |
10 | 56 |
import static com.sun.tools.javac.code.Kinds.*; |
10950 | 57 |
import static com.sun.tools.javac.code.Kinds.ERRONEOUS; |
10 | 58 |
import static com.sun.tools.javac.code.TypeTags.*; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
59 |
import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*; |
10950 | 60 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
14045 | 61 |
import java.util.Iterator; |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
62 |
|
10 | 63 |
/** Helper class for name resolution, used mostly by the attribution phase. |
64 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
65 |
* <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
|
66 |
* If you write code that depends on this, you do so at your own risk. |
10 | 67 |
* This code and its internal interfaces are subject to change or |
68 |
* deletion without notice.</b> |
|
69 |
*/ |
|
70 |
public class Resolve { |
|
71 |
protected static final Context.Key<Resolve> resolveKey = |
|
72 |
new Context.Key<Resolve>(); |
|
73 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
74 |
Names names; |
10 | 75 |
Log log; |
76 |
Symtab syms; |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
77 |
Attr attr; |
10 | 78 |
Check chk; |
79 |
Infer infer; |
|
80 |
ClassReader reader; |
|
81 |
TreeInfo treeinfo; |
|
82 |
Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
83 |
JCDiagnostic.Factory diags; |
10 | 84 |
public final boolean boxingEnabled; // = source.allowBoxing(); |
85 |
public final boolean varargsEnabled; // = source.allowVarargs(); |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
86 |
public final boolean allowMethodHandles; |
10 | 87 |
private final boolean debugResolve; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
88 |
final EnumSet<VerboseResolutionMode> verboseResolutionMode; |
10 | 89 |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
90 |
Scope polymorphicSignatureScope; |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
91 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
92 |
protected Resolve(Context context) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
93 |
context.put(resolveKey, this); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
94 |
syms = Symtab.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
95 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
96 |
varNotFound = new |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
97 |
SymbolNotFoundError(ABSENT_VAR); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
98 |
wrongMethod = new |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
99 |
InapplicableSymbolError(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
100 |
wrongMethods = new |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
101 |
InapplicableSymbolsError(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
102 |
methodNotFound = new |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
103 |
SymbolNotFoundError(ABSENT_MTH); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
104 |
typeNotFound = new |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
105 |
SymbolNotFoundError(ABSENT_TYP); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
106 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
107 |
names = Names.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
108 |
log = Log.instance(context); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
109 |
attr = Attr.instance(context); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
110 |
chk = Check.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
111 |
infer = Infer.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
112 |
reader = ClassReader.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
113 |
treeinfo = TreeInfo.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
114 |
types = Types.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
115 |
diags = JCDiagnostic.Factory.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
116 |
Source source = Source.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
117 |
boxingEnabled = source.allowBoxing(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
118 |
varargsEnabled = source.allowVarargs(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
119 |
Options options = Options.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
120 |
debugResolve = options.isSet("debugresolve"); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
121 |
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
122 |
Target target = Target.instance(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
123 |
allowMethodHandles = target.hasMethodHandles(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
124 |
polymorphicSignatureScope = new Scope(syms.noSymbol); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
125 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
126 |
inapplicableMethodException = new InapplicableMethodException(diags); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
127 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
128 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
129 |
/** error symbols, which are returned when resolution fails |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
130 |
*/ |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
131 |
private final SymbolNotFoundError varNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
132 |
private final InapplicableSymbolError wrongMethod; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
133 |
private final InapplicableSymbolsError wrongMethods; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
134 |
private final SymbolNotFoundError methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
135 |
private final SymbolNotFoundError typeNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
136 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
137 |
public static Resolve instance(Context context) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
138 |
Resolve instance = context.get(resolveKey); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
139 |
if (instance == null) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
140 |
instance = new Resolve(context); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
141 |
return instance; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
142 |
} |
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 |
// <editor-fold defaultstate="collapsed" desc="Verbose resolution diagnostics support"> |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
145 |
enum VerboseResolutionMode { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
146 |
SUCCESS("success"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
147 |
FAILURE("failure"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
148 |
APPLICABLE("applicable"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
149 |
INAPPLICABLE("inapplicable"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
150 |
DEFERRED_INST("deferred-inference"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
151 |
PREDEF("predef"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
152 |
OBJECT_INIT("object-init"), |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
153 |
INTERNAL("internal"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
154 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
155 |
String opt; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
156 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
157 |
private VerboseResolutionMode(String opt) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
158 |
this.opt = opt; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
159 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
160 |
|
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
161 |
static EnumSet<VerboseResolutionMode> getVerboseResolutionMode(Options opts) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
162 |
String s = opts.get("verboseResolution"); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
163 |
EnumSet<VerboseResolutionMode> res = EnumSet.noneOf(VerboseResolutionMode.class); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
164 |
if (s == null) return res; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
165 |
if (s.contains("all")) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
166 |
res = EnumSet.allOf(VerboseResolutionMode.class); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
167 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
168 |
Collection<String> args = Arrays.asList(s.split(",")); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
169 |
for (VerboseResolutionMode mode : values()) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
170 |
if (args.contains(mode.opt)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
171 |
res.add(mode); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
172 |
} else if (args.contains("-" + mode.opt)) { |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
173 |
res.remove(mode); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
174 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
175 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
176 |
return res; |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
177 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
178 |
} |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
179 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
180 |
void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
181 |
List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
182 |
boolean success = bestSoFar.kind < ERRONEOUS; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
183 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
184 |
if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
185 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
186 |
} else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
187 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
188 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
189 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
190 |
if (bestSoFar.name == names.init && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
191 |
bestSoFar.owner == syms.objectType.tsym && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
192 |
!verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
193 |
return; //skip diags for Object constructor resolution |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
194 |
} else if (site == syms.predefClass.type && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
195 |
!verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
196 |
return; //skip spurious diags for predef symbols (i.e. operators) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
197 |
} else if (currentResolutionContext.internalResolution && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
198 |
!verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
199 |
return; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
200 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
201 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
202 |
int pos = 0; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
203 |
int mostSpecificPos = -1; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
204 |
ListBuffer<JCDiagnostic> subDiags = ListBuffer.lb(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
205 |
for (Candidate c : currentResolutionContext.candidates) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
206 |
if (currentResolutionContext.step != c.step || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
207 |
(c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
208 |
(!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
209 |
continue; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
210 |
} else { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
211 |
subDiags.append(c.isApplicable() ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
212 |
getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
213 |
getVerboseInapplicableCandidateDiag(pos, c.sym, c.details)); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
214 |
if (c.sym == bestSoFar) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
215 |
mostSpecificPos = pos; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
216 |
pos++; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
217 |
} |
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 |
String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1"; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
220 |
JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
221 |
site.tsym, mostSpecificPos, currentResolutionContext.step, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
222 |
methodArguments(argtypes), methodArguments(typeargtypes)); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
223 |
JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList()); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
224 |
log.report(d); |
10 | 225 |
} |
226 |
||
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
227 |
JCDiagnostic getVerboseApplicableCandidateDiag(int pos, Symbol sym, Type inst) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
228 |
JCDiagnostic subDiag = null; |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
229 |
if (sym.type.tag == FORALL) { |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
230 |
subDiag = diags.fragment("partial.inst.sig", inst); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
231 |
} |
10 | 232 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
233 |
String key = subDiag == null ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
234 |
"applicable.method.found" : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
235 |
"applicable.method.found.1"; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
236 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
237 |
return diags.fragment(key, pos, sym, subDiag); |
10 | 238 |
} |
239 |
||
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
240 |
JCDiagnostic getVerboseInapplicableCandidateDiag(int pos, Symbol sym, JCDiagnostic subDiag) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
241 |
return diags.fragment("not.applicable.method.found", pos, sym, subDiag); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
242 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
243 |
// </editor-fold> |
10 | 244 |
|
245 |
/* ************************************************************************ |
|
246 |
* Identifier resolution |
|
247 |
*************************************************************************/ |
|
248 |
||
249 |
/** An environment is "static" if its static level is greater than |
|
250 |
* the one of its outer environment |
|
251 |
*/ |
|
252 |
static boolean isStatic(Env<AttrContext> env) { |
|
253 |
return env.info.staticLevel > env.outer.info.staticLevel; |
|
254 |
} |
|
255 |
||
256 |
/** An environment is an "initializer" if it is a constructor or |
|
257 |
* an instance initializer. |
|
258 |
*/ |
|
259 |
static boolean isInitializer(Env<AttrContext> env) { |
|
260 |
Symbol owner = env.info.scope.owner; |
|
261 |
return owner.isConstructor() || |
|
262 |
owner.owner.kind == TYP && |
|
263 |
(owner.kind == VAR || |
|
264 |
owner.kind == MTH && (owner.flags() & BLOCK) != 0) && |
|
265 |
(owner.flags() & STATIC) == 0; |
|
266 |
} |
|
267 |
||
268 |
/** Is class accessible in given evironment? |
|
269 |
* @param env The current environment. |
|
270 |
* @param c The class whose accessibility is checked. |
|
271 |
*/ |
|
272 |
public boolean isAccessible(Env<AttrContext> env, TypeSymbol c) { |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
273 |
return isAccessible(env, c, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
274 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
275 |
|
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
276 |
public boolean isAccessible(Env<AttrContext> env, TypeSymbol c, boolean checkInner) { |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
277 |
boolean isAccessible = false; |
10 | 278 |
switch ((short)(c.flags() & AccessFlags)) { |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
279 |
case PRIVATE: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
280 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
281 |
env.enclClass.sym.outermostClass() == |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
282 |
c.owner.outermostClass(); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
283 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
284 |
case 0: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
285 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
286 |
env.toplevel.packge == c.owner // fast special case |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
287 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
288 |
env.toplevel.packge == c.packge() |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
289 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
290 |
// Hack: this case is added since synthesized default constructors |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
291 |
// of anonymous classes should be allowed to access |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
292 |
// classes which would be inaccessible otherwise. |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
293 |
env.enclMethod != null && |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
294 |
(env.enclMethod.mods.flags & ANONCONSTR) != 0; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
295 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
296 |
default: // error recovery |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
297 |
case PUBLIC: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
298 |
isAccessible = true; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
299 |
break; |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
300 |
case PROTECTED: |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
301 |
isAccessible = |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
302 |
env.toplevel.packge == c.owner // fast special case |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
303 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
304 |
env.toplevel.packge == c.packge() |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
305 |
|| |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
306 |
isInnerSubClass(env.enclClass.sym, c.owner); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
307 |
break; |
10 | 308 |
} |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
309 |
return (checkInner == false || c.type.getEnclosingType() == Type.noType) ? |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
310 |
isAccessible : |
7637 | 311 |
isAccessible && isAccessible(env, c.type.getEnclosingType(), checkInner); |
10 | 312 |
} |
313 |
//where |
|
314 |
/** Is given class a subclass of given base class, or an inner class |
|
315 |
* of a subclass? |
|
316 |
* Return null if no such class exists. |
|
317 |
* @param c The class which is the subclass or is contained in it. |
|
318 |
* @param base The base class |
|
319 |
*/ |
|
320 |
private boolean isInnerSubClass(ClassSymbol c, Symbol base) { |
|
321 |
while (c != null && !c.isSubClass(base, types)) { |
|
322 |
c = c.owner.enclClass(); |
|
323 |
} |
|
324 |
return c != null; |
|
325 |
} |
|
326 |
||
327 |
boolean isAccessible(Env<AttrContext> env, Type t) { |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
328 |
return isAccessible(env, t, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
329 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
330 |
|
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
331 |
boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) { |
10 | 332 |
return (t.tag == ARRAY) |
333 |
? isAccessible(env, types.elemtype(t)) |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
334 |
: isAccessible(env, t.tsym, checkInner); |
10 | 335 |
} |
336 |
||
337 |
/** Is symbol accessible as a member of given type in given evironment? |
|
338 |
* @param env The current environment. |
|
339 |
* @param site The type of which the tested symbol is regarded |
|
340 |
* as a member. |
|
341 |
* @param sym The symbol. |
|
342 |
*/ |
|
343 |
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
|
344 |
return isAccessible(env, site, sym, false); |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
345 |
} |
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
346 |
public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) { |
10 | 347 |
if (sym.name == names.init && sym.owner != site.tsym) return false; |
348 |
switch ((short)(sym.flags() & AccessFlags)) { |
|
349 |
case PRIVATE: |
|
350 |
return |
|
351 |
(env.enclClass.sym == sym.owner // fast special case |
|
352 |
|| |
|
353 |
env.enclClass.sym.outermostClass() == |
|
354 |
sym.owner.outermostClass()) |
|
355 |
&& |
|
356 |
sym.isInheritedIn(site.tsym, types); |
|
357 |
case 0: |
|
358 |
return |
|
359 |
(env.toplevel.packge == sym.owner.owner // fast special case |
|
360 |
|| |
|
361 |
env.toplevel.packge == sym.packge()) |
|
362 |
&& |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
363 |
isAccessible(env, site, checkInner) |
10 | 364 |
&& |
2511 | 365 |
sym.isInheritedIn(site.tsym, types) |
366 |
&& |
|
367 |
notOverriddenIn(site, sym); |
|
10 | 368 |
case PROTECTED: |
369 |
return |
|
370 |
(env.toplevel.packge == sym.owner.owner // fast special case |
|
371 |
|| |
|
372 |
env.toplevel.packge == sym.packge() |
|
373 |
|| |
|
374 |
isProtectedAccessible(sym, env.enclClass.sym, site) |
|
375 |
|| |
|
376 |
// OK to select instance method or field from 'super' or type name |
|
377 |
// (but type names should be disallowed elsewhere!) |
|
378 |
env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP) |
|
379 |
&& |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
380 |
isAccessible(env, site, checkInner) |
10 | 381 |
&& |
2511 | 382 |
notOverriddenIn(site, sym); |
10 | 383 |
default: // this case includes erroneous combinations as well |
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
6721
diff
changeset
|
384 |
return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym); |
2511 | 385 |
} |
386 |
} |
|
387 |
//where |
|
388 |
/* `sym' is accessible only if not overridden by |
|
389 |
* another symbol which is a member of `site' |
|
390 |
* (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
|
391 |
* 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
|
392 |
* cannot be overridden (e.g. MH.invokeExact(Object[])). |
2511 | 393 |
*/ |
394 |
private boolean notOverriddenIn(Type site, Symbol sym) { |
|
395 |
if (sym.kind != MTH || sym.isConstructor() || sym.isStatic()) |
|
396 |
return true; |
|
397 |
else { |
|
398 |
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
|
399 |
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
|
400 |
!types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym))); |
10 | 401 |
} |
402 |
} |
|
403 |
//where |
|
404 |
/** Is given protected symbol accessible if it is selected from given site |
|
405 |
* and the selection takes place in given class? |
|
406 |
* @param sym The symbol with protected access |
|
407 |
* @param c The class where the access takes place |
|
408 |
* @site The type of the qualifier |
|
409 |
*/ |
|
410 |
private |
|
411 |
boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { |
|
412 |
while (c != null && |
|
413 |
!(c.isSubClass(sym.owner, types) && |
|
414 |
(c.flags() & INTERFACE) == 0 && |
|
415 |
// In JLS 2e 6.6.2.1, the subclass restriction applies |
|
416 |
// only to instance fields and methods -- types are excluded |
|
417 |
// regardless of whether they are declared 'static' or not. |
|
418 |
((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types)))) |
|
419 |
c = c.owner.enclClass(); |
|
420 |
return c != null; |
|
421 |
} |
|
422 |
||
423 |
/** Try to instantiate the type of a method so that it fits |
|
424 |
* given type arguments and argument types. If succesful, return |
|
425 |
* the method's instantiated type, else return null. |
|
426 |
* The instantiation will take into account an additional leading |
|
427 |
* formal parameter if the method is an instance method seen as a member |
|
428 |
* of un underdetermined site In this case, we treat site as an additional |
|
429 |
* parameter and the parameters of the class containing the method as |
|
430 |
* additional type variables that get instantiated. |
|
431 |
* |
|
432 |
* @param env The current environment |
|
433 |
* @param site The type of which the method is a member. |
|
434 |
* @param m The method symbol. |
|
435 |
* @param argtypes The invocation's given value arguments. |
|
436 |
* @param typeargtypes The invocation's given type arguments. |
|
437 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
438 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
439 |
*/ |
|
440 |
Type rawInstantiate(Env<AttrContext> env, |
|
441 |
Type site, |
|
442 |
Symbol m, |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
443 |
ResultInfo resultInfo, |
10 | 444 |
List<Type> argtypes, |
445 |
List<Type> typeargtypes, |
|
446 |
boolean allowBoxing, |
|
447 |
boolean useVarargs, |
|
448 |
Warner warn) |
|
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2723
diff
changeset
|
449 |
throws Infer.InferenceException { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
450 |
if (useVarargs && (m.flags() & VARARGS) == 0) |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
451 |
throw inapplicableMethodException.setMessage(); |
10 | 452 |
Type mt = types.memberType(site, m); |
453 |
||
454 |
// tvars is the list of formal type variables for which type arguments |
|
455 |
// need to inferred. |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
456 |
List<Type> tvars = List.nil(); |
10 | 457 |
if (typeargtypes == null) typeargtypes = List.nil(); |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
458 |
if (mt.tag != FORALL && typeargtypes.nonEmpty()) { |
10 | 459 |
// 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
|
460 |
// which is fine, see JLS 15.12.2.1 |
10 | 461 |
} else if (mt.tag == FORALL && typeargtypes.nonEmpty()) { |
462 |
ForAll pmt = (ForAll) mt; |
|
463 |
if (typeargtypes.length() != pmt.tvars.length()) |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
464 |
throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args |
10 | 465 |
// Check type arguments are within bounds |
466 |
List<Type> formals = pmt.tvars; |
|
467 |
List<Type> actuals = typeargtypes; |
|
468 |
while (formals.nonEmpty() && actuals.nonEmpty()) { |
|
469 |
List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head), |
|
470 |
pmt.tvars, typeargtypes); |
|
471 |
for (; bounds.nonEmpty(); bounds = bounds.tail) |
|
472 |
if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn)) |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
473 |
throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds); |
10 | 474 |
formals = formals.tail; |
475 |
actuals = actuals.tail; |
|
476 |
} |
|
477 |
mt = types.subst(pmt.qtype, pmt.tvars, typeargtypes); |
|
478 |
} else if (mt.tag == FORALL) { |
|
479 |
ForAll pmt = (ForAll) mt; |
|
480 |
List<Type> tvars1 = types.newInstances(pmt.tvars); |
|
481 |
tvars = tvars.appendList(tvars1); |
|
482 |
mt = types.subst(pmt.qtype, pmt.tvars, tvars1); |
|
483 |
} |
|
484 |
||
485 |
// 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
|
486 |
boolean instNeeded = tvars.tail != null; /*inlined: tvars.nonEmpty()*/ |
10 | 487 |
for (List<Type> l = argtypes; |
488 |
l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded; |
|
489 |
l = l.tail) { |
|
490 |
if (l.head.tag == FORALL) instNeeded = true; |
|
491 |
} |
|
492 |
||
493 |
if (instNeeded) |
|
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
494 |
return infer.instantiateMethod(env, |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
495 |
tvars, |
10 | 496 |
(MethodType)mt, |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
497 |
resultInfo, |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5520
diff
changeset
|
498 |
m, |
10 | 499 |
argtypes, |
500 |
allowBoxing, |
|
501 |
useVarargs, |
|
502 |
warn); |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
503 |
|
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
504 |
checkRawArgumentsAcceptable(env, argtypes, mt.getParameterTypes(), |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
505 |
allowBoxing, useVarargs, warn); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
506 |
return mt; |
10 | 507 |
} |
508 |
||
509 |
/** Same but returns null instead throwing a NoInstanceException |
|
510 |
*/ |
|
511 |
Type instantiate(Env<AttrContext> env, |
|
512 |
Type site, |
|
513 |
Symbol m, |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
514 |
ResultInfo resultInfo, |
10 | 515 |
List<Type> argtypes, |
516 |
List<Type> typeargtypes, |
|
517 |
boolean allowBoxing, |
|
518 |
boolean useVarargs, |
|
519 |
Warner warn) { |
|
520 |
try { |
|
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
521 |
return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, |
10 | 522 |
allowBoxing, useVarargs, warn); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
523 |
} catch (InapplicableMethodException ex) { |
10 | 524 |
return null; |
525 |
} |
|
526 |
} |
|
527 |
||
528 |
/** Check if a parameter list accepts a list of args. |
|
529 |
*/ |
|
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
530 |
boolean argumentsAcceptable(Env<AttrContext> env, |
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
531 |
List<Type> argtypes, |
10 | 532 |
List<Type> formals, |
533 |
boolean allowBoxing, |
|
534 |
boolean useVarargs, |
|
535 |
Warner warn) { |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
536 |
try { |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
537 |
checkRawArgumentsAcceptable(env, argtypes, formals, allowBoxing, useVarargs, warn); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
538 |
return true; |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
539 |
} catch (InapplicableMethodException ex) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
540 |
return false; |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
541 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
542 |
} |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
543 |
/** |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
544 |
* A check handler is used by the main method applicability routine in order |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
545 |
* to handle specific method applicability failures. It is assumed that a class |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
546 |
* implementing this interface should throw exceptions that are a subtype of |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
547 |
* InapplicableMethodException (see below). Such exception will terminate the |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
548 |
* method applicability check and propagate important info outwards (for the |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
549 |
* purpose of generating better diagnostics). |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
550 |
*/ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
551 |
interface MethodCheckHandler { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
552 |
/* The number of actuals and formals differ */ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
553 |
InapplicableMethodException arityMismatch(); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
554 |
/* An actual argument type does not conform to the corresponding formal type */ |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
555 |
InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details); |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
556 |
/* The element type of a varargs is not accessible in the current context */ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
557 |
InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
558 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
559 |
|
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
560 |
/** |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
561 |
* Basic method check handler used within Resolve - all methods end up |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
562 |
* throwing InapplicableMethodException; a diagnostic fragment that describes |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
563 |
* the cause as to why the method is not applicable is set on the exception |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
564 |
* before it is thrown. |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
565 |
*/ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
566 |
MethodCheckHandler resolveHandler = new MethodCheckHandler() { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
567 |
public InapplicableMethodException arityMismatch() { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
568 |
return inapplicableMethodException.setMessage("arg.length.mismatch"); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
569 |
} |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
570 |
public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) { |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
571 |
String key = varargs ? |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
572 |
"varargs.argument.mismatch" : |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
573 |
"no.conforming.assignment.exists"; |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
574 |
return inapplicableMethodException.setMessage(key, |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
575 |
details); |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
576 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
577 |
public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
578 |
return inapplicableMethodException.setMessage("inaccessible.varargs.type", |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
579 |
expected, Kinds.kindName(location), location); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
580 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
581 |
}; |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
582 |
|
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
583 |
void checkRawArgumentsAcceptable(Env<AttrContext> env, |
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
584 |
List<Type> argtypes, |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
585 |
List<Type> formals, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
586 |
boolean allowBoxing, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
587 |
boolean useVarargs, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
588 |
Warner warn) { |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
589 |
checkRawArgumentsAcceptable(env, List.<Type>nil(), argtypes, formals, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
590 |
allowBoxing, useVarargs, warn, resolveHandler); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
591 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
592 |
|
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
593 |
/** |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
594 |
* Main method applicability routine. Given a list of actual types A, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
595 |
* a list of formal types F, determines whether the types in A are |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
596 |
* compatible (by method invocation conversion) with the types in F. |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
597 |
* |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
598 |
* Since this routine is shared between overload resolution and method |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
599 |
* type-inference, it is crucial that actual types are converted to the |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
600 |
* corresponding 'undet' form (i.e. where inference variables are replaced |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
601 |
* with undetvars) so that constraints can be propagated and collected. |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
602 |
* |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
603 |
* Moreover, if one or more types in A is a poly type, this routine calls |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
604 |
* Infer.instantiateArg in order to complete the poly type (this might involve |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
605 |
* deferred attribution). |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
606 |
* |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
607 |
* A method check handler (see above) is used in order to report errors. |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
608 |
*/ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
609 |
List<Type> checkRawArgumentsAcceptable(Env<AttrContext> env, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
610 |
List<Type> undetvars, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
611 |
List<Type> argtypes, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
612 |
List<Type> formals, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
613 |
boolean allowBoxing, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
614 |
boolean useVarargs, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
615 |
Warner warn, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
616 |
MethodCheckHandler handler) { |
10 | 617 |
Type varargsFormal = useVarargs ? formals.last() : null; |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
618 |
ListBuffer<Type> checkedArgs = ListBuffer.lb(); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
619 |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
620 |
if (varargsFormal == null && |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
621 |
argtypes.size() != formals.size()) { |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
622 |
throw handler.arityMismatch(); // not enough args |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
623 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
624 |
|
10 | 625 |
while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
626 |
ResultInfo resultInfo = methodCheckResult(formals.head, allowBoxing, false, undetvars, handler, warn); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
627 |
checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); |
10 | 628 |
argtypes = argtypes.tail; |
629 |
formals = formals.tail; |
|
630 |
} |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
631 |
|
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
632 |
if (formals.head != varargsFormal) { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
633 |
throw handler.arityMismatch(); // not enough args |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
634 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
635 |
|
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
636 |
if (useVarargs) { |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
637 |
//note: if applicability check is triggered by most specific test, |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
638 |
//the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
9720
bc06a797f393
7042566: Regression: new ambiguity between varargs method
mcimadamore
parents:
9303
diff
changeset
|
639 |
Type elt = types.elemtype(varargsFormal); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
640 |
while (argtypes.nonEmpty()) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
641 |
ResultInfo resultInfo = methodCheckResult(elt, allowBoxing, true, undetvars, handler, warn); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
642 |
checkedArgs.append(resultInfo.check(env.tree.pos(), argtypes.head)); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
643 |
argtypes = argtypes.tail; |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
644 |
} |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
645 |
//check varargs element type accessibility |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
646 |
if (undetvars.isEmpty() && !isAccessible(env, elt)) { |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
647 |
Symbol location = env.enclClass.sym; |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
648 |
throw handler.inaccessibleVarargs(location, elt); |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
649 |
} |
10 | 650 |
} |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
10950
diff
changeset
|
651 |
return checkedArgs.toList(); |
10 | 652 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
653 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
654 |
/** |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
655 |
* 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
|
656 |
* context might contain inference variables. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
657 |
*/ |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
658 |
abstract class MethodCheckContext implements CheckContext { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
659 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
660 |
MethodCheckHandler handler; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
661 |
boolean useVarargs; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
662 |
List<Type> undetvars; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
663 |
Warner rsWarner; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
664 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
665 |
public MethodCheckContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
666 |
this.handler = handler; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
667 |
this.useVarargs = useVarargs; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
668 |
this.undetvars = undetvars; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
669 |
this.rsWarner = rsWarner; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
670 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
671 |
|
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
672 |
public void report(DiagnosticPosition pos, JCDiagnostic details) { |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
673 |
throw handler.argumentMismatch(useVarargs, details); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
674 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
675 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
676 |
public Warner checkWarner(DiagnosticPosition pos, Type found, Type req) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
677 |
return rsWarner; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
678 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
679 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
680 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
681 |
/** |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
682 |
* Subclass of method check context class that implements strict method conversion. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
683 |
* Strict method conversion checks compatibility between types using subtyping tests. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
684 |
*/ |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
685 |
class StrictMethodContext extends MethodCheckContext { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
686 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
687 |
public StrictMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
688 |
super(handler, useVarargs, undetvars, rsWarner); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
689 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
690 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
691 |
public boolean compatible(Type found, Type req, Warner warn) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
692 |
return types.isSubtypeUnchecked(found, infer.asUndetType(req, undetvars), warn); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
693 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
694 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
695 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
696 |
/** |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
697 |
* Subclass of method check context class that implements loose method conversion. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
698 |
* Loose method conversion checks compatibility between types using method conversion tests. |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
699 |
*/ |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
700 |
class LooseMethodContext extends MethodCheckContext { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
701 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
702 |
public LooseMethodContext(MethodCheckHandler handler, boolean useVarargs, List<Type> undetvars, Warner rsWarner) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
703 |
super(handler, useVarargs, undetvars, rsWarner); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
704 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
705 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
706 |
public boolean compatible(Type found, Type req, Warner warn) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
707 |
return types.isConvertible(found, infer.asUndetType(req, undetvars), warn); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
708 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
709 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
710 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
711 |
/** |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
712 |
* Create a method check context to be used during method applicability check |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
713 |
*/ |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
714 |
ResultInfo methodCheckResult(Type to, boolean allowBoxing, boolean useVarargs, |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
715 |
List<Type> undetvars, MethodCheckHandler methodHandler, Warner rsWarner) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
716 |
MethodCheckContext checkContext = allowBoxing ? |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
717 |
new LooseMethodContext(methodHandler, useVarargs, undetvars, rsWarner) : |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
718 |
new StrictMethodContext(methodHandler, useVarargs, undetvars, rsWarner); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
719 |
return attr.new ResultInfo(VAL, to, checkContext) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
720 |
@Override |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
721 |
protected Type check(DiagnosticPosition pos, Type found) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
722 |
return super.check(pos, chk.checkNonVoid(pos, types.capture(types.upperBound(found)))); |
8229
39266c1b1b0e
6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents:
8228
diff
changeset
|
723 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
724 |
}; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
725 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
726 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
727 |
public static class InapplicableMethodException extends RuntimeException { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
728 |
private static final long serialVersionUID = 0; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
729 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
730 |
JCDiagnostic diagnostic; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
731 |
JCDiagnostic.Factory diags; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
732 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
733 |
InapplicableMethodException(JCDiagnostic.Factory diags) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
734 |
this.diagnostic = null; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
735 |
this.diags = diags; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
736 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
737 |
InapplicableMethodException setMessage() { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
738 |
this.diagnostic = null; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
739 |
return this; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
740 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
741 |
InapplicableMethodException setMessage(String key) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
742 |
this.diagnostic = key != null ? diags.fragment(key) : null; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
743 |
return this; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
744 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
745 |
InapplicableMethodException setMessage(String key, Object... args) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
746 |
this.diagnostic = key != null ? diags.fragment(key, args) : null; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
747 |
return this; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
748 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
749 |
InapplicableMethodException setMessage(JCDiagnostic diag) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
750 |
this.diagnostic = diag; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
751 |
return this; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
752 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
753 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
754 |
public JCDiagnostic getDiagnostic() { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
755 |
return diagnostic; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
756 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
757 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12082
diff
changeset
|
758 |
private final InapplicableMethodException inapplicableMethodException; |
10 | 759 |
|
760 |
/* *************************************************************************** |
|
761 |
* Symbol lookup |
|
762 |
* the following naming conventions for arguments are used |
|
763 |
* |
|
764 |
* env is the environment where the symbol was mentioned |
|
765 |
* site is the type of which the symbol is a member |
|
766 |
* name is the symbol's name |
|
767 |
* if no arguments are given |
|
768 |
* argtypes are the value arguments, if we search for a method |
|
769 |
* |
|
770 |
* If no symbol was found, a ResolveError detailing the problem is returned. |
|
771 |
****************************************************************************/ |
|
772 |
||
773 |
/** Find field. Synthetic fields are always skipped. |
|
774 |
* @param env The current environment. |
|
775 |
* @param site The original type from where the selection takes place. |
|
776 |
* @param name The name of the field. |
|
777 |
* @param c The class to search for the field. This is always |
|
778 |
* a superclass or implemented interface of site's class. |
|
779 |
*/ |
|
780 |
Symbol findField(Env<AttrContext> env, |
|
781 |
Type site, |
|
782 |
Name name, |
|
783 |
TypeSymbol c) { |
|
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
10
diff
changeset
|
784 |
while (c.type.tag == TYPEVAR) |
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
10
diff
changeset
|
785 |
c = c.type.getUpperBound().tsym; |
10 | 786 |
Symbol bestSoFar = varNotFound; |
787 |
Symbol sym; |
|
788 |
Scope.Entry e = c.members().lookup(name); |
|
789 |
while (e.scope != null) { |
|
790 |
if (e.sym.kind == VAR && (e.sym.flags_field & SYNTHETIC) == 0) { |
|
791 |
return isAccessible(env, site, e.sym) |
|
792 |
? e.sym : new AccessError(env, site, e.sym); |
|
793 |
} |
|
794 |
e = e.next(); |
|
795 |
} |
|
796 |
Type st = types.supertype(c.type); |
|
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
10
diff
changeset
|
797 |
if (st != null && (st.tag == CLASS || st.tag == TYPEVAR)) { |
10 | 798 |
sym = findField(env, site, name, st.tsym); |
799 |
if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
800 |
} |
|
801 |
for (List<Type> l = types.interfaces(c.type); |
|
802 |
bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); |
|
803 |
l = l.tail) { |
|
804 |
sym = findField(env, site, name, l.head.tsym); |
|
805 |
if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS && |
|
806 |
sym.owner != bestSoFar.owner) |
|
807 |
bestSoFar = new AmbiguityError(bestSoFar, sym); |
|
808 |
else if (sym.kind < bestSoFar.kind) |
|
809 |
bestSoFar = sym; |
|
810 |
} |
|
811 |
return bestSoFar; |
|
812 |
} |
|
813 |
||
814 |
/** Resolve a field identifier, throw a fatal error if not found. |
|
815 |
* @param pos The position to use for error reporting. |
|
816 |
* @param env The environment current at the method invocation. |
|
817 |
* @param site The type of the qualifying expression, in which |
|
818 |
* identifier is searched. |
|
819 |
* @param name The identifier's name. |
|
820 |
*/ |
|
821 |
public VarSymbol resolveInternalField(DiagnosticPosition pos, Env<AttrContext> env, |
|
822 |
Type site, Name name) { |
|
823 |
Symbol sym = findField(env, site, name, site.tsym); |
|
824 |
if (sym.kind == VAR) return (VarSymbol)sym; |
|
825 |
else throw new FatalError( |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
826 |
diags.fragment("fatal.err.cant.locate.field", |
10 | 827 |
name)); |
828 |
} |
|
829 |
||
830 |
/** Find unqualified variable or field with given name. |
|
831 |
* Synthetic fields always skipped. |
|
832 |
* @param env The current environment. |
|
833 |
* @param name The name of the variable or field. |
|
834 |
*/ |
|
835 |
Symbol findVar(Env<AttrContext> env, Name name) { |
|
836 |
Symbol bestSoFar = varNotFound; |
|
837 |
Symbol sym; |
|
838 |
Env<AttrContext> env1 = env; |
|
839 |
boolean staticOnly = false; |
|
840 |
while (env1.outer != null) { |
|
841 |
if (isStatic(env1)) staticOnly = true; |
|
842 |
Scope.Entry e = env1.info.scope.lookup(name); |
|
843 |
while (e.scope != null && |
|
844 |
(e.sym.kind != VAR || |
|
845 |
(e.sym.flags_field & SYNTHETIC) != 0)) |
|
846 |
e = e.next(); |
|
847 |
sym = (e.scope != null) |
|
848 |
? e.sym |
|
849 |
: findField( |
|
850 |
env1, env1.enclClass.sym.type, name, env1.enclClass.sym); |
|
851 |
if (sym.exists()) { |
|
852 |
if (staticOnly && |
|
853 |
sym.kind == VAR && |
|
854 |
sym.owner.kind == TYP && |
|
855 |
(sym.flags() & STATIC) == 0) |
|
856 |
return new StaticError(sym); |
|
857 |
else |
|
858 |
return sym; |
|
859 |
} else if (sym.kind < bestSoFar.kind) { |
|
860 |
bestSoFar = sym; |
|
861 |
} |
|
862 |
||
863 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
864 |
env1 = env1.outer; |
|
865 |
} |
|
866 |
||
867 |
sym = findField(env, syms.predefClass.type, name, syms.predefClass); |
|
868 |
if (sym.exists()) |
|
869 |
return sym; |
|
870 |
if (bestSoFar.exists()) |
|
871 |
return bestSoFar; |
|
872 |
||
873 |
Scope.Entry e = env.toplevel.namedImportScope.lookup(name); |
|
874 |
for (; e.scope != null; e = e.next()) { |
|
875 |
sym = e.sym; |
|
876 |
Type origin = e.getOrigin().owner.type; |
|
877 |
if (sym.kind == VAR) { |
|
878 |
if (e.sym.owner.type != origin) |
|
879 |
sym = sym.clone(e.getOrigin().owner); |
|
880 |
return isAccessible(env, origin, sym) |
|
881 |
? sym : new AccessError(env, origin, sym); |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
Symbol origin = null; |
|
886 |
e = env.toplevel.starImportScope.lookup(name); |
|
887 |
for (; e.scope != null; e = e.next()) { |
|
888 |
sym = e.sym; |
|
889 |
if (sym.kind != VAR) |
|
890 |
continue; |
|
891 |
// invariant: sym.kind == VAR |
|
892 |
if (bestSoFar.kind < AMBIGUOUS && sym.owner != bestSoFar.owner) |
|
893 |
return new AmbiguityError(bestSoFar, sym); |
|
894 |
else if (bestSoFar.kind >= VAR) { |
|
895 |
origin = e.getOrigin().owner; |
|
896 |
bestSoFar = isAccessible(env, origin.type, sym) |
|
897 |
? sym : new AccessError(env, origin.type, sym); |
|
898 |
} |
|
899 |
} |
|
900 |
if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type) |
|
901 |
return bestSoFar.clone(origin); |
|
902 |
else |
|
903 |
return bestSoFar; |
|
904 |
} |
|
905 |
||
906 |
Warner noteWarner = new Warner(); |
|
907 |
||
908 |
/** Select the best method for a call site among two choices. |
|
909 |
* @param env The current environment. |
|
910 |
* @param site The original type from where the |
|
911 |
* selection takes place. |
|
912 |
* @param argtypes The invocation's value arguments, |
|
913 |
* @param typeargtypes The invocation's type arguments, |
|
914 |
* @param sym Proposed new best match. |
|
915 |
* @param bestSoFar Previously found best match. |
|
916 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
917 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
918 |
*/ |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
919 |
@SuppressWarnings("fallthrough") |
10 | 920 |
Symbol selectBest(Env<AttrContext> env, |
921 |
Type site, |
|
922 |
List<Type> argtypes, |
|
923 |
List<Type> typeargtypes, |
|
924 |
Symbol sym, |
|
925 |
Symbol bestSoFar, |
|
926 |
boolean allowBoxing, |
|
927 |
boolean useVarargs, |
|
928 |
boolean operator) { |
|
929 |
if (sym.kind == ERR) return bestSoFar; |
|
1649
9ec015f3661e
6776289: Regression: javac7 doesnt resolve method calls properly
mcimadamore
parents:
1534
diff
changeset
|
930 |
if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar; |
8032 | 931 |
Assert.check(sym.kind < AMBIGUOUS); |
10 | 932 |
try { |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
933 |
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
934 |
allowBoxing, useVarargs, Warner.noWarnings); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
935 |
if (!operator) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
936 |
currentResolutionContext.addApplicableCandidate(sym, mt); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
937 |
} catch (InapplicableMethodException ex) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
938 |
if (!operator) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
939 |
currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic()); |
10 | 940 |
switch (bestSoFar.kind) { |
941 |
case ABSENT_MTH: |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
942 |
return wrongMethod; |
10 | 943 |
case WRONG_MTH: |
10812
7341374e12e8
7102515: javac running very very long and not returning
mcimadamore
parents:
10197
diff
changeset
|
944 |
if (operator) return bestSoFar; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
945 |
case WRONG_MTHS: |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
946 |
return wrongMethods; |
10 | 947 |
default: |
948 |
return bestSoFar; |
|
949 |
} |
|
950 |
} |
|
951 |
if (!isAccessible(env, site, sym)) { |
|
952 |
return (bestSoFar.kind == ABSENT_MTH) |
|
953 |
? new AccessError(env, site, sym) |
|
954 |
: bestSoFar; |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
955 |
} |
10 | 956 |
return (bestSoFar.kind > AMBIGUOUS) |
957 |
? sym |
|
958 |
: mostSpecific(sym, bestSoFar, env, site, |
|
959 |
allowBoxing && operator, useVarargs); |
|
960 |
} |
|
961 |
||
962 |
/* Return the most specific of the two methods for a call, |
|
963 |
* given that both are accessible and applicable. |
|
964 |
* @param m1 A new candidate for most specific. |
|
965 |
* @param m2 The previous most specific candidate. |
|
966 |
* @param env The current environment. |
|
967 |
* @param site The original type from where the selection |
|
968 |
* takes place. |
|
969 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
970 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
971 |
*/ |
|
972 |
Symbol mostSpecific(Symbol m1, |
|
973 |
Symbol m2, |
|
974 |
Env<AttrContext> env, |
|
2511 | 975 |
final Type site, |
10 | 976 |
boolean allowBoxing, |
977 |
boolean useVarargs) { |
|
978 |
switch (m2.kind) { |
|
979 |
case MTH: |
|
980 |
if (m1 == m2) return m1; |
|
7623 | 981 |
boolean m1SignatureMoreSpecific = signatureMoreSpecific(env, site, m1, m2, allowBoxing, useVarargs); |
982 |
boolean m2SignatureMoreSpecific = signatureMoreSpecific(env, site, m2, m1, allowBoxing, useVarargs); |
|
10 | 983 |
if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) { |
7623 | 984 |
Type mt1 = types.memberType(site, m1); |
985 |
Type mt2 = types.memberType(site, m2); |
|
10 | 986 |
if (!types.overrideEquivalent(mt1, mt2)) |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
987 |
return ambiguityError(m1, m2); |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
988 |
|
10 | 989 |
// same signature; select (a) the non-bridge method, or |
990 |
// (b) the one that overrides the other, or (c) the concrete |
|
991 |
// 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
|
992 |
if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE)) |
10 | 993 |
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
|
994 |
|
10 | 995 |
// if one overrides or hides the other, use it |
996 |
TypeSymbol m1Owner = (TypeSymbol)m1.owner; |
|
997 |
TypeSymbol m2Owner = (TypeSymbol)m2.owner; |
|
998 |
if (types.asSuper(m1Owner.type, m2Owner) != null && |
|
999 |
((m1.owner.flags_field & INTERFACE) == 0 || |
|
1000 |
(m2.owner.flags_field & INTERFACE) != 0) && |
|
1001 |
m1.overrides(m2, m1Owner, types, false)) |
|
1002 |
return m1; |
|
1003 |
if (types.asSuper(m2Owner.type, m1Owner) != null && |
|
1004 |
((m2.owner.flags_field & INTERFACE) == 0 || |
|
1005 |
(m1.owner.flags_field & INTERFACE) != 0) && |
|
1006 |
m2.overrides(m1, m2Owner, types, false)) |
|
1007 |
return m2; |
|
1008 |
boolean m1Abstract = (m1.flags() & ABSTRACT) != 0; |
|
1009 |
boolean m2Abstract = (m2.flags() & ABSTRACT) != 0; |
|
1010 |
if (m1Abstract && !m2Abstract) return m2; |
|
1011 |
if (m2Abstract && !m1Abstract) return m1; |
|
1012 |
// both abstract or both concrete |
|
1013 |
if (!m1Abstract && !m2Abstract) |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1014 |
return ambiguityError(m1, m2); |
1529
a076d4cd3048
6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents:
1528
diff
changeset
|
1015 |
// check that both signatures have the same erasure |
a076d4cd3048
6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents:
1528
diff
changeset
|
1016 |
if (!types.isSameTypes(m1.erasure(types).getParameterTypes(), |
a076d4cd3048
6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
mcimadamore
parents:
1528
diff
changeset
|
1017 |
m2.erasure(types).getParameterTypes())) |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1018 |
return ambiguityError(m1, m2); |
10 | 1019 |
// both abstract, neither overridden; merge throws clause and result type |
10197
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1020 |
Type mst = mostSpecificReturnType(mt1, mt2); |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1021 |
if (mst == null) { |
10 | 1022 |
// Theoretically, this can't happen, but it is possible |
1023 |
// due to error recovery or mixing incompatible class files |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1024 |
return ambiguityError(m1, m2); |
10 | 1025 |
} |
10197
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1026 |
Symbol mostSpecific = mst == mt1 ? m1 : m2; |
8430 | 1027 |
List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes()); |
1028 |
Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown); |
|
2511 | 1029 |
MethodSymbol result = new MethodSymbol( |
1030 |
mostSpecific.flags(), |
|
1031 |
mostSpecific.name, |
|
8430 | 1032 |
newSig, |
2511 | 1033 |
mostSpecific.owner) { |
1034 |
@Override |
|
1035 |
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { |
|
1036 |
if (origin == site.tsym) |
|
1037 |
return this; |
|
1038 |
else |
|
1039 |
return super.implementation(origin, types, checkResult); |
|
14045 | 1040 |
} |
1041 |
}; |
|
10 | 1042 |
return result; |
1043 |
} |
|
1044 |
if (m1SignatureMoreSpecific) return m1; |
|
1045 |
if (m2SignatureMoreSpecific) return m2; |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1046 |
return ambiguityError(m1, m2); |
10 | 1047 |
case AMBIGUOUS: |
1048 |
AmbiguityError e = (AmbiguityError)m2; |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
1049 |
Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs); |
10 | 1050 |
Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs); |
1051 |
if (err1 == err2) return err1; |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
1052 |
if (err1 == e.sym && err2 == e.sym2) return m2; |
10 | 1053 |
if (err1 instanceof AmbiguityError && |
1054 |
err2 instanceof AmbiguityError && |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
1055 |
((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym) |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1056 |
return ambiguityError(m1, m2); |
10 | 1057 |
else |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1058 |
return ambiguityError(err1, err2); |
10 | 1059 |
default: |
1060 |
throw new AssertionError(); |
|
1061 |
} |
|
1062 |
} |
|
7623 | 1063 |
//where |
1064 |
private boolean signatureMoreSpecific(Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1065 |
noteWarner.clear(); |
7623 | 1066 |
Type mtype1 = types.memberType(site, adjustVarargs(m1, m2, useVarargs)); |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12335
diff
changeset
|
1067 |
Type mtype2 = instantiate(env, site, adjustVarargs(m2, m1, useVarargs), null, |
9720
bc06a797f393
7042566: Regression: new ambiguity between varargs method
mcimadamore
parents:
9303
diff
changeset
|
1068 |
types.lowerBoundArgtypes(mtype1), null, |
bc06a797f393
7042566: Regression: new ambiguity between varargs method
mcimadamore
parents:
9303
diff
changeset
|
1069 |
allowBoxing, false, noteWarner); |
bc06a797f393
7042566: Regression: new ambiguity between varargs method
mcimadamore
parents:
9303
diff
changeset
|
1070 |
return mtype2 != null && |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1071 |
!noteWarner.hasLint(Lint.LintCategory.UNCHECKED); |
7623 | 1072 |
} |
1073 |
//where |
|
1074 |
private Symbol adjustVarargs(Symbol to, Symbol from, boolean useVarargs) { |
|
1075 |
List<Type> fromArgs = from.type.getParameterTypes(); |
|
1076 |
List<Type> toArgs = to.type.getParameterTypes(); |
|
1077 |
if (useVarargs && |
|
1078 |
(from.flags() & VARARGS) != 0 && |
|
1079 |
(to.flags() & VARARGS) != 0) { |
|
1080 |
Type varargsTypeFrom = fromArgs.last(); |
|
1081 |
Type varargsTypeTo = toArgs.last(); |
|
7635
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1082 |
ListBuffer<Type> args = ListBuffer.lb(); |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1083 |
if (toArgs.length() < fromArgs.length()) { |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1084 |
//if we are checking a varargs method 'from' against another varargs |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1085 |
//method 'to' (where arity of 'to' < arity of 'from') then expand signature |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1086 |
//of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to' |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1087 |
//until 'to' signature has the same arity as 'from') |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1088 |
while (fromArgs.head != varargsTypeFrom) { |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1089 |
args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head); |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1090 |
fromArgs = fromArgs.tail; |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1091 |
toArgs = toArgs.head == varargsTypeTo ? |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1092 |
toArgs : |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1093 |
toArgs.tail; |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1094 |
} |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1095 |
} else { |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1096 |
//formal argument list is same as original list where last |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1097 |
//argument (array type) is removed |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1098 |
args.appendList(toArgs.reverse().tail.reverse()); |
7623 | 1099 |
} |
7635
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1100 |
//append varargs element type as last synthetic formal |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7623
diff
changeset
|
1101 |
args.append(types.elemtype(varargsTypeTo)); |
8430 | 1102 |
Type mtype = types.createMethodTypeWithParameters(to.type, args.toList()); |
9720
bc06a797f393
7042566: Regression: new ambiguity between varargs method
mcimadamore
parents:
9303
diff
changeset
|
1103 |
return new MethodSymbol(to.flags_field & ~VARARGS, to.name, mtype, to.owner); |
7623 | 1104 |
} else { |
1105 |
return to; |
|
1106 |
} |
|
1107 |
} |
|
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1108 |
//where |
10197
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1109 |
Type mostSpecificReturnType(Type mt1, Type mt2) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1110 |
Type rt1 = mt1.getReturnType(); |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1111 |
Type rt2 = mt2.getReturnType(); |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1112 |
|
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1113 |
if (mt1.tag == FORALL && mt2.tag == FORALL) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1114 |
//if both are generic methods, adjust return type ahead of subtyping check |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1115 |
rt1 = types.subst(rt1, mt1.getTypeArguments(), mt2.getTypeArguments()); |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1116 |
} |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1117 |
//first use subtyping, then return type substitutability |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1118 |
if (types.isSubtype(rt1, rt2)) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1119 |
return mt1; |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1120 |
} else if (types.isSubtype(rt2, rt1)) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1121 |
return mt2; |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1122 |
} else if (types.returnTypeSubstitutable(mt1, mt2)) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1123 |
return mt1; |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1124 |
} else if (types.returnTypeSubstitutable(mt2, mt1)) { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1125 |
return mt2; |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1126 |
} else { |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1127 |
return null; |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1128 |
} |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1129 |
} |
28afe0fb34c8
7062745: Regression: difference in overload resolution when two methods are maximally specific
mcimadamore
parents:
9720
diff
changeset
|
1130 |
//where |
8228
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1131 |
Symbol ambiguityError(Symbol m1, Symbol m2) { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1132 |
if (((m1.flags() | m2.flags()) & CLASH) != 0) { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1133 |
return (m1.flags() & CLASH) == 0 ? m1 : m2; |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1134 |
} else { |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1135 |
return new AmbiguityError(m1, m2); |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1136 |
} |
4e6ee38974b2
6910550: javac 1.5.0_17 fails with incorrect error message
mcimadamore
parents:
8045
diff
changeset
|
1137 |
} |
10 | 1138 |
|
1139 |
/** Find best qualified method matching given name, type and value |
|
1140 |
* arguments. |
|
1141 |
* @param env The current environment. |
|
1142 |
* @param site The original type from where the selection |
|
1143 |
* takes place. |
|
1144 |
* @param name The method's name. |
|
1145 |
* @param argtypes The method's value arguments. |
|
1146 |
* @param typeargtypes The method's type arguments |
|
1147 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1148 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1149 |
*/ |
|
1150 |
Symbol findMethod(Env<AttrContext> env, |
|
1151 |
Type site, |
|
1152 |
Name name, |
|
1153 |
List<Type> argtypes, |
|
1154 |
List<Type> typeargtypes, |
|
1155 |
boolean allowBoxing, |
|
1156 |
boolean useVarargs, |
|
1157 |
boolean operator) { |
|
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
1158 |
Symbol bestSoFar = methodNotFound; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
1159 |
bestSoFar = findMethod(env, |
10 | 1160 |
site, |
1161 |
name, |
|
1162 |
argtypes, |
|
1163 |
typeargtypes, |
|
1164 |
site.tsym.type, |
|
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
1165 |
bestSoFar, |
10 | 1166 |
allowBoxing, |
1167 |
useVarargs, |
|
14045 | 1168 |
operator); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
1169 |
reportVerboseResolutionDiagnostic(env.tree.pos(), name, site, argtypes, typeargtypes, bestSoFar); |
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
1170 |
return bestSoFar; |
10 | 1171 |
} |
1172 |
// where |
|
1173 |
private Symbol findMethod(Env<AttrContext> env, |
|
1174 |
Type site, |
|
1175 |
Name name, |
|
1176 |
List<Type> argtypes, |
|
1177 |
List<Type> typeargtypes, |
|
1178 |
Type intype, |
|
1179 |
Symbol bestSoFar, |
|
1180 |
boolean allowBoxing, |
|
1181 |
boolean useVarargs, |
|
14045 | 1182 |
boolean operator) { |
1183 |
boolean abstractOk = true; |
|
1184 |
List<Type> itypes = List.nil(); |
|
1185 |
for (TypeSymbol s : superclasses(intype)) { |
|
1186 |
bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, |
|
1187 |
s.members(), bestSoFar, allowBoxing, useVarargs, operator, true); |
|
1188 |
abstractOk &= excludeAbstractsFilter.accepts(s); |
|
1189 |
if (abstractOk) { |
|
1190 |
for (Type itype : types.interfaces(s.type)) { |
|
1191 |
itypes = types.union(types.closure(itype), itypes); |
|
10 | 1192 |
} |
1193 |
} |
|
14045 | 1194 |
if (name == names.init) break; |
1195 |
} |
|
1196 |
||
1197 |
Symbol concrete = bestSoFar.kind < ERR && |
|
1198 |
(bestSoFar.flags() & ABSTRACT) == 0 ? |
|
1199 |
bestSoFar : methodNotFound; |
|
1200 |
||
1201 |
if (name != names.init) { |
|
1202 |
//keep searching for abstract methods |
|
1203 |
for (Type itype : itypes) { |
|
1204 |
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) |
|
1205 |
bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, |
|
1206 |
itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); |
|
1207 |
if (concrete != bestSoFar && |
|
1208 |
concrete.kind < ERR && bestSoFar.kind < ERR && |
|
1209 |
types.isSubSignature(concrete.type, bestSoFar.type)) { |
|
1210 |
//this is an hack - as javac does not do full membership checks |
|
1211 |
//most specific ends up comparing abstract methods that might have |
|
1212 |
//been implemented by some concrete method in a subclass and, |
|
1213 |
//because of raw override, it is possible for an abstract method |
|
1214 |
//to be more specific than the concrete method - so we need |
|
1215 |
//to explicitly call that out (see CR 6178365) |
|
1216 |
bestSoFar = concrete; |
|
1217 |
} |
|
10 | 1218 |
} |
1219 |
} |
|
1220 |
return bestSoFar; |
|
1221 |
} |
|
1222 |
||
14045 | 1223 |
/** |
1224 |
* Return an Iterable object to scan the superclasses of a given type. |
|
1225 |
* It's crucial that the scan is done lazily, as we don't want to accidentally |
|
1226 |
* access more supertypes than strictly needed (as this could trigger completion |
|
1227 |
* errors if some of the not-needed supertypes are missing/ill-formed). |
|
1228 |
*/ |
|
1229 |
Iterable<TypeSymbol> superclasses(final Type intype) { |
|
1230 |
return new Iterable<TypeSymbol>() { |
|
1231 |
public Iterator<TypeSymbol> iterator() { |
|
1232 |
return new Iterator<TypeSymbol>() { |
|
1233 |
||
1234 |
List<TypeSymbol> seen = List.nil(); |
|
1235 |
TypeSymbol currentSym = getSymbol(intype); |
|
1236 |
||
1237 |
public boolean hasNext() { |
|
1238 |
return currentSym != null; |
|
1239 |
} |
|
1240 |
||
1241 |
public TypeSymbol next() { |
|
1242 |
TypeSymbol prevSym = currentSym; |
|
1243 |
currentSym = getSymbol(types.supertype(currentSym.type)); |
|
1244 |
return prevSym; |
|
1245 |
} |
|
1246 |
||
1247 |
public void remove() { |
|
1248 |
throw new UnsupportedOperationException("Not supported yet."); |
|
1249 |
} |
|
1250 |
||
1251 |
TypeSymbol getSymbol(Type intype) { |
|
1252 |
if (intype.tag != CLASS && |
|
1253 |
intype.tag != TYPEVAR) { |
|
1254 |
return null; |
|
1255 |
} |
|
1256 |
while (intype.tag == TYPEVAR) |
|
1257 |
intype = intype.getUpperBound(); |
|
1258 |
if (seen.contains(intype.tsym)) { |
|
1259 |
//degenerate case in which we have a circular |
|
1260 |
//class hierarchy - because of ill-formed classfiles |
|
1261 |
return null; |
|
1262 |
} |
|
1263 |
seen = seen.prepend(intype.tsym); |
|
1264 |
return intype.tsym; |
|
1265 |
} |
|
1266 |
}; |
|
1267 |
} |
|
1268 |
}; |
|
1269 |
} |
|
1270 |
||
1271 |
/** |
|
1272 |
* We should not look for abstract methods if receiver is a concrete class |
|
1273 |
* (as concrete classes are expected to implement all abstracts coming |
|
1274 |
* from superinterfaces) |
|
1275 |
*/ |
|
1276 |
Filter<Symbol> excludeAbstractsFilter = new Filter<Symbol>() { |
|
1277 |
public boolean accepts(Symbol s) { |
|
1278 |
return (s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0; |
|
1279 |
} |
|
1280 |
}; |
|
1281 |
||
1282 |
/** |
|
1283 |
* Lookup a method with given name and argument types in a given scope |
|
1284 |
*/ |
|
1285 |
Symbol lookupMethod(Env<AttrContext> env, |
|
1286 |
Type site, |
|
1287 |
Name name, |
|
1288 |
List<Type> argtypes, |
|
1289 |
List<Type> typeargtypes, |
|
1290 |
Scope sc, |
|
1291 |
Symbol bestSoFar, |
|
1292 |
boolean allowBoxing, |
|
1293 |
boolean useVarargs, |
|
1294 |
boolean operator, |
|
1295 |
boolean abstractok) { |
|
1296 |
for (Symbol s : sc.getElementsByName(name, lookupFilter)) { |
|
1297 |
bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, |
|
1298 |
bestSoFar, allowBoxing, useVarargs, operator); |
|
1299 |
} |
|
1300 |
return bestSoFar; |
|
1301 |
} |
|
1302 |
//where |
|
1303 |
Filter<Symbol> lookupFilter = new Filter<Symbol>() { |
|
1304 |
public boolean accepts(Symbol s) { |
|
1305 |
return s.kind == MTH && |
|
1306 |
(s.flags() & SYNTHETIC) == 0; |
|
1307 |
} |
|
1308 |
}; |
|
1309 |
||
10 | 1310 |
/** Find unqualified method matching given name, type and value arguments. |
1311 |
* @param env The current environment. |
|
1312 |
* @param name The method's name. |
|
1313 |
* @param argtypes The method's value arguments. |
|
1314 |
* @param typeargtypes The method's type arguments. |
|
1315 |
* @param allowBoxing Allow boxing conversions of arguments. |
|
1316 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
1317 |
*/ |
|
1318 |
Symbol findFun(Env<AttrContext> env, Name name, |
|
1319 |
List<Type> argtypes, List<Type> typeargtypes, |
|
1320 |
boolean allowBoxing, boolean useVarargs) { |
|
1321 |
Symbol bestSoFar = methodNotFound; |
|
1322 |
Symbol sym; |
|
1323 |
Env<AttrContext> env1 = env; |
|
1324 |
boolean staticOnly = false; |
|
1325 |
while (env1.outer != null) { |
|
1326 |
if (isStatic(env1)) staticOnly = true; |
|
1327 |
sym = findMethod( |
|
1328 |
env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, |
|
1329 |
allowBoxing, useVarargs, false); |
|
1330 |
if (sym.exists()) { |
|
1331 |
if (staticOnly && |
|
1332 |
sym.kind == MTH && |
|
1333 |
sym.owner.kind == TYP && |
|
1334 |
(sym.flags() & STATIC) == 0) return new StaticError(sym); |
|
1335 |
else return sym; |
|
1336 |
} else if (sym.kind < bestSoFar.kind) { |
|
1337 |
bestSoFar = sym; |
|
1338 |
} |
|
1339 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
1340 |
env1 = env1.outer; |
|
1341 |
} |
|
1342 |
||
1343 |
sym = findMethod(env, syms.predefClass.type, name, argtypes, |
|
1344 |
typeargtypes, allowBoxing, useVarargs, false); |
|
1345 |
if (sym.exists()) |
|
1346 |
return sym; |
|
1347 |
||
1348 |
Scope.Entry e = env.toplevel.namedImportScope.lookup(name); |
|
1349 |
for (; e.scope != null; e = e.next()) { |
|
1350 |
sym = e.sym; |
|
1351 |
Type origin = e.getOrigin().owner.type; |
|
1352 |
if (sym.kind == MTH) { |
|
1353 |
if (e.sym.owner.type != origin) |
|
1354 |
sym = sym.clone(e.getOrigin().owner); |
|
1355 |
if (!isAccessible(env, origin, sym)) |
|
1356 |
sym = new AccessError(env, origin, sym); |
|
1357 |
bestSoFar = selectBest(env, origin, |
|
1358 |
argtypes, typeargtypes, |
|
1359 |
sym, bestSoFar, |
|
1360 |
allowBoxing, useVarargs, false); |
|
1361 |
} |
|
1362 |
} |
|
1363 |
if (bestSoFar.exists()) |
|
1364 |
return bestSoFar; |
|
1365 |
||
1366 |
e = env.toplevel.starImportScope.lookup(name); |
|
1367 |
for (; e.scope != null; e = e.next()) { |
|
1368 |
sym = e.sym; |
|
1369 |
Type origin = e.getOrigin().owner.type; |
|
1370 |
if (sym.kind == MTH) { |
|
1371 |
if (e.sym.owner.type != origin) |
|
1372 |
sym = sym.clone(e.getOrigin().owner); |
|
1373 |
if (!isAccessible(env, origin, sym)) |
|
1374 |
sym = new AccessError(env, origin, sym); |
|
1375 |
bestSoFar = selectBest(env, origin, |
|
1376 |
argtypes, typeargtypes, |
|
1377 |
sym, bestSoFar, |
|
1378 |
allowBoxing, useVarargs, false); |
|
1379 |
} |
|
1380 |
} |
|
1381 |
return bestSoFar; |
|
1382 |
} |
|
1383 |
||
1384 |
/** Load toplevel or member class with given fully qualified name and |
|
1385 |
* verify that it is accessible. |
|
1386 |
* @param env The current environment. |
|
1387 |
* @param name The fully qualified name of the class to be loaded. |
|
1388 |
*/ |
|
1389 |
Symbol loadClass(Env<AttrContext> env, Name name) { |
|
1390 |
try { |
|
1391 |
ClassSymbol c = reader.loadClass(name); |
|
1392 |
return isAccessible(env, c) ? c : new AccessError(c); |
|
1393 |
} catch (ClassReader.BadClassFile err) { |
|
1394 |
throw err; |
|
1395 |
} catch (CompletionFailure ex) { |
|
1396 |
return typeNotFound; |
|
1397 |
} |
|
1398 |
} |
|
1399 |
||
1400 |
/** Find qualified member type. |
|
1401 |
* @param env The current environment. |
|
1402 |
* @param site The original type from where the selection takes |
|
1403 |
* place. |
|
1404 |
* @param name The type's name. |
|
1405 |
* @param c The class to search for the member type. This is |
|
1406 |
* always a superclass or implemented interface of |
|
1407 |
* site's class. |
|
1408 |
*/ |
|
1409 |
Symbol findMemberType(Env<AttrContext> env, |
|
1410 |
Type site, |
|
1411 |
Name name, |
|
1412 |
TypeSymbol c) { |
|
1413 |
Symbol bestSoFar = typeNotFound; |
|
1414 |
Symbol sym; |
|
1415 |
Scope.Entry e = c.members().lookup(name); |
|
1416 |
while (e.scope != null) { |
|
1417 |
if (e.sym.kind == TYP) { |
|
1418 |
return isAccessible(env, site, e.sym) |
|
1419 |
? e.sym |
|
1420 |
: new AccessError(env, site, e.sym); |
|
1421 |
} |
|
1422 |
e = e.next(); |
|
1423 |
} |
|
1424 |
Type st = types.supertype(c.type); |
|
1425 |
if (st != null && st.tag == CLASS) { |
|
1426 |
sym = findMemberType(env, site, name, st.tsym); |
|
1427 |
if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1428 |
} |
|
1429 |
for (List<Type> l = types.interfaces(c.type); |
|
1430 |
bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); |
|
1431 |
l = l.tail) { |
|
1432 |
sym = findMemberType(env, site, name, l.head.tsym); |
|
1433 |
if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS && |
|
1434 |
sym.owner != bestSoFar.owner) |
|
1435 |
bestSoFar = new AmbiguityError(bestSoFar, sym); |
|
1436 |
else if (sym.kind < bestSoFar.kind) |
|
1437 |
bestSoFar = sym; |
|
1438 |
} |
|
1439 |
return bestSoFar; |
|
1440 |
} |
|
1441 |
||
1442 |
/** Find a global type in given scope and load corresponding class. |
|
1443 |
* @param env The current environment. |
|
1444 |
* @param scope The scope in which to look for the type. |
|
1445 |
* @param name The type's name. |
|
1446 |
*/ |
|
1447 |
Symbol findGlobalType(Env<AttrContext> env, Scope scope, Name name) { |
|
1448 |
Symbol bestSoFar = typeNotFound; |
|
1449 |
for (Scope.Entry e = scope.lookup(name); e.scope != null; e = e.next()) { |
|
1450 |
Symbol sym = loadClass(env, e.sym.flatName()); |
|
1451 |
if (bestSoFar.kind == TYP && sym.kind == TYP && |
|
1452 |
bestSoFar != sym) |
|
1453 |
return new AmbiguityError(bestSoFar, sym); |
|
1454 |
else if (sym.kind < bestSoFar.kind) |
|
1455 |
bestSoFar = sym; |
|
1456 |
} |
|
1457 |
return bestSoFar; |
|
1458 |
} |
|
1459 |
||
1460 |
/** Find an unqualified type symbol. |
|
1461 |
* @param env The current environment. |
|
1462 |
* @param name The type's name. |
|
1463 |
*/ |
|
1464 |
Symbol findType(Env<AttrContext> env, Name name) { |
|
1465 |
Symbol bestSoFar = typeNotFound; |
|
1466 |
Symbol sym; |
|
1467 |
boolean staticOnly = false; |
|
1468 |
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) { |
|
1469 |
if (isStatic(env1)) staticOnly = true; |
|
1470 |
for (Scope.Entry e = env1.info.scope.lookup(name); |
|
1471 |
e.scope != null; |
|
1472 |
e = e.next()) { |
|
1473 |
if (e.sym.kind == TYP) { |
|
1474 |
if (staticOnly && |
|
1475 |
e.sym.type.tag == TYPEVAR && |
|
1476 |
e.sym.owner.kind == TYP) return new StaticError(e.sym); |
|
1477 |
return e.sym; |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
sym = findMemberType(env1, env1.enclClass.sym.type, name, |
|
1482 |
env1.enclClass.sym); |
|
1483 |
if (staticOnly && sym.kind == TYP && |
|
1484 |
sym.type.tag == CLASS && |
|
1485 |
sym.type.getEnclosingType().tag == CLASS && |
|
1486 |
env1.enclClass.sym.type.isParameterized() && |
|
1487 |
sym.type.getEnclosingType().isParameterized()) |
|
1488 |
return new StaticError(sym); |
|
1489 |
else if (sym.exists()) return sym; |
|
1490 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1491 |
||
1492 |
JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass; |
|
1493 |
if ((encl.sym.flags() & STATIC) != 0) |
|
1494 |
staticOnly = true; |
|
1495 |
} |
|
1496 |
||
10950 | 1497 |
if (!env.tree.hasTag(IMPORT)) { |
10 | 1498 |
sym = findGlobalType(env, env.toplevel.namedImportScope, name); |
1499 |
if (sym.exists()) return sym; |
|
1500 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1501 |
||
1502 |
sym = findGlobalType(env, env.toplevel.packge.members(), name); |
|
1503 |
if (sym.exists()) return sym; |
|
1504 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1505 |
||
1506 |
sym = findGlobalType(env, env.toplevel.starImportScope, name); |
|
1507 |
if (sym.exists()) return sym; |
|
1508 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1509 |
} |
|
1510 |
||
1511 |
return bestSoFar; |
|
1512 |
} |
|
1513 |
||
1514 |
/** Find an unqualified identifier which matches a specified kind set. |
|
1515 |
* @param env The current environment. |
|
1516 |
* @param name The indentifier's name. |
|
1517 |
* @param kind Indicates the possible symbol kinds |
|
1518 |
* (a subset of VAL, TYP, PCK). |
|
1519 |
*/ |
|
1520 |
Symbol findIdent(Env<AttrContext> env, Name name, int kind) { |
|
1521 |
Symbol bestSoFar = typeNotFound; |
|
1522 |
Symbol sym; |
|
1523 |
||
1524 |
if ((kind & VAR) != 0) { |
|
1525 |
sym = findVar(env, name); |
|
1526 |
if (sym.exists()) return sym; |
|
1527 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1528 |
} |
|
1529 |
||
1530 |
if ((kind & TYP) != 0) { |
|
1531 |
sym = findType(env, name); |
|
1532 |
if (sym.exists()) return sym; |
|
1533 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1534 |
} |
|
1535 |
||
1536 |
if ((kind & PCK) != 0) return reader.enterPackage(name); |
|
1537 |
else return bestSoFar; |
|
1538 |
} |
|
1539 |
||
1540 |
/** Find an identifier in a package which matches a specified kind set. |
|
1541 |
* @param env The current environment. |
|
1542 |
* @param name The identifier's name. |
|
1543 |
* @param kind Indicates the possible symbol kinds |
|
1544 |
* (a nonempty subset of TYP, PCK). |
|
1545 |
*/ |
|
1546 |
Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck, |
|
1547 |
Name name, int kind) { |
|
1548 |
Name fullname = TypeSymbol.formFullName(name, pck); |
|
1549 |
Symbol bestSoFar = typeNotFound; |
|
1550 |
PackageSymbol pack = null; |
|
1551 |
if ((kind & PCK) != 0) { |
|
1552 |
pack = reader.enterPackage(fullname); |
|
1553 |
if (pack.exists()) return pack; |
|
1554 |
} |
|
1555 |
if ((kind & TYP) != 0) { |
|
1556 |
Symbol sym = loadClass(env, fullname); |
|
1557 |
if (sym.exists()) { |
|
1558 |
// don't allow programs to use flatnames |
|
1559 |
if (name == sym.name) return sym; |
|
1560 |
} |
|
1561 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1562 |
} |
|
1563 |
return (pack != null) ? pack : bestSoFar; |
|
1564 |
} |
|
1565 |
||
1566 |
/** Find an identifier among the members of a given type `site'. |
|
1567 |
* @param env The current environment. |
|
1568 |
* @param site The type containing the symbol to be found. |
|
1569 |
* @param name The identifier's name. |
|
1570 |
* @param kind Indicates the possible symbol kinds |
|
1571 |
* (a subset of VAL, TYP). |
|
1572 |
*/ |
|
1573 |
Symbol findIdentInType(Env<AttrContext> env, Type site, |
|
1574 |
Name name, int kind) { |
|
1575 |
Symbol bestSoFar = typeNotFound; |
|
1576 |
Symbol sym; |
|
1577 |
if ((kind & VAR) != 0) { |
|
1578 |
sym = findField(env, site, name, site.tsym); |
|
1579 |
if (sym.exists()) return sym; |
|
1580 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1581 |
} |
|
1582 |
||
1583 |
if ((kind & TYP) != 0) { |
|
1584 |
sym = findMemberType(env, site, name, site.tsym); |
|
1585 |
if (sym.exists()) return sym; |
|
1586 |
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; |
|
1587 |
} |
|
1588 |
return bestSoFar; |
|
1589 |
} |
|
1590 |
||
1591 |
/* *************************************************************************** |
|
1592 |
* Access checking |
|
1593 |
* The following methods convert ResolveErrors to ErrorSymbols, issuing |
|
1594 |
* an error message in the process |
|
1595 |
****************************************************************************/ |
|
1596 |
||
1597 |
/** If `sym' is a bad symbol: report error and return errSymbol |
|
1598 |
* else pass through unchanged, |
|
1599 |
* additional arguments duplicate what has been used in trying to find the |
|
13844 | 1600 |
* symbol {@literal (--> flyweight pattern)}. This improves performance since we |
10 | 1601 |
* expect misses to happen frequently. |
1602 |
* |
|
1603 |
* @param sym The symbol that was found, or a ResolveError. |
|
1604 |
* @param pos The position to use for error reporting. |
|
1605 |
* @param site The original type from where the selection took place. |
|
1606 |
* @param name The symbol's name. |
|
1607 |
* @param argtypes The invocation's value arguments, |
|
1608 |
* if we looked for a method. |
|
1609 |
* @param typeargtypes The invocation's type arguments, |
|
1610 |
* if we looked for a method. |
|
1611 |
*/ |
|
1612 |
Symbol access(Symbol sym, |
|
1613 |
DiagnosticPosition pos, |
|
8045 | 1614 |
Symbol location, |
10 | 1615 |
Type site, |
1616 |
Name name, |
|
1617 |
boolean qualified, |
|
1618 |
List<Type> argtypes, |
|
1619 |
List<Type> typeargtypes) { |
|
1620 |
if (sym.kind >= AMBIGUOUS) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
1621 |
ResolveError errSym = (ResolveError)sym; |
10 | 1622 |
if (!site.isErroneous() && |
1623 |
!Type.isErroneous(argtypes) && |
|
1624 |
(typeargtypes==null || !Type.isErroneous(typeargtypes))) |
|
8045 | 1625 |
logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
1626 |
sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); |
10 | 1627 |
} |
1628 |
return sym; |
|
1629 |
} |
|
1630 |
||
8045 | 1631 |
/** Same as original access(), but without location. |
1632 |
*/ |
|
1633 |
Symbol access(Symbol sym, |
|
1634 |
DiagnosticPosition pos, |
|
1635 |
Type site, |
|
1636 |
Name name, |
|
1637 |
boolean qualified, |
|
1638 |
List<Type> argtypes, |
|
1639 |
List<Type> typeargtypes) { |
|
1640 |
return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); |
|
1641 |
} |
|
1642 |
||
1643 |
/** Same as original access(), but without type arguments and arguments. |
|
1644 |
*/ |
|
1645 |
Symbol access(Symbol sym, |
|
1646 |
DiagnosticPosition pos, |
|
1647 |
Symbol location, |
|
1648 |
Type site, |
|
1649 |
Name name, |
|
1650 |
boolean qualified) { |
|
1651 |
if (sym.kind >= AMBIGUOUS) |
|
1652 |
return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null); |
|
1653 |
else |
|
1654 |
return sym; |
|
1655 |
} |
|
1656 |
||
1657 |
/** Same as original access(), but without location, type arguments and arguments. |
|
10 | 1658 |
*/ |
1659 |
Symbol access(Symbol sym, |
|
1660 |
DiagnosticPosition pos, |
|
1661 |
Type site, |
|
1662 |
Name name, |
|
1663 |
boolean qualified) { |
|
8045 | 1664 |
return access(sym, pos, site.tsym, site, name, qualified); |
10 | 1665 |
} |
1666 |
||
1667 |
/** Check that sym is not an abstract method. |
|
1668 |
*/ |
|
1669 |
void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { |
|
1670 |
if ((sym.flags() & ABSTRACT) != 0) |
|
1671 |
log.error(pos, "abstract.cant.be.accessed.directly", |
|
1672 |
kindName(sym), sym, sym.location()); |
|
1673 |
} |
|
1674 |
||
1675 |
/* *************************************************************************** |
|
1676 |
* Debugging |
|
1677 |
****************************************************************************/ |
|
1678 |
||
1679 |
/** print all scopes starting with scope s and proceeding outwards. |
|
1680 |
* used for debugging. |
|
1681 |
*/ |
|
1682 |
public void printscopes(Scope s) { |
|
1683 |
while (s != null) { |
|
1684 |
if (s.owner != null) |
|
1685 |
System.err.print(s.owner + ": "); |
|
1686 |
for (Scope.Entry e = s.elems; e != null; e = e.sibling) { |
|
1687 |
if ((e.sym.flags() & ABSTRACT) != 0) |
|
1688 |
System.err.print("abstract "); |
|
1689 |
System.err.print(e.sym + " "); |
|
1690 |
} |
|
1691 |
System.err.println(); |
|
1692 |
s = s.next; |
|
1693 |
} |
|
1694 |
} |
|
1695 |
||
1696 |
void printscopes(Env<AttrContext> env) { |
|
1697 |
while (env.outer != null) { |
|
1698 |
System.err.println("------------------------------"); |
|
1699 |
printscopes(env.info.scope); |
|
1700 |
env = env.outer; |
|
1701 |
} |
|
1702 |
} |
|
1703 |
||
1704 |
public void printscopes(Type t) { |
|
1705 |
while (t.tag == CLASS) { |
|
1706 |
printscopes(t.tsym.members()); |
|
1707 |
t = types.supertype(t); |
|
1708 |
} |
|
1709 |
} |
|
1710 |
||
1711 |
/* *************************************************************************** |
|
1712 |
* Name resolution |
|
1713 |
* Naming conventions are as for symbol lookup |
|
1714 |
* Unlike the find... methods these methods will report access errors |
|
1715 |
****************************************************************************/ |
|
1716 |
||
1717 |
/** Resolve an unqualified (non-method) identifier. |
|
1718 |
* @param pos The position to use for error reporting. |
|
1719 |
* @param env The environment current at the identifier use. |
|
1720 |
* @param name The identifier's name. |
|
1721 |
* @param kind The set of admissible symbol kinds for the identifier. |
|
1722 |
*/ |
|
1723 |
Symbol resolveIdent(DiagnosticPosition pos, Env<AttrContext> env, |
|
1724 |
Name name, int kind) { |
|
1725 |
return access( |
|
1726 |
findIdent(env, name, kind), |
|
1727 |
pos, env.enclClass.sym.type, name, false); |
|
1728 |
} |
|
1729 |
||
1730 |
/** Resolve an unqualified method identifier. |
|
1731 |
* @param pos The position to use for error reporting. |
|
1732 |
* @param env The environment current at the method invocation. |
|
1733 |
* @param name The identifier's name. |
|
1734 |
* @param argtypes The types of the invocation's value arguments. |
|
1735 |
* @param typeargtypes The types of the invocation's type arguments. |
|
1736 |
*/ |
|
1737 |
Symbol resolveMethod(DiagnosticPosition pos, |
|
1738 |
Env<AttrContext> env, |
|
1739 |
Name name, |
|
1740 |
List<Type> argtypes, |
|
1741 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1742 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1743 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1744 |
currentResolutionContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1745 |
Symbol sym = methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1746 |
List<MethodResolutionPhase> steps = methodResolutionSteps; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1747 |
while (steps.nonEmpty() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1748 |
steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1749 |
sym.kind >= ERRONEOUS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1750 |
currentResolutionContext.step = steps.head; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1751 |
sym = findFun(env, name, argtypes, typeargtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1752 |
steps.head.isBoxingRequired, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1753 |
env.info.varArgs = steps.head.isVarargsRequired); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1754 |
currentResolutionContext.resolutionCache.put(steps.head, sym); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1755 |
steps = steps.tail; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1756 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1757 |
if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1758 |
MethodResolutionPhase errPhase = |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1759 |
currentResolutionContext.firstErroneousResolutionPhase(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1760 |
sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1761 |
pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1762 |
env.info.varArgs = errPhase.isVarargsRequired; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1763 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1764 |
return sym; |
10 | 1765 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1766 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1767 |
currentResolutionContext = prevResolutionContext; |
10 | 1768 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1769 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
1770 |
|
10 | 1771 |
/** Resolve a qualified method identifier |
1772 |
* @param pos The position to use for error reporting. |
|
1773 |
* @param env The environment current at the method invocation. |
|
1774 |
* @param site The type of the qualifying expression, in which |
|
1775 |
* identifier is searched. |
|
1776 |
* @param name The identifier's name. |
|
1777 |
* @param argtypes The types of the invocation's value arguments. |
|
1778 |
* @param typeargtypes The types of the invocation's type arguments. |
|
1779 |
*/ |
|
1780 |
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
1781 |
Type site, Name name, List<Type> argtypes, |
|
1782 |
List<Type> typeargtypes) { |
|
8045 | 1783 |
return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes); |
1784 |
} |
|
1785 |
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
1786 |
Symbol location, Type site, Name name, List<Type> argtypes, |
|
1787 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1788 |
return resolveQualifiedMethod(new MethodResolutionContext(), pos, env, location, site, name, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1789 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1790 |
private Symbol resolveQualifiedMethod(MethodResolutionContext resolveContext, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1791 |
DiagnosticPosition pos, Env<AttrContext> env, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1792 |
Symbol location, Type site, Name name, List<Type> argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1793 |
List<Type> typeargtypes) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1794 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1795 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1796 |
currentResolutionContext = resolveContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1797 |
Symbol sym = methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1798 |
List<MethodResolutionPhase> steps = methodResolutionSteps; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1799 |
while (steps.nonEmpty() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1800 |
steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1801 |
sym.kind >= ERRONEOUS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1802 |
currentResolutionContext.step = steps.head; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1803 |
sym = findMethod(env, site, name, argtypes, typeargtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1804 |
steps.head.isBoxingRequired(), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1805 |
env.info.varArgs = steps.head.isVarargsRequired(), false); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1806 |
currentResolutionContext.resolutionCache.put(steps.head, sym); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1807 |
steps = steps.tail; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1808 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1809 |
if (sym.kind >= AMBIGUOUS) { |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1810 |
//if nothing is found return the 'first' error |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1811 |
MethodResolutionPhase errPhase = |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1812 |
currentResolutionContext.firstErroneousResolutionPhase(); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1813 |
sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1814 |
pos, location, site, name, true, argtypes, typeargtypes); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1815 |
env.info.varArgs = errPhase.isVarargsRequired; |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1816 |
} else if (allowMethodHandles) { |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1817 |
MethodSymbol msym = (MethodSymbol)sym; |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1818 |
if (msym.isSignaturePolymorphic(types)) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1819 |
env.info.varArgs = false; |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1820 |
return findPolymorphicSignatureInstance(env, sym, argtypes); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1821 |
} |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1822 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1823 |
return sym; |
10 | 1824 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1825 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1826 |
currentResolutionContext = prevResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1827 |
} |
10 | 1828 |
} |
1829 |
||
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1830 |
/** 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
|
1831 |
* 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
|
1832 |
* 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
|
1833 |
* @param env Attribution environment |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1834 |
* @param spMethod signature polymorphic method - i.e. MH.invokeExact |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1835 |
* @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
|
1836 |
*/ |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1837 |
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1838 |
Symbol spMethod, |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
1839 |
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
|
1840 |
Type mtype = infer.instantiatePolymorphicSignatureInstance(env, |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1841 |
(MethodSymbol)spMethod, argtypes); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1842 |
for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) { |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1843 |
if (types.isSameType(mtype, sym.type)) { |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1844 |
return sym; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1845 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1846 |
} |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1847 |
|
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1848 |
// create the desired method |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1849 |
long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags; |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1850 |
Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1851 |
polymorphicSignatureScope.enter(msym); |
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
1852 |
return msym; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1853 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6356
diff
changeset
|
1854 |
|
10 | 1855 |
/** Resolve a qualified method identifier, throw a fatal error if not |
1856 |
* found. |
|
1857 |
* @param pos The position to use for error reporting. |
|
1858 |
* @param env The environment current at the method invocation. |
|
1859 |
* @param site The type of the qualifying expression, in which |
|
1860 |
* identifier is searched. |
|
1861 |
* @param name The identifier's name. |
|
1862 |
* @param argtypes The types of the invocation's value arguments. |
|
1863 |
* @param typeargtypes The types of the invocation's type arguments. |
|
1864 |
*/ |
|
1865 |
public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env, |
|
1866 |
Type site, Name name, |
|
1867 |
List<Type> argtypes, |
|
1868 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1869 |
MethodResolutionContext resolveContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1870 |
resolveContext.internalResolution = true; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1871 |
Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1872 |
site, name, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1873 |
if (sym.kind == MTH) return (MethodSymbol)sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1874 |
else throw new FatalError( |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1875 |
diags.fragment("fatal.err.cant.locate.meth", |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1876 |
name)); |
10 | 1877 |
} |
1878 |
||
1879 |
/** Resolve constructor. |
|
1880 |
* @param pos The position to use for error reporting. |
|
1881 |
* @param env The environment current at the constructor invocation. |
|
1882 |
* @param site The type of class for which a constructor is searched. |
|
1883 |
* @param argtypes The types of the constructor invocation's value |
|
1884 |
* arguments. |
|
1885 |
* @param typeargtypes The types of the constructor invocation's type |
|
1886 |
* arguments. |
|
1887 |
*/ |
|
1888 |
Symbol resolveConstructor(DiagnosticPosition pos, |
|
1889 |
Env<AttrContext> env, |
|
1890 |
Type site, |
|
1891 |
List<Type> argtypes, |
|
1892 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1893 |
return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1894 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1895 |
private Symbol resolveConstructor(MethodResolutionContext resolveContext, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1896 |
DiagnosticPosition pos, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1897 |
Env<AttrContext> env, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1898 |
Type site, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1899 |
List<Type> argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1900 |
List<Type> typeargtypes) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1901 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1902 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1903 |
currentResolutionContext = resolveContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1904 |
Symbol sym = methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1905 |
List<MethodResolutionPhase> steps = methodResolutionSteps; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1906 |
while (steps.nonEmpty() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1907 |
steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1908 |
sym.kind >= ERRONEOUS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1909 |
currentResolutionContext.step = steps.head; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1910 |
sym = findConstructor(pos, env, site, argtypes, typeargtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1911 |
steps.head.isBoxingRequired(), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1912 |
env.info.varArgs = steps.head.isVarargsRequired()); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1913 |
currentResolutionContext.resolutionCache.put(steps.head, sym); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1914 |
steps = steps.tail; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1915 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1916 |
if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1917 |
MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1918 |
sym = access(currentResolutionContext.resolutionCache.get(errPhase), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1919 |
pos, site, names.init, true, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1920 |
env.info.varArgs = errPhase.isVarargsRequired(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1921 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1922 |
return sym; |
10 | 1923 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1924 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1925 |
currentResolutionContext = prevResolutionContext; |
10 | 1926 |
} |
1927 |
} |
|
1928 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1929 |
/** Resolve constructor using diamond inference. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1930 |
* @param pos The position to use for error reporting. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1931 |
* @param env The environment current at the constructor invocation. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1932 |
* @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
|
1933 |
* The scope of this class has been touched in attribution. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1934 |
* @param argtypes The types of the constructor invocation's value |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1935 |
* arguments. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1936 |
* @param typeargtypes The types of the constructor invocation's type |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1937 |
* arguments. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1938 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1939 |
Symbol resolveDiamond(DiagnosticPosition pos, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1940 |
Env<AttrContext> env, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1941 |
Type site, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1942 |
List<Type> argtypes, |
6344
f190fb7fdd2d
6975275: diamond implementation needs some cleanup
mcimadamore
parents:
6151
diff
changeset
|
1943 |
List<Type> typeargtypes) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1944 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1945 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1946 |
currentResolutionContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1947 |
Symbol sym = methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1948 |
List<MethodResolutionPhase> steps = methodResolutionSteps; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1949 |
while (steps.nonEmpty() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1950 |
steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1951 |
sym.kind >= ERRONEOUS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1952 |
currentResolutionContext.step = steps.head; |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1953 |
sym = findDiamond(env, site, argtypes, typeargtypes, |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1954 |
steps.head.isBoxingRequired(), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1955 |
env.info.varArgs = steps.head.isVarargsRequired()); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1956 |
currentResolutionContext.resolutionCache.put(steps.head, sym); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1957 |
steps = steps.tail; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1958 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1959 |
if (sym.kind >= AMBIGUOUS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1960 |
final JCDiagnostic details = sym.kind == WRONG_MTH ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1961 |
currentResolutionContext.candidates.head.details : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1962 |
null; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1963 |
Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1964 |
@Override |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1965 |
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1966 |
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1967 |
String key = details == null ? |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1968 |
"cant.apply.diamond" : |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1969 |
"cant.apply.diamond.1"; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1970 |
return diags.create(dkind, log.currentSource(), pos, key, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1971 |
diags.fragment("diamond", site.tsym), details); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1972 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1973 |
}; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1974 |
MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1975 |
sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1976 |
env.info.varArgs = errPhase.isVarargsRequired(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1977 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1978 |
return sym; |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1979 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1980 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
1981 |
currentResolutionContext = prevResolutionContext; |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1982 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1983 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
3372
diff
changeset
|
1984 |
|
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1985 |
/** 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
|
1986 |
* assuming that the original scope contains a constructor of the kind: |
13844 | 1987 |
* {@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
|
1988 |
* a method check is executed against the modified constructor type: |
13844 | 1989 |
* {@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
|
1990 |
* 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
|
1991 |
* the inferred type for the diamond operator. |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1992 |
*/ |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1993 |
private Symbol findDiamond(Env<AttrContext> env, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1994 |
Type site, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1995 |
List<Type> argtypes, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1996 |
List<Type> typeargtypes, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1997 |
boolean allowBoxing, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1998 |
boolean useVarargs) { |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
1999 |
Symbol bestSoFar = methodNotFound; |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2000 |
for (Scope.Entry e = site.tsym.members().lookup(names.init); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2001 |
e.scope != null; |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2002 |
e = e.next()) { |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2003 |
//- System.out.println(" e " + e.sym); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2004 |
if (e.sym.kind == MTH && |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2005 |
(e.sym.flags_field & SYNTHETIC) == 0) { |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2006 |
List<Type> oldParams = e.sym.type.tag == FORALL ? |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2007 |
((ForAll)e.sym.type).tvars : |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2008 |
List.<Type>nil(); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2009 |
Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams), |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2010 |
types.createMethodTypeWithReturn(e.sym.type.asMethodType(), site)); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2011 |
bestSoFar = selectBest(env, site, argtypes, typeargtypes, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2012 |
new MethodSymbol(e.sym.flags(), names.init, constrType, site.tsym), |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2013 |
bestSoFar, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2014 |
allowBoxing, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2015 |
useVarargs, |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2016 |
false); |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2017 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2018 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2019 |
return bestSoFar; |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2020 |
} |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12076
diff
changeset
|
2021 |
|
10 | 2022 |
/** Resolve constructor. |
2023 |
* @param pos The position to use for error reporting. |
|
2024 |
* @param env The environment current at the constructor invocation. |
|
2025 |
* @param site The type of class for which a constructor is searched. |
|
2026 |
* @param argtypes The types of the constructor invocation's value |
|
2027 |
* arguments. |
|
2028 |
* @param typeargtypes The types of the constructor invocation's type |
|
2029 |
* arguments. |
|
2030 |
* @param allowBoxing Allow boxing and varargs conversions. |
|
2031 |
* @param useVarargs Box trailing arguments into an array for varargs. |
|
2032 |
*/ |
|
2033 |
Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env, |
|
2034 |
Type site, List<Type> argtypes, |
|
2035 |
List<Type> typeargtypes, |
|
2036 |
boolean allowBoxing, |
|
2037 |
boolean useVarargs) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2038 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2039 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2040 |
currentResolutionContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2041 |
return findConstructor(pos, env, site, argtypes, typeargtypes, allowBoxing, useVarargs); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2042 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2043 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2044 |
currentResolutionContext = prevResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2045 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2046 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2047 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2048 |
Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2049 |
Type site, List<Type> argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2050 |
List<Type> typeargtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2051 |
boolean allowBoxing, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2052 |
boolean useVarargs) { |
10 | 2053 |
Symbol sym = findMethod(env, site, |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2054 |
names.init, argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2055 |
typeargtypes, allowBoxing, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2056 |
useVarargs, false); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8229
diff
changeset
|
2057 |
chk.checkDeprecated(pos, env.info.scope.owner, sym); |
10 | 2058 |
return sym; |
2059 |
} |
|
2060 |
||
2061 |
/** Resolve a constructor, throw a fatal error if not found. |
|
2062 |
* @param pos The position to use for error reporting. |
|
2063 |
* @param env The environment current at the method invocation. |
|
2064 |
* @param site The type to be constructed. |
|
2065 |
* @param argtypes The types of the invocation's value arguments. |
|
2066 |
* @param typeargtypes The types of the invocation's type arguments. |
|
2067 |
*/ |
|
2068 |
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env, |
|
2069 |
Type site, |
|
2070 |
List<Type> argtypes, |
|
2071 |
List<Type> typeargtypes) { |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2072 |
MethodResolutionContext resolveContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2073 |
resolveContext.internalResolution = true; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2074 |
Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes); |
10 | 2075 |
if (sym.kind == MTH) return (MethodSymbol)sym; |
2076 |
else throw new FatalError( |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
2077 |
diags.fragment("fatal.err.cant.locate.ctor", site)); |
10 | 2078 |
} |
2079 |
||
2080 |
/** Resolve operator. |
|
2081 |
* @param pos The position to use for error reporting. |
|
2082 |
* @param optag The tag of the operation tree. |
|
2083 |
* @param env The environment current at the operation. |
|
2084 |
* @param argtypes The types of the operands. |
|
2085 |
*/ |
|
10950 | 2086 |
Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag, |
10 | 2087 |
Env<AttrContext> env, List<Type> argtypes) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2088 |
MethodResolutionContext prevResolutionContext = currentResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2089 |
try { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2090 |
currentResolutionContext = new MethodResolutionContext(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2091 |
Name name = treeinfo.operatorName(optag); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2092 |
Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2093 |
null, false, false, true); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2094 |
if (boxingEnabled && sym.kind >= WRONG_MTHS) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2095 |
sym = findMethod(env, syms.predefClass.type, name, argtypes, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2096 |
null, true, false, true); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2097 |
return access(sym, pos, env.enclClass.sym.type, name, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2098 |
false, argtypes, null); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2099 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2100 |
finally { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2101 |
currentResolutionContext = prevResolutionContext; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2102 |
} |
10 | 2103 |
} |
2104 |
||
2105 |
/** Resolve operator. |
|
2106 |
* @param pos The position to use for error reporting. |
|
2107 |
* @param optag The tag of the operation tree. |
|
2108 |
* @param env The environment current at the operation. |
|
2109 |
* @param arg The type of the operand. |
|
2110 |
*/ |
|
10950 | 2111 |
Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) { |
10 | 2112 |
return resolveOperator(pos, optag, env, List.of(arg)); |
2113 |
} |
|
2114 |
||
2115 |
/** Resolve binary operator. |
|
2116 |
* @param pos The position to use for error reporting. |
|
2117 |
* @param optag The tag of the operation tree. |
|
2118 |
* @param env The environment current at the operation. |
|
2119 |
* @param left The types of the left operand. |
|
2120 |
* @param right The types of the right operand. |
|
2121 |
*/ |
|
2122 |
Symbol resolveBinaryOperator(DiagnosticPosition pos, |
|
10950 | 2123 |
JCTree.Tag optag, |
10 | 2124 |
Env<AttrContext> env, |
2125 |
Type left, |
|
2126 |
Type right) { |
|
2127 |
return resolveOperator(pos, optag, env, List.of(left, right)); |
|
2128 |
} |
|
2129 |
||
2130 |
/** |
|
2131 |
* Resolve `c.name' where name == this or name == super. |
|
2132 |
* @param pos The position to use for error reporting. |
|
2133 |
* @param env The environment current at the expression. |
|
2134 |
* @param c The qualifier. |
|
2135 |
* @param name The identifier's name. |
|
2136 |
*/ |
|
2137 |
Symbol resolveSelf(DiagnosticPosition pos, |
|
2138 |
Env<AttrContext> env, |
|
2139 |
TypeSymbol c, |
|
2140 |
Name name) { |
|
2141 |
Env<AttrContext> env1 = env; |
|
2142 |
boolean staticOnly = false; |
|
2143 |
while (env1.outer != null) { |
|
2144 |
if (isStatic(env1)) staticOnly = true; |
|
2145 |
if (env1.enclClass.sym == c) { |
|
2146 |
Symbol sym = env1.info.scope.lookup(name).sym; |
|
2147 |
if (sym != null) { |
|
2148 |
if (staticOnly) sym = new StaticError(sym); |
|
2149 |
return access(sym, pos, env.enclClass.sym.type, |
|
2150 |
name, true); |
|
2151 |
} |
|
2152 |
} |
|
2153 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
|
2154 |
env1 = env1.outer; |
|
2155 |
} |
|
2156 |
log.error(pos, "not.encl.class", c); |
|
2157 |
return syms.errSymbol; |
|
2158 |
} |
|
2159 |
||
2160 |
/** |
|
2161 |
* Resolve `c.this' for an enclosing class c that contains the |
|
2162 |
* named member. |
|
2163 |
* @param pos The position to use for error reporting. |
|
2164 |
* @param env The environment current at the expression. |
|
2165 |
* @param member The member that must be contained in the result. |
|
2166 |
*/ |
|
2167 |
Symbol resolveSelfContaining(DiagnosticPosition pos, |
|
2168 |
Env<AttrContext> env, |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2169 |
Symbol member, |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2170 |
boolean isSuperCall) { |
10 | 2171 |
Name name = names._this; |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2172 |
Env<AttrContext> env1 = isSuperCall ? env.outer : env; |
10 | 2173 |
boolean staticOnly = false; |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2174 |
if (env1 != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2175 |
while (env1 != null && env1.outer != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2176 |
if (isStatic(env1)) staticOnly = true; |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2177 |
if (env1.enclClass.sym.isSubClass(member.owner, types)) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2178 |
Symbol sym = env1.info.scope.lookup(name).sym; |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2179 |
if (sym != null) { |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2180 |
if (staticOnly) sym = new StaticError(sym); |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2181 |
return access(sym, pos, env.enclClass.sym.type, |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2182 |
name, true); |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2183 |
} |
10 | 2184 |
} |
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2185 |
if ((env1.enclClass.sym.flags() & STATIC) != 0) |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2186 |
staticOnly = true; |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2187 |
env1 = env1.outer; |
10 | 2188 |
} |
2189 |
} |
|
2190 |
log.error(pos, "encl.class.required", member); |
|
2191 |
return syms.errSymbol; |
|
2192 |
} |
|
2193 |
||
2194 |
/** |
|
2195 |
* 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
|
2196 |
* JLS 8.8.5.1 and 15.9.2 |
10 | 2197 |
*/ |
2198 |
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) { |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2199 |
return resolveImplicitThis(pos, env, t, false); |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2200 |
} |
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2201 |
|
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2202 |
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) { |
10 | 2203 |
Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0) |
2204 |
? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8430
diff
changeset
|
2205 |
: resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type; |
10 | 2206 |
if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) |
2207 |
log.error(pos, "cant.ref.before.ctor.called", "this"); |
|
2208 |
return thisType; |
|
2209 |
} |
|
2210 |
||
2211 |
/* *************************************************************************** |
|
2212 |
* ResolveError classes, indicating error situations when accessing symbols |
|
2213 |
****************************************************************************/ |
|
2214 |
||
12082
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
2215 |
//used by TransTypes when checking target type of synthetic cast |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
2216 |
public void logAccessErrorInternal(Env<AttrContext> env, JCTree tree, Type type) { |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
2217 |
AccessError error = new AccessError(env, env.enclClass.type, type.tsym); |
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
12078
diff
changeset
|
2218 |
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
|
2219 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2220 |
//where |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2221 |
private void logResolveError(ResolveError error, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2222 |
DiagnosticPosition pos, |
8045 | 2223 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2224 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2225 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2226 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2227 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2228 |
JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, |
8045 | 2229 |
pos, location, site, name, argtypes, typeargtypes); |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
2230 |
if (d != null) { |
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
2231 |
d.setFlag(DiagnosticFlag.RESOLVE_ERROR); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2232 |
log.report(d); |
6356
af24929939ca
6976747: JCDiagnostic: replace "boolean mandatory" with new "Set<JCDiagnostic.Flag>"
jjg
parents:
6344
diff
changeset
|
2233 |
} |
10 | 2234 |
} |
2235 |
||
1534
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
2236 |
private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); |
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
2237 |
|
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
2238 |
public Object methodArguments(List<Type> argtypes) { |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
2239 |
return argtypes == null || argtypes.isEmpty() ? noArgs : argtypes; |
1534
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
2240 |
} |
e923a41e84cc
6758789: Some method resolution diagnostic should be improved
mcimadamore
parents:
1533
diff
changeset
|
2241 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2242 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2243 |
* Root class for resolution errors. Subclass of ResolveError |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2244 |
* represent a different kinds of resolution error - as such they must |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2245 |
* specify how they map into concrete compiler diagnostics. |
10 | 2246 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2247 |
private abstract class ResolveError extends Symbol { |
10 | 2248 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2249 |
/** The name of the kind of error, for debugging only. */ |
10 | 2250 |
final String debugName; |
2251 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2252 |
ResolveError(int kind, String debugName) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2253 |
super(kind, 0, null, null, null); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2254 |
this.debugName = debugName; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2255 |
} |
10 | 2256 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2257 |
@Override |
10 | 2258 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
2259 |
throw new AssertionError(); |
|
2260 |
} |
|
2261 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2262 |
@Override |
10 | 2263 |
public String toString() { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2264 |
return debugName; |
10 | 2265 |
} |
2266 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2267 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2268 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2269 |
return false; |
10 | 2270 |
} |
2271 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2272 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2273 |
* Create an external representation for this erroneous symbol to be |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2274 |
* used during attribution - by default this returns the symbol of a |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2275 |
* brand new error type which stores the original type found |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2276 |
* during resolution. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2277 |
* |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2278 |
* @param name the name used during resolution |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2279 |
* @param location the location from which the symbol is accessed |
10 | 2280 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2281 |
protected Symbol access(Name name, TypeSymbol location) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2282 |
return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
10 | 2283 |
} |
2284 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2285 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2286 |
* Create a diagnostic representing this resolution error. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2287 |
* |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2288 |
* @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
|
2289 |
* @param pos The position to be used for error reporting. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2290 |
* @param site The original type from where the selection took place. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2291 |
* @param name The name of the symbol to be resolved. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2292 |
* @param argtypes The invocation's value arguments, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2293 |
* if we looked for a method. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2294 |
* @param typeargtypes The invocation's type arguments, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2295 |
* if we looked for a method. |
10 | 2296 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2297 |
abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2298 |
DiagnosticPosition pos, |
8045 | 2299 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2300 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2301 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2302 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2303 |
List<Type> typeargtypes); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2304 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2305 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2306 |
* A name designates an operator if it consists |
13844 | 2307 |
* of a non-empty sequence of operator symbols {@literal +-~!/*%&|^<>= } |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2308 |
*/ |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2309 |
boolean isOperator(Name name) { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2310 |
int i = 0; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2311 |
while (i < name.getByteLength() && |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2312 |
"+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++; |
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2313 |
return i > 0 && i == name.getByteLength(); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2314 |
} |
10 | 2315 |
} |
2316 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2317 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2318 |
* 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
|
2319 |
* an invalid symbol being found during resolution. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2320 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2321 |
abstract class InvalidSymbolError extends ResolveError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2322 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2323 |
/** The invalid symbol found during resolution */ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2324 |
Symbol sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2325 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2326 |
InvalidSymbolError(int kind, Symbol sym, String debugName) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2327 |
super(kind, debugName); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2328 |
this.sym = sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2329 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2330 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2331 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2332 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2333 |
return true; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2334 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2335 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2336 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2337 |
public String toString() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2338 |
return super.toString() + " wrongSym=" + sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2339 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2340 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2341 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2342 |
public Symbol access(Name name, TypeSymbol location) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2343 |
if (sym.kind >= AMBIGUOUS) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2344 |
return ((ResolveError)sym).access(name, location); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2345 |
else if ((sym.kind & ERRONEOUS) == 0 && (sym.kind & TYP) != 0) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2346 |
return types.createErrorType(name, location, sym.type).tsym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2347 |
else |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2348 |
return sym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2349 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2350 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2351 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2352 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2353 |
* InvalidSymbolError error class indicating that a symbol matching a |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2354 |
* given name does not exists in a given site. |
10 | 2355 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2356 |
class SymbolNotFoundError extends ResolveError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2357 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2358 |
SymbolNotFoundError(int kind) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2359 |
super(kind, "symbol not found error"); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2360 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2361 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2362 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2363 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2364 |
DiagnosticPosition pos, |
8045 | 2365 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2366 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2367 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2368 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2369 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2370 |
argtypes = argtypes == null ? List.<Type>nil() : argtypes; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2371 |
typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2372 |
if (name == names.error) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2373 |
return null; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2374 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2375 |
if (isOperator(name)) { |
8045 | 2376 |
boolean isUnaryOp = argtypes.size() == 1; |
2377 |
String key = argtypes.size() == 1 ? |
|
2378 |
"operator.cant.be.applied" : |
|
2379 |
"operator.cant.be.applied.1"; |
|
2380 |
Type first = argtypes.head; |
|
2381 |
Type second = !isUnaryOp ? argtypes.tail.head : null; |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2382 |
return diags.create(dkind, log.currentSource(), pos, |
8045 | 2383 |
key, name, first, second); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2384 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2385 |
boolean hasLocation = false; |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2386 |
if (location == null) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2387 |
location = site.tsym; |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2388 |
} |
8045 | 2389 |
if (!location.name.isEmpty()) { |
2390 |
if (location.kind == PCK && !site.tsym.exists()) { |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2391 |
return diags.create(dkind, log.currentSource(), pos, |
8045 | 2392 |
"doesnt.exist", location); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2393 |
} |
8045 | 2394 |
hasLocation = !location.name.equals(names._this) && |
2395 |
!location.name.equals(names._super); |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2396 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2397 |
boolean isConstructor = kind == ABSENT_MTH && |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2398 |
name == names.table.names.init; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2399 |
KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2400 |
Name idname = isConstructor ? site.tsym.name : name; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2401 |
String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2402 |
if (hasLocation) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2403 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2404 |
errKey, kindname, idname, //symbol kindname, name |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2405 |
typeargtypes, argtypes, //type parameters and arguments (if any) |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2406 |
getLocationDiag(location, site)); //location kindname, type |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2407 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2408 |
else { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2409 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2410 |
errKey, kindname, idname, //symbol kindname, name |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2411 |
typeargtypes, argtypes); //type parameters and arguments (if any) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2412 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2413 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2414 |
//where |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2415 |
private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2416 |
String key = "cant.resolve"; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2417 |
String suffix = hasLocation ? ".location" : ""; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2418 |
switch (kindname) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2419 |
case METHOD: |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2420 |
case CONSTRUCTOR: { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2421 |
suffix += ".args"; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2422 |
suffix += hasTypeArgs ? ".params" : ""; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2423 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2424 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2425 |
return key + suffix; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2426 |
} |
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2427 |
private JCDiagnostic getLocationDiag(Symbol location, Type site) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2428 |
if (location.kind == VAR) { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2429 |
return diags.fragment("location.1", |
8045 | 2430 |
kindName(location), |
2431 |
location, |
|
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2432 |
location.type); |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2433 |
} else { |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2434 |
return diags.fragment("location", |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2435 |
typeKindName(site), |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2436 |
site, |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2437 |
null); |
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
2438 |
} |
8045 | 2439 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2440 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2441 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2442 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2443 |
* InvalidSymbolError error class indicating that a given symbol |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2444 |
* (either a method, a constructor or an operand) is not applicable |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2445 |
* given an actual arguments/type argument list. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2446 |
*/ |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2447 |
class InapplicableSymbolError extends ResolveError { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2448 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2449 |
InapplicableSymbolError() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2450 |
super(WRONG_MTH, "inapplicable symbol error"); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2451 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2452 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2453 |
protected InapplicableSymbolError(int kind, String debugName) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2454 |
super(kind, debugName); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2455 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2456 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2457 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2458 |
public String toString() { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2459 |
return super.toString(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2460 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2461 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2462 |
@Override |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2463 |
public boolean exists() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2464 |
return true; |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2465 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2466 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2467 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2468 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2469 |
DiagnosticPosition pos, |
8045 | 2470 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2471 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2472 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2473 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2474 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2475 |
if (name == names.error) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2476 |
return null; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2477 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2478 |
if (isOperator(name)) { |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2479 |
boolean isUnaryOp = argtypes.size() == 1; |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2480 |
String key = argtypes.size() == 1 ? |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2481 |
"operator.cant.be.applied" : |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2482 |
"operator.cant.be.applied.1"; |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2483 |
Type first = argtypes.head; |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2484 |
Type second = !isUnaryOp ? argtypes.tail.head : null; |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2485 |
return diags.create(dkind, log.currentSource(), pos, |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2486 |
key, name, first, second); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2487 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2488 |
else { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2489 |
Candidate c = errCandidate(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2490 |
Symbol ws = c.sym.asMemberOf(site, types); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2491 |
return diags.create(dkind, log.currentSource(), pos, |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2492 |
"cant.apply.symbol" + (c.details != null ? ".1" : ""), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2493 |
kindName(ws), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2494 |
ws.name == names.init ? ws.owner.name : ws.name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2495 |
methodArguments(ws.type.getParameterTypes()), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2496 |
methodArguments(argtypes), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2497 |
kindName(ws.owner), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2498 |
ws.owner.type, |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2499 |
c.details); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2500 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2501 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2502 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2503 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2504 |
public Symbol access(Name name, TypeSymbol location) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2505 |
return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2506 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2507 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2508 |
protected boolean shouldReport(Candidate c) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2509 |
return !c.isApplicable() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2510 |
(((c.sym.flags() & VARARGS) != 0 && c.step == VARARITY) || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2511 |
(c.sym.flags() & VARARGS) == 0 && c.step == (boxingEnabled ? BOX : BASIC)); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2512 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2513 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2514 |
private Candidate errCandidate() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2515 |
for (Candidate c : currentResolutionContext.candidates) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2516 |
if (shouldReport(c)) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2517 |
return c; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2518 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2519 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2520 |
Assert.error(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2521 |
return null; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2522 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2523 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2524 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2525 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2526 |
* ResolveError error class indicating that a set of symbols |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2527 |
* (either methods, constructors or operands) is not applicable |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2528 |
* given an actual arguments/type argument list. |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2529 |
*/ |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2530 |
class InapplicableSymbolsError extends InapplicableSymbolError { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2531 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2532 |
InapplicableSymbolsError() { |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2533 |
super(WRONG_MTHS, "inapplicable symbols"); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2534 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2535 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2536 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2537 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2538 |
DiagnosticPosition pos, |
8045 | 2539 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2540 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2541 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2542 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2543 |
List<Type> typeargtypes) { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2544 |
if (currentResolutionContext.candidates.nonEmpty()) { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2545 |
JCDiagnostic err = diags.create(dkind, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2546 |
log.currentSource(), |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2547 |
pos, |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2548 |
"cant.apply.symbols", |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2549 |
name == names.init ? KindName.CONSTRUCTOR : absentKind(kind), |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2550 |
getName(), |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2551 |
argtypes); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2552 |
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2553 |
} else { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2554 |
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, |
8045 | 2555 |
location, site, name, argtypes, typeargtypes); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2556 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2557 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2558 |
|
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2559 |
//where |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2560 |
List<JCDiagnostic> candidateDetails(Type site) { |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2561 |
List<JCDiagnostic> details = List.nil(); |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2562 |
for (Candidate c : currentResolutionContext.candidates) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2563 |
if (!shouldReport(c)) continue; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2564 |
JCDiagnostic detailDiag = diags.fragment("inapplicable.method", |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2565 |
Kinds.kindName(c.sym), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2566 |
c.sym.location(site, types), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2567 |
c.sym.asMemberOf(site, types), |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2568 |
c.details); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2569 |
details = details.prepend(detailDiag); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2570 |
} |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2571 |
return details.reverse(); |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2572 |
} |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2573 |
|
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2574 |
private Name getName() { |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2575 |
Symbol sym = currentResolutionContext.candidates.head.sym; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2576 |
return sym.name == names.init ? |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2577 |
sym.owner.name : |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2578 |
sym.name; |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2579 |
} |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2580 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2581 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2582 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2583 |
* An InvalidSymbolError error class indicating that a symbol is not |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2584 |
* accessible from a given site |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2585 |
*/ |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2586 |
class AccessError extends InvalidSymbolError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2587 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2588 |
private Env<AttrContext> env; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2589 |
private Type site; |
10 | 2590 |
|
2591 |
AccessError(Symbol sym) { |
|
2592 |
this(null, null, sym); |
|
2593 |
} |
|
2594 |
||
2595 |
AccessError(Env<AttrContext> env, Type site, Symbol sym) { |
|
2596 |
super(HIDDEN, sym, "access error"); |
|
2597 |
this.env = env; |
|
2598 |
this.site = site; |
|
2599 |
if (debugResolve) |
|
2600 |
log.error("proc.messager", sym + " @ " + site + " is inaccessible."); |
|
2601 |
} |
|
2602 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2603 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2604 |
public boolean exists() { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2605 |
return false; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2606 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2607 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2608 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2609 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2610 |
DiagnosticPosition pos, |
8045 | 2611 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2612 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2613 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2614 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2615 |
List<Type> typeargtypes) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2616 |
if (sym.owner.type.tag == ERROR) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2617 |
return null; |
10 | 2618 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2619 |
if (sym.name == names.init && sym.owner != site.tsym) { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2620 |
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, |
8045 | 2621 |
pos, location, site, name, argtypes, typeargtypes); |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2622 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2623 |
else if ((sym.flags() & PUBLIC) != 0 |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2624 |
|| (env != null && this.site != null |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2625 |
&& !isAccessible(env, this.site))) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2626 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2627 |
pos, "not.def.access.class.intf.cant.access", |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2628 |
sym, sym.location()); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2629 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2630 |
else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2631 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2632 |
pos, "report.access", sym, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2633 |
asFlagSet(sym.flags() & (PRIVATE | PROTECTED)), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2634 |
sym.location()); |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2635 |
} |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2636 |
else { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2637 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2638 |
pos, "not.def.public.cant.access", sym, sym.location()); |
10 | 2639 |
} |
2640 |
} |
|
2641 |
} |
|
2642 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2643 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2644 |
* InvalidSymbolError error class indicating that an instance member |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2645 |
* has erroneously been accessed from a static context. |
10 | 2646 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2647 |
class StaticError extends InvalidSymbolError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2648 |
|
10 | 2649 |
StaticError(Symbol sym) { |
2650 |
super(STATICERR, sym, "static error"); |
|
2651 |
} |
|
2652 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2653 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2654 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2655 |
DiagnosticPosition pos, |
8045 | 2656 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2657 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2658 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2659 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2660 |
List<Type> typeargtypes) { |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2661 |
Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS) |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2662 |
? types.erasure(sym.type).tsym |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2663 |
: sym); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2664 |
return diags.create(dkind, log.currentSource(), pos, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2665 |
"non-static.cant.be.ref", kindName(sym), errSym); |
10 | 2666 |
} |
2667 |
} |
|
2668 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2669 |
/** |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2670 |
* InvalidSymbolError error class indicating that a pair of symbols |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2671 |
* (either methods, constructors or operands) are ambiguous |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2672 |
* given an actual arguments/type argument list. |
10 | 2673 |
*/ |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2674 |
class AmbiguityError extends InvalidSymbolError { |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2675 |
|
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2676 |
/** The other maximally specific symbol */ |
10 | 2677 |
Symbol sym2; |
2678 |
||
2679 |
AmbiguityError(Symbol sym1, Symbol sym2) { |
|
2680 |
super(AMBIGUOUS, sym1, "ambiguity error"); |
|
2681 |
this.sym2 = sym2; |
|
2682 |
} |
|
2683 |
||
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2684 |
@Override |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2685 |
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2686 |
DiagnosticPosition pos, |
8045 | 2687 |
Symbol location, |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2688 |
Type site, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2689 |
Name name, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2690 |
List<Type> argtypes, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2691 |
List<Type> typeargtypes) { |
10 | 2692 |
AmbiguityError pair = this; |
2693 |
while (true) { |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2694 |
if (pair.sym.kind == AMBIGUOUS) |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2695 |
pair = (AmbiguityError)pair.sym; |
10 | 2696 |
else if (pair.sym2.kind == AMBIGUOUS) |
2697 |
pair = (AmbiguityError)pair.sym2; |
|
2698 |
else break; |
|
2699 |
} |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2700 |
Name sname = pair.sym.name; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2701 |
if (sname == names.init) sname = pair.sym.owner.name; |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5857
diff
changeset
|
2702 |
return diags.create(dkind, log.currentSource(), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2703 |
pos, "ref.ambiguous", sname, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2704 |
kindName(pair.sym), |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2705 |
pair.sym, |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
3140
diff
changeset
|
2706 |
pair.sym.location(site, types), |
10 | 2707 |
kindName(pair.sym2), |
2708 |
pair.sym2, |
|
2709 |
pair.sym2.location(site, types)); |
|
2710 |
} |
|
2711 |
} |
|
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2712 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2713 |
enum MethodResolutionPhase { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2714 |
BASIC(false, false), |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2715 |
BOX(true, false), |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2716 |
VARARITY(true, true); |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2717 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2718 |
boolean isBoxingRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2719 |
boolean isVarargsRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2720 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2721 |
MethodResolutionPhase(boolean isBoxingRequired, boolean isVarargsRequired) { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2722 |
this.isBoxingRequired = isBoxingRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2723 |
this.isVarargsRequired = isVarargsRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2724 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2725 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2726 |
public boolean isBoxingRequired() { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2727 |
return isBoxingRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2728 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2729 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2730 |
public boolean isVarargsRequired() { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2731 |
return isVarargsRequired; |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2732 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2733 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2734 |
public boolean isApplicable(boolean boxingEnabled, boolean varargsEnabled) { |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2735 |
return (varargsEnabled || !isVarargsRequired) && |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2736 |
(boxingEnabled || !isBoxingRequired); |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2737 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2738 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2739 |
|
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2740 |
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
|
2741 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2742 |
/** |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2743 |
* 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
|
2744 |
* overload resolution, such as list of method that are not applicable |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2745 |
* (used to generate more precise diagnostics) and so on. Resolution contexts |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2746 |
* 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
|
2747 |
* work within the resolution context it created. |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2748 |
*/ |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2749 |
class MethodResolutionContext { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2750 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2751 |
private List<Candidate> candidates = List.nil(); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2752 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2753 |
private Map<MethodResolutionPhase, Symbol> resolutionCache = |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2754 |
new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2755 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2756 |
private MethodResolutionPhase step = null; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2757 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2758 |
private boolean internalResolution = false; |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
2759 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2760 |
private MethodResolutionPhase firstErroneousResolutionPhase() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2761 |
MethodResolutionPhase bestSoFar = BASIC; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2762 |
Symbol sym = methodNotFound; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2763 |
List<MethodResolutionPhase> steps = methodResolutionSteps; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2764 |
while (steps.nonEmpty() && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2765 |
steps.head.isApplicable(boxingEnabled, varargsEnabled) && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2766 |
sym.kind >= WRONG_MTHS) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2767 |
sym = resolutionCache.get(steps.head); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2768 |
bestSoFar = steps.head; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2769 |
steps = steps.tail; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2770 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2771 |
return bestSoFar; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2772 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2773 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2774 |
void addInapplicableCandidate(Symbol sym, JCDiagnostic details) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2775 |
Candidate c = new Candidate(currentResolutionContext.step, sym, details, null); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2776 |
if (!candidates.contains(c)) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2777 |
candidates = candidates.append(c); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2778 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2779 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2780 |
void addApplicableCandidate(Symbol sym, Type mtype) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2781 |
Candidate c = new Candidate(currentResolutionContext.step, sym, null, mtype); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2782 |
candidates = candidates.append(c); |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2783 |
} |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10812
diff
changeset
|
2784 |
|
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2785 |
/** |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2786 |
* This class represents an overload resolution candidate. There are two |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2787 |
* kinds of candidates: applicable methods and inapplicable methods; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2788 |
* applicable methods have a pointer to the instantiated method type, |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2789 |
* while inapplicable candidates contain further details about the |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2790 |
* reason why the method has been considered inapplicable. |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2791 |
*/ |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2792 |
class Candidate { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2793 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2794 |
final MethodResolutionPhase step; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2795 |
final Symbol sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2796 |
final JCDiagnostic details; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2797 |
final Type mtype; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2798 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2799 |
private Candidate(MethodResolutionPhase step, Symbol sym, JCDiagnostic details, Type mtype) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2800 |
this.step = step; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2801 |
this.sym = sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2802 |
this.details = details; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2803 |
this.mtype = mtype; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2804 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2805 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2806 |
@Override |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2807 |
public boolean equals(Object o) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2808 |
if (o instanceof Candidate) { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2809 |
Symbol s1 = this.sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2810 |
Symbol s2 = ((Candidate)o).sym; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2811 |
if ((s1 != s2 && |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2812 |
(s1.overrides(s2, s1.owner.type.tsym, types, false) || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2813 |
(s2.overrides(s1, s2.owner.type.tsym, types, false)))) || |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2814 |
((s1.isConstructor() || s2.isConstructor()) && s1.owner != s2.owner)) |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2815 |
return true; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2816 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2817 |
return false; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2818 |
} |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2819 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2820 |
boolean isApplicable() { |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2821 |
return mtype != null; |
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2822 |
} |
1533
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2823 |
} |
6a9a2f681d24
6746184: javac fails to compile call to public varargs method
mcimadamore
parents:
1529
diff
changeset
|
2824 |
} |
12076
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2825 |
|
1b7560bd1760
7132880: Resolve should support nested resolution contexts
mcimadamore
parents:
11707
diff
changeset
|
2826 |
MethodResolutionContext currentResolutionContext = null; |
10 | 2827 |
} |