8023545: Misleading error message when using diamond operator with private constructor

Reviewed-by: jjg
This commit is contained in:
Vicente Romero 2013-09-03 23:41:37 +01:00
parent 06caeea3d6
commit cab6b226ff
3 changed files with 38 additions and 16 deletions

View file

@ -2546,6 +2546,9 @@ public class Resolve {
@Override
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind >= AMBIGUOUS) {
if (sym.kind == HIDDEN) {
sym = super.access(env, pos, location, sym);
} else {
final JCDiagnostic details = sym.kind == WRONG_MTH ?
((InapplicableSymbolError)sym).errCandidate().snd :
null;
@ -2563,6 +2566,7 @@ public class Resolve {
sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
env.info.pendingResolutionPhase = currentResolutionContext.step;
}
}
return sym;
}});
}

View file

@ -0,0 +1,16 @@
/*
* @test /nodynamiccopyright/
* @bug 8023545
* @summary Misleading error message when using diamond operator with private constructor
* @compile/fail/ref=MisleadingErrorMsgDiamondPlusPrivateCtorTest.out -XDrawDiagnostics MisleadingErrorMsgDiamondPlusPrivateCtorTest.java
*/
public class MisleadingErrorMsgDiamondPlusPrivateCtorTest {
public void foo() {
MyClass<Object> foo = new MyClass<>();
}
}
class MyClass<E> {
private MyClass() {}
}

View file

@ -0,0 +1,2 @@
MisleadingErrorMsgDiamondPlusPrivateCtorTest.java:10:31: compiler.err.report.access: <E>MyClass(), private, MyClass
1 error