[FIR] Don't generate implicit primary constructor for expect classes
This commit is contained in:
committed by
teamcityserver
parent
b1e47a46cd
commit
2c1ada131d
+3
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
|
|||||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
import org.jetbrains.kotlin.name.*
|
import org.jetbrains.kotlin.name.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||||
|
|
||||||
class DeclarationsConverter(
|
class DeclarationsConverter(
|
||||||
@@ -767,6 +768,8 @@ class DeclarationsConverter(
|
|||||||
isEnumEntry: Boolean = false
|
isEnumEntry: Boolean = false
|
||||||
): PrimaryConstructor? {
|
): PrimaryConstructor? {
|
||||||
if (primaryConstructor == null && !classWrapper.isEnumEntry() && classWrapper.hasSecondaryConstructor) return null
|
if (primaryConstructor == null && !classWrapper.isEnumEntry() && classWrapper.hasSecondaryConstructor) return null
|
||||||
|
val classKind = classWrapper.classBuilder.classKind
|
||||||
|
if (primaryConstructor == null && (classWrapper.hasExpect() && classKind == ClassKind.ENUM_CLASS)) return null
|
||||||
if (classWrapper.isInterface()) return null
|
if (classWrapper.isInterface()) return null
|
||||||
|
|
||||||
var modifiers = Modifier()
|
var modifiers = Modifier()
|
||||||
|
|||||||
@@ -707,7 +707,10 @@ open class RawFirBuilder(
|
|||||||
// TODO: in case we have no primary constructor,
|
// TODO: in case we have no primary constructor,
|
||||||
// it may be not possible to determine delegated super type right here
|
// it may be not possible to determine delegated super type right here
|
||||||
delegatedSuperTypeRef = delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef
|
delegatedSuperTypeRef = delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef
|
||||||
if ((this !is KtClass || !this.isInterface()) && this.hasPrimaryConstructor()) {
|
val shouldNotGenerateImplicitPrimaryConstructor = hasExplicitPrimaryConstructor() || hasSecondaryConstructors() ||
|
||||||
|
(hasExpectModifier() && classKind != ClassKind.ENUM_CLASS)
|
||||||
|
|
||||||
|
if ((this !is KtClass || !this.isInterface()) && (primaryConstructor != null || !shouldNotGenerateImplicitPrimaryConstructor)) {
|
||||||
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
|
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
|
||||||
superTypeCallEntry,
|
superTypeCallEntry,
|
||||||
delegatedSuperTypeRef,
|
delegatedSuperTypeRef,
|
||||||
|
|||||||
-4
@@ -1,9 +1,5 @@
|
|||||||
FILE: expectActual.kt
|
FILE: expectActual.kt
|
||||||
public? final? expect class MyClass : R|kotlin/Any| {
|
public? final? expect class MyClass : R|kotlin/Any| {
|
||||||
public? expect constructor(): R|MyClass| {
|
|
||||||
super<R|kotlin/Any|>()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public? final? expect fun foo(): String
|
public? final? expect fun foo(): String
|
||||||
public? final? expect val x: Int
|
public? final? expect val x: Int
|
||||||
|
|||||||
-4
@@ -1,9 +1,5 @@
|
|||||||
FILE: expectActual.kt
|
FILE: expectActual.kt
|
||||||
public? final? expect class MyClass : R|kotlin/Any| {
|
public? final? expect class MyClass : R|kotlin/Any| {
|
||||||
public? expect [ContainingClassKey=MyClass] constructor(): R|MyClass| {
|
|
||||||
super<R|kotlin/Any|>()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public? final? expect fun foo(): String
|
public? final? expect fun foo(): String
|
||||||
public? final? expect val x: Int
|
public? final? expect val x: Int
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ abstract class KtClassOrObject :
|
|||||||
|
|
||||||
override fun hasPrimaryConstructor(): Boolean = hasExplicitPrimaryConstructor() || !hasSecondaryConstructors()
|
override fun hasPrimaryConstructor(): Boolean = hasExplicitPrimaryConstructor() || !hasSecondaryConstructors()
|
||||||
|
|
||||||
private fun hasSecondaryConstructors(): Boolean = !secondaryConstructors.isEmpty()
|
fun hasSecondaryConstructors(): Boolean = !secondaryConstructors.isEmpty()
|
||||||
|
|
||||||
override fun getSecondaryConstructors(): List<KtSecondaryConstructor> = getBody()?.secondaryConstructors.orEmpty()
|
override fun getSecondaryConstructors(): List<KtSecondaryConstructor> = getBody()?.secondaryConstructors.orEmpty()
|
||||||
|
|
||||||
@@ -198,4 +198,4 @@ fun KtClassOrObject.getOrCreateBody(): KtClassBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val KtClassOrObject.allConstructors
|
val KtClassOrObject.allConstructors
|
||||||
get() = listOfNotNull(primaryConstructor) + secondaryConstructors
|
get() = listOfNotNull(primaryConstructor) + secondaryConstructors
|
||||||
|
|||||||
Reference in New Issue
Block a user