Render the descriptor in "cannot infer visibility" message

Otherwise it's unclear what member is problematic if it's a fake override
(because the diagnostic in that case is reported on the whole class)
This commit is contained in:
Alexander Udalov
2014-05-21 19:11:00 +04:00
parent db25f568dc
commit 1706bd4a00
6 changed files with 22 additions and 3 deletions
@@ -217,7 +217,7 @@ public interface Errors {
DiagnosticFactory2<JetAnnotationEntry, CallableMemberDescriptor, DeclarationDescriptor> DATA_CLASS_OVERRIDE_CONFLICT =
DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<JetDeclaration> CANNOT_INFER_VISIBILITY = DiagnosticFactory0.create(ERROR, DECLARATION);
DiagnosticFactory1<JetDeclaration, CallableMemberDescriptor> CANNOT_INFER_VISIBILITY = DiagnosticFactory1.create(ERROR, DECLARATION);
DiagnosticFactory2<JetNamedDeclaration, CallableMemberDescriptor, DeclarationDescriptor> OVERRIDING_FINAL_MEMBER =
DiagnosticFactory2.create(ERROR, OVERRIDE_MODIFIER);
@@ -152,7 +152,7 @@ public class DefaultErrorMessages {
MAP.put(CANNOT_OVERRIDE_INVISIBLE_MEMBER, "''{0}'' has no access to ''{1}'', so it cannot override it", FQ_NAMES_IN_TYPES,
FQ_NAMES_IN_TYPES);
MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility. Please specify it explicitly");
MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility for ''{0}''. Please specify it explicitly", COMPACT);
MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Missing delegation specifier ''{0}''", NAME);
MAP.put(ENUM_ENTRY_ILLEGAL_TYPE, "The type constructor of enum entry should be ''{0}''", NAME);
@@ -190,7 +190,7 @@ public class OverrideResolver {
//noinspection ConstantConditions
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
if (element instanceof JetDeclaration) {
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element, descriptor));
}
return Unit.VALUE;
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: CANNOT_INFER_VISIBILITY
trait T {
internal val foo: String
}
trait U {
protected val foo: String
}
trait V : T, U
@@ -0,0 +1,2 @@
<!-- cannotInferVisibility1 -->
Cannot infer visibility for 'val foo: kotlin.String'. Please specify it explicitly
@@ -41,6 +41,11 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
doTest("idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt");
}
@TestMetadata("cannotInferVisibility.kt")
public void testCannotInferVisibility() throws Exception {
doTest("idea/testData/diagnosticMessage/cannotInferVisibility.kt");
}
@TestMetadata("cannotOverrideInvisibleMember.kt")
public void testCannotOverrideInvisibleMember() throws Exception {
doTest("idea/testData/diagnosticMessage/cannotOverrideInvisibleMember.kt");