From b6b2303aa759ba62c8665a7231b7725ce990bf17 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 21 Jul 2016 15:59:23 +0300 Subject: [PATCH] Improve error message for inaccessible invisible_fake members #KT-8989 Fixed --- .../diagnostics/rendering/DefaultErrorMessages.java | 10 +++++----- .../kotlin/diagnostics/rendering/Renderers.kt | 6 ++++++ .../multiModuleHighlighting/visibility/m2/m2.kt | 4 ++-- j2k/testData/fileOrElement/enum/constantsWithBody2.kt | 4 ++-- .../errors.txt | 2 +- .../general/InternalFromAnotherModule/errors.txt | 2 +- .../flagsAndMemberInSameClassChanged/build.log | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index a2c440658ec..934bad0b827 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -94,8 +94,8 @@ public class DefaultErrorMessages { static { MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", ELEMENT_TEXT); - MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); - MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); + MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE); + MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE); MAP.put(PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL, "Protected constructor ''{0}'' from other classes can only be used in super-call", Renderers.SHORT_NAMES_IN_TYPES); @@ -276,7 +276,7 @@ public class DefaultErrorMessages { MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME); MAP.put(CAPTURED_VAL_INITIALIZATION, "Captured values initialization is forbidden due to possible reassignment", NAME); MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME); - MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is {1} in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); + MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is {1} in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE); MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME); MAP.put(VARIABLE_EXPECTED, "Variable expected"); @@ -587,8 +587,8 @@ public class DefaultErrorMessages { MAP.put(INVALID_IF_AS_EXPRESSION, "'if' must have both main and 'else' branches if used as an expression"); MAP.put(OVERRIDING_FINAL_MEMBER, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME); - MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); - MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); + MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", VISIBILITY, NAME, NAME); + MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", VISIBILITY, NAME, NAME); MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, "Return type of ''{0}'' is not a subtype of the return type of the overridden member ''{1}''", NAME, FQ_NAMES_IN_TYPES); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt index 23f956b6710..f600c6096b1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt @@ -75,6 +75,12 @@ object Renderers { @JvmField val NAME = Renderer { it.name.asString() } + @JvmField val VISIBILITY = Renderer { + if (it == Visibilities.INVISIBLE_FAKE) + "invisible (private in a supertype)" + else it.displayName + } + @JvmField val DECLARATION_NAME_WITH_KIND = Renderer { val declarationKindWithSpace = when (it) { is PackageFragmentDescriptor -> "package " diff --git a/idea/testData/multiModuleHighlighting/visibility/m2/m2.kt b/idea/testData/multiModuleHighlighting/visibility/m2/m2.kt index bd74302b027..25952830f50 100644 --- a/idea/testData/multiModuleHighlighting/visibility/m2/m2.kt +++ b/idea/testData/multiModuleHighlighting/visibility/m2/m2.kt @@ -23,12 +23,12 @@ public class B: a: A) {} fun f() { - pri() + pri() pro() pub() - int() + int() } } diff --git a/j2k/testData/fileOrElement/enum/constantsWithBody2.kt b/j2k/testData/fileOrElement/enum/constantsWithBody2.kt index 829d7e2a98d..5462e4ed2da 100644 --- a/j2k/testData/fileOrElement/enum/constantsWithBody2.kt +++ b/j2k/testData/fileOrElement/enum/constantsWithBody2.kt @@ -1,4 +1,4 @@ -// ERROR: Cannot access 'p': it is 'invisible_fake' in 'A' +// ERROR: Cannot access 'p': it is 'invisible (private in a supertype)' in 'A' enum class E private constructor(private val p: Int) { A(1) { override fun bar() { @@ -15,4 +15,4 @@ enum class E private constructor(private val p: Int) { } internal abstract fun bar() -} \ No newline at end of file +} diff --git a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/errors.txt b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/errors.txt index c025526d7a1..b97a187c913 100644 --- a/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/errors.txt +++ b/jps-plugin/testData/general/CircularDependenciesInternalFromAnotherModule/errors.txt @@ -7,4 +7,4 @@ Cannot access 'InternalClass1': it is 'internal' in 'test' at line 8, column 36 Cannot access 'InternalClass2': it is 'internal' in 'test' at line 19, column 15 Cannot access 'InternalClassAnnotation': it is 'internal' in 'test' at line 10, column 2 Cannot access 'InternalFileAnnotation': it is 'internal' in 'test' at line 1, column 7 -Cannot access 'member': it is 'invisible_fake' in 'ClassAA1' at line 27, column 25 \ No newline at end of file +Cannot access 'member': it is 'invisible (private in a supertype)' in 'ClassAA1' at line 27, column 25 \ No newline at end of file diff --git a/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt b/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt index d1920809ebf..e1be8b69b99 100644 --- a/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt +++ b/jps-plugin/testData/general/InternalFromAnotherModule/errors.txt @@ -5,4 +5,4 @@ Cannot access 'InternalClass1': it is 'internal' in 'test' at line 5, column 13 Cannot access 'InternalClass1': it is 'internal' in 'test' at line 8, column 36 Cannot access 'InternalClassAnnotation': it is 'internal' in 'test' at line 10, column 2 Cannot access 'InternalTestAnnotation': it is 'internal' in 'test' at line 1, column 7 -Cannot access 'member': it is 'invisible_fake' in 'ClassAA1' at line 27, column 25 \ No newline at end of file +Cannot access 'member': it is 'invisible (private in a supertype)' in 'ClassAA1' at line 27, column 25 \ No newline at end of file diff --git a/jps-plugin/testData/incremental/classHierarchyAffected/flagsAndMemberInSameClassChanged/build.log b/jps-plugin/testData/incremental/classHierarchyAffected/flagsAndMemberInSameClassChanged/build.log index 5b6fbaf1784..edca3b9801d 100644 --- a/jps-plugin/testData/incremental/classHierarchyAffected/flagsAndMemberInSameClassChanged/build.log +++ b/jps-plugin/testData/incremental/classHierarchyAffected/flagsAndMemberInSameClassChanged/build.log @@ -38,7 +38,7 @@ Cannot access 'A': it is 'private' in file Cannot access 'A': it is 'private' in file Cannot access 'A': it is 'private' in file Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Any? -Cannot access 'x': it is 'invisible_fake' in 'B' +Cannot access 'x': it is 'invisible (private in a supertype)' in 'B' Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Any? ================ Step #2 =================