Mercurial > hg > openjdk > lambda > langtools
changeset 2242:a81cf02dfe46
8020843: javac crashes on accessibility check with method reference with typevar receiver (take two)
Refine logic for selecting error message to be reported in the bound/unbound lookup.
author | mcimadamore |
---|---|
date | Fri, 19 Jul 2013 15:12:24 +0100 |
parents | 7f4fc4264f61 |
children | 718064a04b56 |
files | src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/lambda/8020843/T8020843.java test/tools/javac/lambda/8020843/T8020843.out test/tools/javac/lambda/8020843/T8020843a.java test/tools/javac/lambda/8020843/T8020843a.out test/tools/javac/lambda/8020843/T8020843b.java test/tools/javac/lambda/8020843/T8020843b.out test/tools/javac/lambda/MethodReference28.out |
diffstat | 8 files changed, 94 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jul 19 12:36:19 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Jul 19 15:12:24 2013 +0100 @@ -2689,22 +2689,50 @@ //merge results Pair<Symbol, ReferenceLookupHelper> res; - if (!lookupSuccess(unboundSym)) { - res = new Pair<Symbol, ReferenceLookupHelper>(boundSym, boundLookupHelper); - env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase; - } else if (lookupSuccess(boundSym)) { - res = new Pair<Symbol, ReferenceLookupHelper>(ambiguityError(boundSym, unboundSym), boundLookupHelper); - env.info.pendingResolutionPhase = boundEnv.info.pendingResolutionPhase; - } else { - res = new Pair<Symbol, ReferenceLookupHelper>(unboundSym, unboundLookupHelper); - env.info.pendingResolutionPhase = unboundEnv.info.pendingResolutionPhase; - } + Symbol bestSym = choose(boundSym, unboundSym); + res = new Pair<Symbol, ReferenceLookupHelper>(bestSym, + bestSym == unboundSym ? unboundLookupHelper : boundLookupHelper); + env.info.pendingResolutionPhase = bestSym == unboundSym ? + unboundEnv.info.pendingResolutionPhase : + boundEnv.info.pendingResolutionPhase; return res; } - //private - boolean lookupSuccess(Symbol s) { - return s.kind == MTH || s.kind == AMBIGUOUS || s.kind == HIDDEN; + //where + private Symbol choose(Symbol s1, Symbol s2) { + if (lookupSuccess(s1) && lookupSuccess(s2)) { + return ambiguityError(s1, s2); + } else if (lookupSuccess(s1) || + (canIgnore(s2) && !canIgnore(s1))) { + return s1; + } else if (lookupSuccess(s2) || + (canIgnore(s1) && !canIgnore(s2))) { + return s2; + } else { + return s1; + } + } + + private boolean lookupSuccess(Symbol s) { + return s.kind == MTH || s.kind == AMBIGUOUS; + } + + private boolean canIgnore(Symbol s) { + switch (s.kind) { + case ABSENT_MTH: + return true; + case WRONG_MTH: + InapplicableSymbolError errSym = + (InapplicableSymbolError)s; + return new Template(MethodCheckDiag.ARITY_MISMATCH.regex()) + .matches(errSym.errCandidate().snd); + case WRONG_MTHS: + InapplicableSymbolsError errSyms = + (InapplicableSymbolsError)s; + return errSyms.filterCandidates(errSyms.mapCandidates()).isEmpty(); + default: + return false; + } } /** @@ -3496,7 +3524,9 @@ List<Type> argtypes, List<Type> typeargtypes) { Map<Symbol, JCDiagnostic> candidatesMap = mapCandidates(); - Map<Symbol, JCDiagnostic> filteredCandidates = filterCandidates(candidatesMap); + Map<Symbol, JCDiagnostic> filteredCandidates = compactMethodDiags ? + filterCandidates(candidatesMap) : + mapCandidates(); if (filteredCandidates.isEmpty()) { filteredCandidates = candidatesMap; } @@ -3548,8 +3578,7 @@ Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<Symbol, JCDiagnostic>(); for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) { JCDiagnostic d = _entry.getValue(); - if (!compactMethodDiags || - !new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) { + if (!new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) { candidates.put(_entry.getKey(), d); } }
--- a/test/tools/javac/lambda/8020843/T8020843.java Fri Jul 19 12:36:19 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @bug 8020843 - * @summary javac crashes on accessibility check with method reference with typevar receiver - * @compile/fail/ref=T8020843.out -XDrawDiagnostics T8020843.java - */ - -class T8020843 { - interface Function<X, Y> { - Y m(X x); - } - - <T> void test(T t) { - Function<T, Object> ss = T::clone; - } -}
--- a/test/tools/javac/lambda/8020843/T8020843.out Fri Jul 19 12:36:19 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -T8020843.java:14:34: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.report.access: clone(), protected, java.lang.Object)) -1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8020843/T8020843a.java Fri Jul 19 15:12:24 2013 +0100 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8020843 + * @summary javac crashes on accessibility check with method reference with typevar receiver + * @compile/fail/ref=T8020843a.out -XDrawDiagnostics T8020843a.java + */ + +class T8020843a { + interface Function<X, Y> { + Y m(X x); + } + + <T> void test(T t) { + Function<T, Object> ss = T::clone; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8020843/T8020843a.out Fri Jul 19 15:12:24 2013 +0100 @@ -0,0 +1,2 @@ +T8020843a.java:14:34: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.report.access: clone(), protected, java.lang.Object)) +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8020843/T8020843b.java Fri Jul 19 15:12:24 2013 +0100 @@ -0,0 +1,27 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8020843 + * @summary javac crashes on accessibility check with method reference with typevar receiver + * @compile/fail/ref=T8020843b.out -XDrawDiagnostics T8020843b.java + */ + +class T8020843b { + interface Function<X, Y> { + Y m(X x); + } + + interface BiFunction<X, Y, Z> { + Z m(X x, Y y); + } + + Object m(int i) { return null; } + static Object m(String t) { return null; } + + Object m2(int i) { return null; } + static Object m2(long t) { return null; } + + static void test() { + Function<T8020843b, Object> f1 = T8020843b::m; //show bound case diag + BiFunction<T8020843b, String, Object> f2 = T8020843b::m2; //show unbound case diag + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8020843/T8020843b.out Fri Jul 19 15:12:24 2013 +0100 @@ -0,0 +1,3 @@ +T8020843b.java:24:42: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbols: kindname.method, m, T8020843b,{(compiler.misc.inapplicable.method: kindname.method, T8020843b, m(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: T8020843b, int))),(compiler.misc.inapplicable.method: kindname.method, T8020843b, m(java.lang.String), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: T8020843b, java.lang.String)))})) +T8020843b.java:25:52: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbols: kindname.method, m2, T8020843b,java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, T8020843b, m2(int), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, int))),(compiler.misc.inapplicable.method: kindname.method, T8020843b, m2(long), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, long)))})) +2 errors
--- a/test/tools/javac/lambda/MethodReference28.out Fri Jul 19 12:36:19 2013 +0100 +++ b/test/tools/javac/lambda/MethodReference28.out Fri Jul 19 15:12:24 2013 +0100 @@ -9,6 +9,6 @@ MethodReference28.java:46:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m3, java.lang.String, int, kindname.class, MethodReference28, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: int, java.lang.String)))) MethodReference28.java:47:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m4, java.lang.String[], int, kindname.class, MethodReference28, (compiler.misc.varargs.argument.mismatch: (compiler.misc.inconvertible.types: int, java.lang.String)))) MethodReference28.java:52:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m2, java.lang.Integer,java.lang.Integer, MethodReference28,int, kindname.class, MethodReference28, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: MethodReference28, java.lang.Integer)))) -MethodReference28.java:53:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m3, java.lang.String, MethodReference28,int, kindname.class, MethodReference28, (compiler.misc.arg.length.mismatch))) +MethodReference28.java:53:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m3, java.lang.String, MethodReference28,int, kindname.class, MethodReference28, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: int, java.lang.String)))) MethodReference28.java:54:19: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, m4, java.lang.String[], MethodReference28,int, kindname.class, MethodReference28, (compiler.misc.varargs.argument.mismatch: (compiler.misc.inconvertible.types: MethodReference28, java.lang.String)))) 13 errors