mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8023545: Misleading error message when using diamond operator with private constructor
Reviewed-by: jjg
This commit is contained in:
parent
06caeea3d6
commit
cab6b226ff
3 changed files with 38 additions and 16 deletions
|
@ -2546,22 +2546,26 @@ public class Resolve {
|
||||||
@Override
|
@Override
|
||||||
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
|
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
|
||||||
if (sym.kind >= AMBIGUOUS) {
|
if (sym.kind >= AMBIGUOUS) {
|
||||||
final JCDiagnostic details = sym.kind == WRONG_MTH ?
|
if (sym.kind == HIDDEN) {
|
||||||
((InapplicableSymbolError)sym).errCandidate().snd :
|
sym = super.access(env, pos, location, sym);
|
||||||
null;
|
} else {
|
||||||
sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
|
final JCDiagnostic details = sym.kind == WRONG_MTH ?
|
||||||
@Override
|
((InapplicableSymbolError)sym).errCandidate().snd :
|
||||||
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
|
null;
|
||||||
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
|
sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
|
||||||
String key = details == null ?
|
@Override
|
||||||
"cant.apply.diamond" :
|
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
|
||||||
"cant.apply.diamond.1";
|
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
|
||||||
return diags.create(dkind, log.currentSource(), pos, key,
|
String key = details == null ?
|
||||||
diags.fragment("diamond", site.tsym), details);
|
"cant.apply.diamond" :
|
||||||
}
|
"cant.apply.diamond.1";
|
||||||
};
|
return diags.create(dkind, log.currentSource(), pos, key,
|
||||||
sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
|
diags.fragment("diamond", site.tsym), details);
|
||||||
env.info.pendingResolutionPhase = currentResolutionContext.step;
|
}
|
||||||
|
};
|
||||||
|
sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
|
||||||
|
env.info.pendingResolutionPhase = currentResolutionContext.step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sym;
|
return sym;
|
||||||
}});
|
}});
|
||||||
|
|
|
@ -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() {}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
MisleadingErrorMsgDiamondPlusPrivateCtorTest.java:10:31: compiler.err.report.access: <E>MyClass(), private, MyClass
|
||||||
|
1 error
|
Loading…
Add table
Add a link
Reference in a new issue