CreateExpect: should prefer type aliases

#KT-32571 Fixed
This commit is contained in:
Dmitry Gridin
2019-08-22 17:48:19 +07:00
parent 5928a36fa2
commit 56a7445660
18 changed files with 35 additions and 14 deletions
@@ -231,13 +231,11 @@ private val EXPECT_RENDERER = OVERRIDE_RENDERER.withOptions {
secondaryConstructorsAsPrimary = false
renderDefaultVisibility = false
renderDefaultModality = false
renderTypeExpansions = true
}
private val ACTUAL_RENDERER = EXPECT_RENDERER.withOptions {
modifiers = modifiers + ACTUAL
actualPropertiesInPrimaryConstructor = true
renderTypeExpansions = false
renderConstructorDelegation = true
}
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
import org.jetbrains.kotlin.types.AbbreviatedType
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -329,4 +330,8 @@ class KotlinTypeInaccessibleException(fqNames: Collection<FqName?>) : Exception(
fun KtNamedDeclaration.isAlwaysActual(): Boolean = safeAs<KtParameter>()?.parent?.parent?.safeAs<KtPrimaryConstructor>()
?.mustHaveValOrVar() ?: false
val KotlinType.fqName: FqName? get() = constructor.declarationDescriptor?.fqNameOrNull()
val KotlinType.fqName: FqName?
get() = when (this) {
is AbbreviatedType -> abbreviation.fqName
else -> constructor.declarationDescriptor?.fqNameOrNull()
}
@@ -1,3 +1,3 @@
expect class SomeString
// It would be great to have SomeString in foo() below, but it's problematic
expect fun foo(): String
expect fun foo(): SomeString
@@ -1 +0,0 @@
expect fun foo(): String
@@ -1,4 +1,5 @@
// "Create expected function in common module testModule_Common" "true"
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun foo() = &quot;&quot;
// DISABLE-ERRORS
typealias SomeString = String
@@ -1,6 +0,0 @@
// "Create expected function in common module testModule_Common" "true"
// DISABLE-ERRORS
typealias SomeString = String
actual fun foo(): SomeString = ""
@@ -1 +0,0 @@
expect fun <T> createList(): java.util.ArrayList<T>
@@ -0,0 +1 @@
expect val some: HashMap<Int, Int>
@@ -0,0 +1,4 @@
// "Create expected property in common module proj_Common" "true"
// DISABLE-ERRORS
actual val some<caret>: HashMap<Int, Int> = TODO()
@@ -0,0 +1,4 @@
// "Create expected property in common module proj_Common" "true"
// DISABLE-ERRORS
actual val some: HashMap<Int, Int> = TODO()
@@ -0,0 +1 @@
expect class <caret>A : HashMap<Int, Int>
@@ -0,0 +1,4 @@
// "Create expected class in common module proj_Common" "true"
// DISABLE-ERRORS
actual class <caret>A : HashMap<Int, Int>()
@@ -1,5 +1,4 @@
expect class My {
fun foo(): Int
val some: Double
}
@@ -6,7 +6,7 @@ import kotlin.Double as MyDouble
typealias MyInt = Int
actual class <caret>My {
actual fun foo(): MyInt = 42
fun foo(): MyInt = 42
actual val some: MyDouble = 4.0
}
@@ -0,0 +1,2 @@
These declarations cannot be transformed:
fun foo() = 42
@@ -477,6 +477,16 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
runTest("idea/testData/multiModuleQuickFix/createExpect/sealedClass/");
}
@TestMetadata("stdlibWithJavaAlias")
public void testStdlibWithJavaAlias() throws Exception {
runTest("idea/testData/multiModuleQuickFix/createExpect/stdlibWithJavaAlias/");
}
@TestMetadata("superTypeFromStdlib")
public void testSuperTypeFromStdlib() throws Exception {
runTest("idea/testData/multiModuleQuickFix/createExpect/superTypeFromStdlib/");
}
@TestMetadata("topLevelFunctionWithAnnotations")
public void testTopLevelFunctionWithAnnotations() throws Exception {
runTest("idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/");