CreateExpect: shouldn't generate expect declaration from actual function with default implementation from interface
#KT-32737 Fixed
This commit is contained in:
@@ -30,11 +30,13 @@ import org.jetbrains.kotlin.idea.quickfix.TypeAccessibilityChecker
|
||||
import org.jetbrains.kotlin.idea.refactoring.createKotlinFile
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHint
|
||||
import org.jetbrains.kotlin.idea.refactoring.isInterfaceClass
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
||||
@@ -389,6 +391,11 @@ fun TypeAccessibilityChecker.isCorrectAndHaveNonPrivateModifier(declaration: KtN
|
||||
return false
|
||||
}
|
||||
|
||||
if (declaration is KtFunction && declaration.hasBody() && declaration.containingClassOrObject?.isInterfaceClass() == true) {
|
||||
if (showErrorHint) showInaccessibleDeclarationError(declaration, "The function declaration shouldn't have a default implementation")
|
||||
return false
|
||||
}
|
||||
|
||||
if (!showErrorHint) return checkAccessibility(declaration)
|
||||
|
||||
val types = incorrectTypes(declaration).ifEmpty { return true }
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My {
|
||||
fun foo(param: String)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String)
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// SHOULD_FAIL_WITH: "The function declaration shouldn't have a default implementation"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String) = param.length
|
||||
}
|
||||
idea/testData/multiModuleQuickFix/createExpect/functionWithImplementationInInterface/jvm/My.kt.after
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// SHOULD_FAIL_WITH: "The function declaration shouldn't have a default implementation"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String) = param.length
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// DISABLE-ERRORS
|
||||
|
||||
expect interface My
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// SHOULD_FAIL_WITH: "The function declaration shouldn't have a default implementation"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String) {
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Create expected function in common module testModule_Common" "true"
|
||||
// SHOULD_FAIL_WITH: "The function declaration shouldn't have a default implementation"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
actual interface My {
|
||||
actual fun <caret>foo(param: String) {
|
||||
|
||||
}
|
||||
}
|
||||
+15
@@ -553,6 +553,21 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
||||
runTest("idea/testData/multiModuleQuickFix/createExpect/function2/");
|
||||
}
|
||||
|
||||
@TestMetadata("functionInInterface")
|
||||
public void testFunctionInInterface() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/createExpect/functionInInterface/");
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithImplementationInInterface")
|
||||
public void testFunctionWithImplementationInInterface() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/createExpect/functionWithImplementationInInterface/");
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithImplementationInInterface2")
|
||||
public void testFunctionWithImplementationInInterface2() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/createExpect/functionWithImplementationInInterface2/");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClass")
|
||||
public void testInlineClass() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/createExpect/inlineClass/");
|
||||
|
||||
Reference in New Issue
Block a user