Report some actual declaration problems on declaration name
Related to KT-20398
This commit is contained in:
@@ -576,17 +576,17 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtTypeAlias> ACTUAL_TYPE_ALIAS_WITH_USE_SITE_VARIANCE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtTypeAlias> ACTUAL_TYPE_ALIAS_WITH_COMPLEX_SUBSTITUTION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory3<KtDeclaration, MemberDescriptor, ModuleDescriptor,
|
||||
DiagnosticFactory3<KtNamedDeclaration, MemberDescriptor, ModuleDescriptor,
|
||||
Map<Incompatible, Collection<MemberDescriptor>>> NO_ACTUAL_FOR_EXPECT =
|
||||
DiagnosticFactory3.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory2<KtDeclaration, MemberDescriptor,
|
||||
DiagnosticFactory2<KtNamedDeclaration, MemberDescriptor,
|
||||
Map<Incompatible, Collection<MemberDescriptor>>> ACTUAL_WITHOUT_EXPECT =
|
||||
DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory2<KtDeclaration, ClassDescriptor,
|
||||
DiagnosticFactory2<KtNamedDeclaration, ClassDescriptor,
|
||||
List<Pair<MemberDescriptor, Map<Incompatible, Collection<MemberDescriptor>>>>> NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS =
|
||||
DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> ACTUAL_MISSING = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory2.create(ERROR, ACTUAL_DECLARATION_NAME);
|
||||
DiagnosticFactory0<KtNamedDeclaration> ACTUAL_MISSING = DiagnosticFactory0.create(ERROR, ACTUAL_DECLARATION_NAME);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -96,6 +96,17 @@ object PositioningStrategies {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField val ACTUAL_DECLARATION_NAME: PositioningStrategy<KtNamedDeclaration> = object : DeclarationHeader<KtNamedDeclaration>() {
|
||||
override fun mark(element: KtNamedDeclaration): List<TextRange> {
|
||||
val nameIdentifier = element.nameIdentifier
|
||||
return when {
|
||||
nameIdentifier != null -> markElement(nameIdentifier)
|
||||
element is KtNamedFunction -> DECLARATION_SIGNATURE.mark(element)
|
||||
else -> DEFAULT.mark(element)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField val DECLARATION_NAME: PositioningStrategy<KtNamedDeclaration> = object : DeclarationHeader<KtNamedDeclaration>() {
|
||||
override fun mark(element: KtNamedDeclaration): List<TextRange> {
|
||||
val nameIdentifier = element.nameIdentifier
|
||||
|
||||
+4
-2
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtConstructor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -59,6 +60,7 @@ object ExpectedActualDeclarationChecker : DeclarationChecker {
|
||||
) {
|
||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)) return
|
||||
|
||||
if (declaration !is KtNamedDeclaration) return
|
||||
if (descriptor !is MemberDescriptor || DescriptorUtils.isEnumEntry(descriptor)) return
|
||||
|
||||
if (descriptor.isExpect) {
|
||||
@@ -71,7 +73,7 @@ object ExpectedActualDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
fun checkExpectedDeclarationHasActual(
|
||||
reportOn: KtDeclaration,
|
||||
reportOn: KtNamedDeclaration,
|
||||
descriptor: MemberDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
platformModule: ModuleDescriptor
|
||||
@@ -120,7 +122,7 @@ object ExpectedActualDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
private fun checkActualDeclarationHasExpected(
|
||||
reportOn: KtDeclaration, descriptor: MemberDescriptor, diagnosticHolder: DiagnosticSink, checkActual: Boolean
|
||||
reportOn: KtNamedDeclaration, descriptor: MemberDescriptor, diagnosticHolder: DiagnosticSink, checkActual: Boolean
|
||||
) {
|
||||
// Using the platform module instead of the common module is sort of fine here because the former always depends on the latter.
|
||||
// However, it would be clearer to find the common module this platform module implements and look for expected there instead.
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ expect class Foo {
|
||||
// FILE: jvm.kt
|
||||
|
||||
actual class Foo {
|
||||
<!ACTUAL_MISSING!>fun bar(): String<!> = "bar"
|
||||
fun <!ACTUAL_MISSING!>bar<!>(): String = "bar"
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -5,7 +5,7 @@ Output:
|
||||
-- JVM --
|
||||
Exit code: COMPILATION_ERROR
|
||||
Output:
|
||||
compiler/testData/multiplatform/regressions/incompatibleClassScopesWithImplTypeAlias/jvm.kt:3:1: error: actual class 'Writer' has no corresponding members for expected class members:
|
||||
compiler/testData/multiplatform/regressions/incompatibleClassScopesWithImplTypeAlias/jvm.kt:3:18: error: actual class 'Writer' has no corresponding members for expected class members:
|
||||
|
||||
protected constructor Writer()
|
||||
|
||||
@@ -15,4 +15,4 @@ compiler/testData/multiplatform/regressions/incompatibleClassScopesWithImplTypeA
|
||||
protected/*protected and package*/ constructor Writer(p0: Any!)
|
||||
|
||||
actual typealias Writer = java.io.Writer
|
||||
^
|
||||
^
|
||||
|
||||
+2
-2
@@ -5,6 +5,6 @@ Output:
|
||||
-- JVM --
|
||||
Exit code: COMPILATION_ERROR
|
||||
Output:
|
||||
compiler/testData/multiplatform/simpleNoImplKeywordOnTopLevelFunction/jvm.kt:3:1: error: declaration should be marked with 'actual' (suppress with -Xno-check-actual)
|
||||
compiler/testData/multiplatform/simpleNoImplKeywordOnTopLevelFunction/jvm.kt:3:5: error: declaration should be marked with 'actual' (suppress with -Xno-check-actual)
|
||||
fun foo(s: String): Array<CharSequence?> = arrayOf(s)
|
||||
^
|
||||
^
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.facet.implementingDescriptors
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
@@ -36,7 +37,7 @@ import org.jetbrains.kotlin.resolve.diagnostics.SimpleDiagnostics
|
||||
|
||||
class PlatformExpectedAnnotator : Annotator {
|
||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||
val declaration = element as? KtDeclaration ?: return
|
||||
val declaration = element as? KtNamedDeclaration ?: return
|
||||
if (!isExpectedDeclaration(declaration)) return
|
||||
|
||||
if (TargetPlatformDetector.getPlatform(declaration.containingKtFile) !is TargetPlatform.Common) return
|
||||
|
||||
Reference in New Issue
Block a user