mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-26 00:21:32 +00:00
Compare commits
252 Commits
rr/faster_
...
build-257
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
510968ecde | ||
|
|
1625afe876 | ||
|
|
a12121af0a | ||
|
|
b499972dea | ||
|
|
42ce1d603b | ||
|
|
2f99eabfa4 | ||
|
|
7f59152934 | ||
|
|
0eb57d6e50 | ||
|
|
b1655a14c6 | ||
|
|
f7627ec5e7 | ||
|
|
be981a8f58 | ||
|
|
94cc45ac8b | ||
|
|
7f3b23ce19 | ||
|
|
cef496758c | ||
|
|
6eb8468ad1 | ||
|
|
7bfbe986e6 | ||
|
|
7b01df5844 | ||
|
|
881907ca9d | ||
|
|
b742f769fd | ||
|
|
197102543b | ||
|
|
59cbbccca9 | ||
|
|
40486cdb39 | ||
|
|
065703c17c | ||
|
|
3f9ab89ec5 | ||
|
|
6411ab97b5 | ||
|
|
3ca5011f6b | ||
|
|
3f919ec280 | ||
|
|
ffacf1eada | ||
|
|
77824e81a7 | ||
|
|
f4ce103d17 | ||
|
|
805adfa8a1 | ||
|
|
191cb849d7 | ||
|
|
9a0b6a3774 | ||
|
|
7000218d44 | ||
|
|
9bf8040472 | ||
|
|
aa52e019e4 | ||
|
|
5c0e497e99 | ||
|
|
123d2c5fcc | ||
|
|
05089eb3df | ||
|
|
14e65cdfec | ||
|
|
dce0f29b12 | ||
|
|
85cc48feda | ||
|
|
b365b8ceb4 | ||
|
|
f142bfe47d | ||
|
|
9ecc74242b | ||
|
|
41c79d8884 | ||
|
|
2dbd8e3cea | ||
|
|
eaf0a6b34b | ||
|
|
6a4a5be3f6 | ||
|
|
851d5f1f18 | ||
|
|
667603f4fb | ||
|
|
f63e74a906 | ||
|
|
cb68128280 | ||
|
|
fdebc9c78f | ||
|
|
c9073fda91 | ||
|
|
6462ffc916 | ||
|
|
2f7dea07b8 | ||
|
|
e6f003fe95 | ||
|
|
e51c3d8bfd | ||
|
|
9b56082e5b | ||
|
|
42e253929f | ||
|
|
694d122d47 | ||
|
|
47a6776a45 | ||
|
|
8bc0192ef5 | ||
|
|
8b8c0bd008 | ||
|
|
f1264cef06 | ||
|
|
eb6a643ba4 | ||
|
|
1f13593c5c | ||
|
|
63f40f642c | ||
|
|
09a1fe9162 | ||
|
|
b7c79cd3de | ||
|
|
c4298b683d | ||
|
|
f5548251f9 | ||
|
|
e008c9bd9e | ||
|
|
b7d1573a8f | ||
|
|
f52aca5b75 | ||
|
|
f043a4022d | ||
|
|
a6786a0cb4 | ||
|
|
c97b0d835e | ||
|
|
2092fbfa99 | ||
|
|
220225924c | ||
|
|
bf5efc7883 | ||
|
|
ca63b0bae4 | ||
|
|
c0b892ba01 | ||
|
|
d01d23f2c3 | ||
|
|
b3811bdca0 | ||
|
|
34e8264dcc | ||
|
|
3bcba533f1 | ||
|
|
12a3a64fbe | ||
|
|
9f5a2151c7 | ||
|
|
e68689d3a6 | ||
|
|
5a813ed8ef | ||
|
|
fc8a7291c3 | ||
|
|
b10794d2c2 | ||
|
|
b248c0d3b9 | ||
|
|
3c969d32d1 | ||
|
|
c662128551 | ||
|
|
ac4a471b45 | ||
|
|
2221e26ba5 | ||
|
|
f730463f70 | ||
|
|
f5749a0f4a | ||
|
|
5b768a38e5 | ||
|
|
78dfa7338e | ||
|
|
5c440639b7 | ||
|
|
f696b0fb4b | ||
|
|
73be4df77d | ||
|
|
02a9850f5f | ||
|
|
f848503cbc | ||
|
|
5677c5dbb9 | ||
|
|
daebb1650f | ||
|
|
4a324fb2e9 | ||
|
|
5a115f3e0f | ||
|
|
7be1b0adfb | ||
|
|
1f52604d8c | ||
|
|
429e19465f | ||
|
|
8fe012d8d5 | ||
|
|
4515a4ab5e | ||
|
|
0ccc73f2b7 | ||
|
|
3196f55839 | ||
|
|
c3a5e2cf6f | ||
|
|
5fa153cdd7 | ||
|
|
7b14416644 | ||
|
|
12a227b02b | ||
|
|
329e1a975c | ||
|
|
e49d35b5ba | ||
|
|
276f732e4d | ||
|
|
a3c0074bb0 | ||
|
|
8086541143 | ||
|
|
383ace2ac1 | ||
|
|
c42fb935fc | ||
|
|
f8a4182450 | ||
|
|
4280122730 | ||
|
|
ef15352791 | ||
|
|
1154b563bf | ||
|
|
583c9d7837 | ||
|
|
1d77408ce8 | ||
|
|
9d9d379564 | ||
|
|
33eaeee8f9 | ||
|
|
0a29b890ec | ||
|
|
29216645fa | ||
|
|
0a4cd22434 | ||
|
|
74c446f594 | ||
|
|
1873d6a212 | ||
|
|
318172cd69 | ||
|
|
f2887577c6 | ||
|
|
b6a2481586 | ||
|
|
5a9d947505 | ||
|
|
4f83e53a4e | ||
|
|
fab98d7c2c | ||
|
|
5f87753e52 | ||
|
|
0c0cfd9bd6 | ||
|
|
aa55e1557e | ||
|
|
51ae634432 | ||
|
|
2bae08a9d8 | ||
|
|
69a4bf7f23 | ||
|
|
0eb6b804a6 | ||
|
|
d0a204c76f | ||
|
|
3ff89644d3 | ||
|
|
703671ca55 | ||
|
|
b5b37d2b60 | ||
|
|
4731b9fe0c | ||
|
|
0c30e813b1 | ||
|
|
7c1961b6fe | ||
|
|
e80ff88d37 | ||
|
|
fef31c2034 | ||
|
|
98456f1a23 | ||
|
|
b1331eeb5f | ||
|
|
6f54071e75 | ||
|
|
cb53e7d81d | ||
|
|
f0c688c94b | ||
|
|
fd22c793d1 | ||
|
|
33d47a2bea | ||
|
|
ae143a8b03 | ||
|
|
0d2bd296aa | ||
|
|
a0478cc75b | ||
|
|
4ddff7084e | ||
|
|
31b7811d1f | ||
|
|
0a9192cb6d | ||
|
|
66e91fa67b | ||
|
|
1bf1539a32 | ||
|
|
596c78b948 | ||
|
|
1cbb29355f | ||
|
|
0c914ac3b6 | ||
|
|
def7acdbbe | ||
|
|
5b3a932aca | ||
|
|
698e356181 | ||
|
|
982e45d669 | ||
|
|
4834fd8fa7 | ||
|
|
2aa5ef46c3 | ||
|
|
d2a726638b | ||
|
|
b818468d29 | ||
|
|
15919e736d | ||
|
|
23e5cb0269 | ||
|
|
efde013ff6 | ||
|
|
199a87f05a | ||
|
|
16091fd96c | ||
|
|
917acfe494 | ||
|
|
18cd7fec21 | ||
|
|
ec5d8c2bcf | ||
|
|
616dc5b504 | ||
|
|
2eab762d9a | ||
|
|
ce3bb5b997 | ||
|
|
b1d41819c6 | ||
|
|
ec80300a7c | ||
|
|
eca336aa37 | ||
|
|
a4af2696a4 | ||
|
|
f637ffb83c | ||
|
|
2ca1b07895 | ||
|
|
67f404541d | ||
|
|
af536c3f05 | ||
|
|
1029703489 | ||
|
|
a24c7554e5 | ||
|
|
7abe38bdd4 | ||
|
|
482903a1c5 | ||
|
|
76278b1784 | ||
|
|
a515b8b6cb | ||
|
|
d82b872142 | ||
|
|
e589221b4f | ||
|
|
34e1153754 | ||
|
|
0ed3306600 | ||
|
|
4367ca416d | ||
|
|
bf95822527 | ||
|
|
9ca614b6e5 | ||
|
|
f5d9b09cd0 | ||
|
|
249c1b8d9f | ||
|
|
4a47244c0d | ||
|
|
1ca28f941e | ||
|
|
ece8c5dd9a | ||
|
|
f9ead56021 | ||
|
|
e5187adeef | ||
|
|
56e1faa44e | ||
|
|
f0dad4dd64 | ||
|
|
6bccf61a40 | ||
|
|
77a4b1ce96 | ||
|
|
e599934ee4 | ||
|
|
cf91dc3c55 | ||
|
|
dba4b9dc73 | ||
|
|
ee90525e9b | ||
|
|
31b78452a5 | ||
|
|
d44c4cdcaf | ||
|
|
a80d119660 | ||
|
|
9bb717da9c | ||
|
|
4d6d9a7d13 | ||
|
|
33b5aab3b5 | ||
|
|
c079c23404 | ||
|
|
1ec4ec7f3e | ||
|
|
f82b829727 | ||
|
|
1286c8a52b | ||
|
|
85f004033d | ||
|
|
3cab7f6e71 | ||
|
|
168ab67de9 | ||
|
|
e92d12e172 |
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.incremental
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import org.jetbrains.kotlin.incremental.storage.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.supertypes
|
||||
@@ -34,12 +35,15 @@ interface IncrementalCacheCommon {
|
||||
val thisWithDependentCaches: Iterable<AbstractIncrementalCache<*>>
|
||||
fun classesFqNamesBySources(files: Iterable<File>): Collection<FqName>
|
||||
fun getSubtypesOf(className: FqName): Sequence<FqName>
|
||||
fun getSupertypesOf(className: FqName): Sequence<FqName>
|
||||
fun getSourceFileIfClass(fqName: FqName): File?
|
||||
fun markDirty(removedAndCompiledSources: Collection<File>)
|
||||
fun clearCacheForRemovedClasses(changesCollector: ChangesCollector)
|
||||
fun getComplementaryFilesRecursive(dirtyFiles: Collection<File>): Collection<File>
|
||||
fun updateComplementaryFiles(dirtyFiles: Collection<File>, expectActualTracker: ExpectActualTrackerImpl)
|
||||
fun dump(): String
|
||||
|
||||
fun isSealed(className: FqName): Boolean?
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +54,7 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
protected val pathConverter: FileToPathConverter
|
||||
) : BasicMapsOwner(workingDir), IncrementalCacheCommon {
|
||||
companion object {
|
||||
private val CLASS_ATTRIBUTES = "class-attributes"
|
||||
private val SUBTYPES = "subtypes"
|
||||
private val SUPERTYPES = "supertypes"
|
||||
private val CLASS_FQ_NAME_TO_SOURCE = "class-fq-name-to-source"
|
||||
@@ -71,6 +76,7 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
result
|
||||
}
|
||||
|
||||
internal val classAttributesMap = registerMap(ClassAttributesMap(CLASS_ATTRIBUTES.storageFile))
|
||||
private val subtypesMap = registerMap(SubtypesMap(SUBTYPES.storageFile))
|
||||
private val supertypesMap = registerMap(SupertypesMap(SUPERTYPES.storageFile))
|
||||
protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile, pathConverter))
|
||||
@@ -90,6 +96,14 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
override fun getSubtypesOf(className: FqName): Sequence<FqName> =
|
||||
subtypesMap[className].asSequence()
|
||||
|
||||
override fun getSupertypesOf(className: FqName): Sequence<FqName> {
|
||||
return supertypesMap[className].asSequence()
|
||||
}
|
||||
|
||||
override fun isSealed(className: FqName): Boolean? {
|
||||
return classAttributesMap[className]?.isSealed
|
||||
}
|
||||
|
||||
override fun getSourceFileIfClass(fqName: FqName): File? =
|
||||
classFqNameToSourceMap[fqName]
|
||||
|
||||
@@ -118,6 +132,7 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
|
||||
supertypesMap[child] = parents
|
||||
classFqNameToSourceMap[child] = srcFile
|
||||
classAttributesMap[child] = ICClassesAttributes(ProtoBuf.Modality.SEALED == Flags.MODALITY.get(proto.flags))
|
||||
}
|
||||
|
||||
protected fun removeAllFromClassStorage(removedClasses: Collection<FqName>, changesCollector: ChangesCollector) {
|
||||
@@ -152,14 +167,17 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
}
|
||||
}
|
||||
|
||||
removedFqNames.forEach { classFqNameToSourceMap.remove(it) }
|
||||
removedFqNames.forEach {
|
||||
classFqNameToSourceMap.remove(it)
|
||||
classAttributesMap.remove(it)
|
||||
}
|
||||
}
|
||||
|
||||
protected class ClassFqNameToSourceMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) :
|
||||
BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) {
|
||||
) : BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) {
|
||||
|
||||
operator fun set(fqName: FqName, sourceFile: File) {
|
||||
storage[fqName.asString()] = pathConverter.toPath(sourceFile)
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@ package org.jetbrains.kotlin.incremental
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.supertypes
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
|
||||
class ChangesCollector {
|
||||
private val removedMembers = hashMapOf<FqName, MutableSet<String>>()
|
||||
private val changedParents = hashMapOf<FqName, MutableSet<FqName>>()
|
||||
private val changedMembers = hashMapOf<FqName, MutableSet<String>>()
|
||||
private val areSubclassesAffected = hashMapOf<FqName, Boolean>()
|
||||
|
||||
@@ -47,6 +49,10 @@ class ChangesCollector {
|
||||
changes.add(ChangeInfo.SignatureChanged(fqName, areSubclassesAffected))
|
||||
}
|
||||
|
||||
for ((fqName, changedParents) in changedParents) {
|
||||
changes.add(ChangeInfo.ParentsChanged(fqName, changedParents))
|
||||
}
|
||||
|
||||
return changes
|
||||
}
|
||||
|
||||
@@ -79,12 +85,12 @@ class ChangesCollector {
|
||||
}
|
||||
|
||||
if (oldData == null) {
|
||||
newData!!.collectAll(isRemoved = false, collectAllMembersForNewClass = collectAllMembersForNewClass)
|
||||
newData!!.collectAll(isRemoved = false, isAdded = true, collectAllMembersForNewClass = collectAllMembersForNewClass)
|
||||
return
|
||||
}
|
||||
|
||||
if (newData == null) {
|
||||
oldData.collectAll(isRemoved = true)
|
||||
oldData.collectAll(isRemoved = true, isAdded = false)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,6 +104,7 @@ class ChangesCollector {
|
||||
collectSignature(oldData, diff.areSubclassesAffected)
|
||||
}
|
||||
collectChangedMembers(fqName, diff.changedMembersNames)
|
||||
addChangedParents(fqName, diff.changedSupertypes)
|
||||
}
|
||||
is PackagePartProtoData -> {
|
||||
collectSignature(oldData, areSubclassesAffected = true)
|
||||
@@ -121,10 +128,11 @@ class ChangesCollector {
|
||||
private fun <T> T.getNonPrivateNames(nameResolver: NameResolver, vararg members: T.() -> List<MessageLite>): Set<String> =
|
||||
members.flatMap { this.it().filterNot { it.isPrivate }.names(nameResolver) }.toSet()
|
||||
|
||||
private fun ProtoData.collectAll(isRemoved: Boolean, collectAllMembersForNewClass: Boolean = false) =
|
||||
//TODO remember all sealed parent classes
|
||||
private fun ProtoData.collectAll(isRemoved: Boolean, isAdded: Boolean, collectAllMembersForNewClass: Boolean = false) =
|
||||
when (this) {
|
||||
is PackagePartProtoData -> collectAllFromPackage(isRemoved)
|
||||
is ClassProtoData -> collectAllFromClass(isRemoved, collectAllMembersForNewClass)
|
||||
is ClassProtoData -> collectAllFromClass(isRemoved, isAdded, collectAllMembersForNewClass)
|
||||
}
|
||||
|
||||
private fun PackagePartProtoData.collectAllFromPackage(isRemoved: Boolean) {
|
||||
@@ -143,7 +151,7 @@ class ChangesCollector {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassProtoData.collectAllFromClass(isRemoved: Boolean, collectAllMembersForNewClass: Boolean = false) {
|
||||
private fun ClassProtoData.collectAllFromClass(isRemoved: Boolean, isAdded: Boolean, collectAllMembersForNewClass: Boolean = false) {
|
||||
val classFqName = nameResolver.getClassId(proto.fqName).asSingleFqName()
|
||||
val kind = Flags.CLASS_KIND.get(proto.flags)
|
||||
|
||||
@@ -162,6 +170,23 @@ class ChangesCollector {
|
||||
|
||||
collectSignature(classFqName, areSubclassesAffected = true)
|
||||
}
|
||||
|
||||
if (isRemoved || isAdded) {
|
||||
collectChangedParents(classFqName, proto.supertypeList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addChangedParents(fqName: FqName, parents: Collection<FqName>) {
|
||||
if (parents.isNotEmpty()) {
|
||||
changedParents.getOrPut(fqName) { HashSet() }.addAll(parents)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassProtoData.collectChangedParents(fqName: FqName, parents: Collection<ProtoBuf.Type>) {
|
||||
val changedParentsFqNames = parents.map { type ->
|
||||
nameResolver.getClassId(type.className).asSingleFqName()
|
||||
}
|
||||
addChangedParents(fqName, changedParentsFqNames)
|
||||
}
|
||||
|
||||
private fun ClassProtoData.getNonPrivateMemberNames(): Set<String> {
|
||||
|
||||
@@ -145,6 +145,7 @@ open class IncrementalJvmCache(
|
||||
}
|
||||
protoMap.remove(className, changesCollector)
|
||||
classFqNameToSourceMap.remove(className.fqNameForClassNameWithoutDollars)
|
||||
classAttributesMap.remove(className.fqNameForClassNameWithoutDollars)
|
||||
internalNameToSource.remove(className.internalName)
|
||||
|
||||
// TODO NO_CHANGES? (delegates only)
|
||||
@@ -271,6 +272,7 @@ open class IncrementalJvmCache(
|
||||
|
||||
private inner class ProtoMap(storageFile: File) : BasicStringMap<ProtoMapValue>(storageFile, ProtoMapValueExternalizer) {
|
||||
|
||||
@Synchronized
|
||||
fun process(kotlinClass: LocalFileKotlinClass, changesCollector: ChangesCollector) {
|
||||
return put(kotlinClass, changesCollector)
|
||||
}
|
||||
@@ -282,10 +284,12 @@ open class IncrementalJvmCache(
|
||||
// from files compiled during last round.
|
||||
// However there is no need to compare old and new data in this case
|
||||
// (also that would fail with exception).
|
||||
@Synchronized
|
||||
fun storeModuleMapping(className: JvmClassName, bytes: ByteArray) {
|
||||
storage[className.internalName] = ProtoMapValue(isPackageFacade = false, bytes = bytes, strings = emptyArray())
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun put(kotlinClass: LocalFileKotlinClass, changesCollector: ChangesCollector) {
|
||||
val header = kotlinClass.classHeader
|
||||
|
||||
@@ -308,6 +312,7 @@ open class IncrementalJvmCache(
|
||||
operator fun get(className: JvmClassName): ProtoMapValue? =
|
||||
storage[className.internalName]
|
||||
|
||||
@Synchronized
|
||||
fun remove(className: JvmClassName, changesCollector: ChangesCollector) {
|
||||
val key = className.internalName
|
||||
val oldValue = storage[key] ?: return
|
||||
@@ -324,6 +329,8 @@ open class IncrementalJvmCache(
|
||||
|
||||
private inner class JavaSourcesProtoMap(storageFile: File) :
|
||||
BasicStringMap<SerializedJavaClass>(storageFile, JavaClassProtoMapValueExternalizer) {
|
||||
|
||||
@Synchronized
|
||||
fun process(jvmClassName: JvmClassName, newData: SerializedJavaClass, changesCollector: ChangesCollector) {
|
||||
val key = jvmClassName.internalName
|
||||
val oldData = storage[key]
|
||||
@@ -335,6 +342,7 @@ open class IncrementalJvmCache(
|
||||
)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun remove(className: JvmClassName, changesCollector: ChangesCollector) {
|
||||
val key = className.internalName
|
||||
val oldValue = storage[key] ?: return
|
||||
@@ -374,6 +382,7 @@ open class IncrementalJvmCache(
|
||||
operator fun contains(className: JvmClassName): Boolean =
|
||||
className.internalName in storage
|
||||
|
||||
@Synchronized
|
||||
fun process(kotlinClass: LocalFileKotlinClass, changesCollector: ChangesCollector) {
|
||||
val key = kotlinClass.className.internalName
|
||||
val oldMap = storage[key] ?: emptyMap()
|
||||
@@ -390,6 +399,7 @@ open class IncrementalJvmCache(
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun remove(className: JvmClassName) {
|
||||
storage.remove(className.internalName)
|
||||
}
|
||||
@@ -522,6 +532,7 @@ open class IncrementalJvmCache(
|
||||
return result
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun process(kotlinClass: LocalFileKotlinClass, changesCollector: ChangesCollector) {
|
||||
val key = kotlinClass.className.internalName
|
||||
val oldMap = storage[key] ?: emptyMap()
|
||||
@@ -547,6 +558,7 @@ open class IncrementalJvmCache(
|
||||
private fun functionNameBySignature(signature: String): String =
|
||||
signature.substringBefore("(")
|
||||
|
||||
@Synchronized
|
||||
fun remove(className: JvmClassName) {
|
||||
storage.remove(className.internalName)
|
||||
}
|
||||
@@ -568,6 +580,7 @@ sealed class ChangeInfo(val fqName: FqName) {
|
||||
|
||||
class SignatureChanged(fqName: FqName, val areSubclassesAffected: Boolean) : ChangeInfo(fqName)
|
||||
|
||||
class ParentsChanged(fqName: FqName, val parentsChanged: Collection<FqName>) : ChangeInfo(fqName)
|
||||
|
||||
protected open fun toStringProperties(): String = "fqName = $fqName"
|
||||
|
||||
|
||||
@@ -136,7 +136,8 @@ fun LookupStorage.update(
|
||||
|
||||
data class DirtyData(
|
||||
val dirtyLookupSymbols: Collection<LookupSymbol> = emptyList(),
|
||||
val dirtyClassesFqNames: Collection<FqName> = emptyList()
|
||||
val dirtyClassesFqNames: Collection<FqName> = emptyList(),
|
||||
val dirtyClassesFqNamesForceRecompile: Collection<FqName> = emptyList()
|
||||
)
|
||||
|
||||
fun ChangesCollector.getDirtyData(
|
||||
@@ -146,6 +147,9 @@ fun ChangesCollector.getDirtyData(
|
||||
val dirtyLookupSymbols = HashSet<LookupSymbol>()
|
||||
val dirtyClassesFqNames = HashSet<FqName>()
|
||||
|
||||
val sealedParents = HashMap<FqName, MutableSet<FqName>>()
|
||||
val notSealedParents = HashSet<FqName>()
|
||||
|
||||
for (change in changes()) {
|
||||
reporter.reportVerbose { "Process $change" }
|
||||
|
||||
@@ -170,10 +174,35 @@ fun ChangesCollector.getDirtyData(
|
||||
}
|
||||
|
||||
fqNames.mapTo(dirtyLookupSymbols) { LookupSymbol(SAM_LOOKUP_NAME.asString(), it.asString()) }
|
||||
} else if (change is ChangeInfo.ParentsChanged) {
|
||||
fun FqName.isSealed(): Boolean {
|
||||
if (notSealedParents.contains(this)) return false
|
||||
if (sealedParents.containsKey(this)) return true
|
||||
return isSealed(this, caches).also { sealed ->
|
||||
if (sealed) {
|
||||
sealedParents[this] = HashSet()
|
||||
} else {
|
||||
notSealedParents.add(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
change.parentsChanged.forEach { parent ->
|
||||
if (parent.isSealed()) {
|
||||
sealedParents.getOrPut(parent) { HashSet() }.add(change.fqName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DirtyData(dirtyLookupSymbols, dirtyClassesFqNames)
|
||||
val forceRecompile = HashSet<FqName>().apply {
|
||||
addAll(sealedParents.keys)
|
||||
//we should recompile all inheritors with parent sealed class: add known subtypes
|
||||
addAll(sealedParents.keys.flatMap { withSubtypes(it, caches) })
|
||||
//we should recompile all inheritors with parent sealed class: add new subtypes
|
||||
addAll(sealedParents.values.flatten())
|
||||
}
|
||||
|
||||
return DirtyData(dirtyLookupSymbols, dirtyClassesFqNames, forceRecompile)
|
||||
}
|
||||
|
||||
fun mapLookupSymbolsToFiles(
|
||||
@@ -217,6 +246,11 @@ fun mapClassesFqNamesToFiles(
|
||||
return fqNameToAffectedFiles.values.flattenTo(HashSet())
|
||||
}
|
||||
|
||||
fun isSealed(
|
||||
fqName: FqName,
|
||||
caches: Iterable<IncrementalCacheCommon>
|
||||
): Boolean = caches.any { it.isSealed(fqName) ?: false }
|
||||
|
||||
fun withSubtypes(
|
||||
typeFqName: FqName,
|
||||
caches: Iterable<IncrementalCacheCommon>
|
||||
|
||||
@@ -28,12 +28,14 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptorVisibility
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
import java.util.*
|
||||
|
||||
data class Difference(
|
||||
val isClassAffected: Boolean = false,
|
||||
val areSubclassesAffected: Boolean = false,
|
||||
val changedMembersNames: Set<String> = emptySet()
|
||||
val changedMembersNames: Set<String> = emptySet(),
|
||||
val changedSupertypes: Set<FqName> = emptySet()
|
||||
)
|
||||
|
||||
sealed class ProtoData
|
||||
@@ -187,6 +189,7 @@ class DifferenceCalculatorForClass(
|
||||
|
||||
var isClassAffected = false
|
||||
var areSubclassesAffected = false
|
||||
val changedSupertypes = HashSet<FqName>()
|
||||
val names = hashSetOf<String>()
|
||||
val classIsSealed = newProto.isSealed && oldProto.isSealed
|
||||
|
||||
@@ -247,12 +250,21 @@ class DifferenceCalculatorForClass(
|
||||
ProtoBufClassKind.FLAGS,
|
||||
ProtoBufClassKind.FQ_NAME,
|
||||
ProtoBufClassKind.TYPE_PARAMETER_LIST,
|
||||
ProtoBufClassKind.SUPERTYPE_LIST,
|
||||
ProtoBufClassKind.SUPERTYPE_ID_LIST,
|
||||
ProtoBufClassKind.JS_EXT_CLASS_ANNOTATION_LIST -> {
|
||||
isClassAffected = true
|
||||
areSubclassesAffected = true
|
||||
}
|
||||
|
||||
ProtoBufClassKind.SUPERTYPE_LIST,
|
||||
ProtoBufClassKind.SUPERTYPE_ID_LIST -> {
|
||||
isClassAffected = true
|
||||
areSubclassesAffected = true
|
||||
|
||||
val oldSupertypes = oldProto.supertypeList.map { oldNameResolver.getClassId(it.className).asSingleFqName() }
|
||||
val newSupertypes = newProto.supertypeList.map { newNameResolver.getClassId(it.className).asSingleFqName() }
|
||||
val changed = (oldSupertypes union newSupertypes) subtract (oldSupertypes intersect newSupertypes)
|
||||
changedSupertypes.addAll(changed)
|
||||
}
|
||||
ProtoBufClassKind.JVM_EXT_CLASS_MODULE_NAME,
|
||||
ProtoBufClassKind.JS_EXT_CLASS_CONTAINING_FILE_ID -> {
|
||||
// TODO
|
||||
@@ -281,7 +293,7 @@ class DifferenceCalculatorForClass(
|
||||
}
|
||||
}
|
||||
|
||||
return Difference(isClassAffected, areSubclassesAffected, names)
|
||||
return Difference(isClassAffected, areSubclassesAffected, names, changedSupertypes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ open class BasicMapsOwner(val cachesDir: File) {
|
||||
protected val String.storageFile: File
|
||||
get() = File(cachesDir, this + "." + CACHE_EXTENSION)
|
||||
|
||||
@Synchronized
|
||||
protected fun <K, V, M : BasicMap<K, V>> registerMap(map: M): M {
|
||||
maps.add(map)
|
||||
return map
|
||||
@@ -47,6 +48,7 @@ open class BasicMapsOwner(val cachesDir: File) {
|
||||
forEachMapSafe("flush") { it.flush(memoryCachesOnly) }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun forEachMapSafe(actionName: String, action: (BasicMap<*, *>) -> Unit) {
|
||||
val actionExceptions = LinkedHashMap<String, Exception>()
|
||||
maps.forEach {
|
||||
@@ -66,5 +68,6 @@ open class BasicMapsOwner(val cachesDir: File) {
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@Synchronized
|
||||
fun dump(): String = maps.joinToString("\n\n") { it.dump() }
|
||||
}
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import com.intellij.util.io.IOUtil
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
import com.intellij.util.io.PersistentHashMap
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,7 +32,6 @@ class CachingLazyStorage<K, V>(
|
||||
private val keyDescriptor: KeyDescriptor<K>,
|
||||
private val valueExternalizer: DataExternalizer<V>
|
||||
) : LazyStorage<K, V> {
|
||||
@Volatile
|
||||
private var storage: PersistentHashMap<K, V>? = null
|
||||
|
||||
@Synchronized
|
||||
@@ -80,8 +81,10 @@ class CachingLazyStorage<K, V>(
|
||||
try {
|
||||
storage?.close()
|
||||
} finally {
|
||||
PersistentHashMap.deleteFilesStartingWith(storageFile)
|
||||
storage = null
|
||||
if (!IOUtil.deleteAllFilesStartingWith(storageFile)) {
|
||||
throw IOException("Could not delete internal storage: ${storageFile.absolutePath}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.DataInput
|
||||
import java.io.DataOutput
|
||||
import java.io.File
|
||||
|
||||
internal data class ICClassesAttributes(val isSealed: Boolean)
|
||||
|
||||
internal object ICClassesAttributesExternalizer : DataExternalizer<ICClassesAttributes> {
|
||||
override fun read(input: DataInput): ICClassesAttributes {
|
||||
return ICClassesAttributes(input.readBoolean())
|
||||
}
|
||||
|
||||
override fun save(output: DataOutput, value: ICClassesAttributes) {
|
||||
output.writeBoolean(value.isSealed)
|
||||
}
|
||||
}
|
||||
|
||||
internal open class ClassAttributesMap(
|
||||
storageFile: File
|
||||
) : BasicStringMap<ICClassesAttributes>(storageFile, ICClassesAttributesExternalizer) {
|
||||
override fun dumpValue(value: ICClassesAttributes): String = value.toString()
|
||||
|
||||
operator fun set(key: FqName, value: ICClassesAttributes) {
|
||||
storage[key.asString()] = value
|
||||
}
|
||||
|
||||
operator fun get(key: FqName): ICClassesAttributes? = storage[key.asString()]
|
||||
|
||||
fun remove(key: FqName) {
|
||||
storage.remove(key.asString())
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,18 @@ import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.File
|
||||
|
||||
internal open class ClassOneToManyMap(
|
||||
storageFile: File
|
||||
) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
internal open class ClassOneToManyMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
override fun dumpValue(value: Collection<String>): String = value.dumpCollection()
|
||||
|
||||
@Synchronized
|
||||
fun add(key: FqName, value: FqName) {
|
||||
storage.append(key.asString(), listOf(value.asString()))
|
||||
}
|
||||
|
||||
operator fun get(key: FqName): Collection<FqName> =
|
||||
storage[key.asString()]?.map(::FqName) ?: setOf()
|
||||
storage[key.asString()]?.map(::FqName) ?: setOf()
|
||||
|
||||
@Synchronized
|
||||
operator fun set(key: FqName, values: Collection<FqName>) {
|
||||
if (values.isEmpty()) {
|
||||
remove(key)
|
||||
@@ -41,10 +41,14 @@ internal open class ClassOneToManyMap(
|
||||
storage[key.asString()] = values.map(FqName::asString)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun remove(key: FqName) {
|
||||
storage.remove(key.asString())
|
||||
}
|
||||
|
||||
// Access to caches could be done from multiple threads (e.g. JPS worker and RMI). The underlying collection is already synchronized,
|
||||
// thus we need synchronization of this method and all modification methods.
|
||||
@Synchronized
|
||||
fun removeValues(key: FqName, removed: Set<FqName>) {
|
||||
val notRemoved = this[key].filter { it !in removed }
|
||||
this[key] = notRemoved
|
||||
|
||||
@@ -25,8 +25,7 @@ internal class DirtyClassesJvmNameMap(storageFile: File) : AbstractDirtyClassesM
|
||||
internal class DirtyClassesFqNameMap(storageFile: File) : AbstractDirtyClassesMap<FqName>(FqNameTransformer, storageFile)
|
||||
|
||||
internal abstract class AbstractDirtyClassesMap<Name>(
|
||||
private val nameTransformer: NameTransformer<Name>,
|
||||
storageFile: File
|
||||
private val nameTransformer: NameTransformer<Name>, storageFile: File
|
||||
) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE) {
|
||||
fun markDirty(className: Name) {
|
||||
storage[nameTransformer.asString(className)] = true
|
||||
@@ -37,10 +36,10 @@ internal abstract class AbstractDirtyClassesMap<Name>(
|
||||
}
|
||||
|
||||
fun getDirtyOutputClasses(): Collection<Name> =
|
||||
storage.keys.map { nameTransformer.asName(it) }
|
||||
storage.keys.map { nameTransformer.asName(it) }
|
||||
|
||||
fun isDirty(className: Name): Boolean =
|
||||
storage.contains(nameTransformer.asString(className))
|
||||
storage.contains(nameTransformer.asString(className))
|
||||
|
||||
override fun dumpValue(value: Boolean) = ""
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import com.intellij.util.io.IOUtil
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
import com.intellij.util.io.PersistentHashMap
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
class NonCachingLazyStorage<K, V>(
|
||||
@@ -27,7 +29,6 @@ class NonCachingLazyStorage<K, V>(
|
||||
private val keyDescriptor: KeyDescriptor<K>,
|
||||
private val valueExternalizer: DataExternalizer<V>
|
||||
) : LazyStorage<K, V> {
|
||||
@Volatile
|
||||
private var storage: PersistentHashMap<K, V>? = null
|
||||
|
||||
@Synchronized
|
||||
@@ -76,11 +77,12 @@ class NonCachingLazyStorage<K, V>(
|
||||
override fun clean() {
|
||||
try {
|
||||
storage?.close()
|
||||
} catch (ignored: Throwable) {
|
||||
} finally {
|
||||
storage = null
|
||||
if (!IOUtil.deleteAllFilesStartingWith(storageFile)) {
|
||||
throw IOException("Could not delete internal storage: ${storageFile.absolutePath}")
|
||||
}
|
||||
}
|
||||
|
||||
PersistentHashMap.deleteFilesStartingWith(storageFile)
|
||||
storage = null
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
||||
@@ -188,7 +188,7 @@ extra["versions.kotlinx-collections-immutable-jvm"] = immutablesVersion
|
||||
extra["versions.ktor-network"] = "1.0.1"
|
||||
|
||||
if (!project.hasProperty("versions.kotlin-native")) {
|
||||
extra["versions.kotlin-native"] = "1.4.30-dev-17395"
|
||||
extra["versions.kotlin-native"] = "1.4.30-rc1-8"
|
||||
}
|
||||
|
||||
val intellijUltimateEnabled by extra(project.kotlinBuildProperties.intellijUltimateEnabled)
|
||||
|
||||
@@ -20,6 +20,10 @@ internal const val PLUGIN_MARKER_SUFFIX = ".gradle.plugin"
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) {
|
||||
|
||||
fun Project.isSonatypePublish(): Boolean =
|
||||
hasProperty("isSonatypePublish") && property("isSonatypePublish") as Boolean
|
||||
|
||||
val pluginDevelopment = extensions.getByType<PluginBundleExtension>()
|
||||
val publishingExtension = extensions.getByType<PublishingExtension>()
|
||||
val mainPublication = publishingExtension.publications[KotlinBuildPublishingPlugin.PUBLICATION_NAME] as MavenPublication
|
||||
@@ -32,7 +36,12 @@ fun Project.publishPluginMarkers(withEmptyJars: Boolean = true) {
|
||||
|
||||
tasks.named<PublishToMavenRepository>(
|
||||
"publish${markerPublication.name.capitalize(Locale.ROOT)}PublicationTo${KotlinBuildPublishingPlugin.REPOSITORY_NAME}Repository"
|
||||
).configureRepository()
|
||||
).apply {
|
||||
configureRepository()
|
||||
configure {
|
||||
onlyIf { !isSonatypePublish() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
// This object should help compiling against different ASM versions in different bunch versions
|
||||
object VersionIndependentOpcodes {
|
||||
const val ACC_RECORD = Opcodes.ACC_RECORD
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
// This object should help compiling against different ASM versions from different bunch versions
|
||||
object VersionIndependentOpcodes {
|
||||
const val ACC_RECORD = 0
|
||||
}
|
||||
@@ -26,13 +26,13 @@ import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.GENERATE_SMAP;
|
||||
|
||||
public abstract class AbstractClassBuilder implements ClassBuilder {
|
||||
protected static final MethodVisitor EMPTY_METHOD_VISITOR = new MethodVisitor(Opcodes.API_VERSION) {};
|
||||
public static final RecordComponentVisitor EMPTY_RECORD_VISITOR = new RecordComponentVisitor(Opcodes.API_VERSION) {};
|
||||
protected static final FieldVisitor EMPTY_FIELD_VISITOR = new FieldVisitor(Opcodes.API_VERSION) {};
|
||||
|
||||
private String thisName;
|
||||
@@ -91,6 +91,16 @@ public abstract class AbstractClassBuilder implements ClassBuilder {
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RecordComponentVisitor newRecordComponent(@NotNull String name, @NotNull String desc, @Nullable String signature) {
|
||||
RecordComponentVisitor visitor = getVisitor().visitRecordComponent(name, desc, signature);
|
||||
if (visitor == null) {
|
||||
return EMPTY_RECORD_VISITOR;
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JvmSerializationBindings getSerializationBindings() {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.inline.FileMapping;
|
||||
import org.jetbrains.kotlin.codegen.inline.SMAPBuilder;
|
||||
import org.jetbrains.kotlin.codegen.inline.SourceMapper;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtilsKt.GENERATE_SMAP;
|
||||
|
||||
public abstract class AbstractClassBuilder implements ClassBuilder {
|
||||
protected static final MethodVisitor EMPTY_METHOD_VISITOR = new MethodVisitor(Opcodes.API_VERSION) {};
|
||||
protected static final FieldVisitor EMPTY_FIELD_VISITOR = new FieldVisitor(Opcodes.API_VERSION) {};
|
||||
|
||||
private String thisName;
|
||||
|
||||
private final JvmSerializationBindings serializationBindings = new JvmSerializationBindings();
|
||||
|
||||
private String sourceName;
|
||||
|
||||
private String debugInfo;
|
||||
|
||||
public static class Concrete extends AbstractClassBuilder {
|
||||
private final ClassVisitor v;
|
||||
|
||||
public Concrete(@NotNull ClassVisitor v) {
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ClassVisitor getVisitor() {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public FieldVisitor newField(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable Object value
|
||||
) {
|
||||
FieldVisitor visitor = getVisitor().visitField(access, name, desc, signature, value);
|
||||
if (visitor == null) {
|
||||
return EMPTY_FIELD_VISITOR;
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public MethodVisitor newMethod(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable String[] exceptions
|
||||
) {
|
||||
MethodVisitor visitor = getVisitor().visitMethod(access, name, desc, signature, exceptions);
|
||||
if (visitor == null) {
|
||||
return EMPTY_METHOD_VISITOR;
|
||||
}
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JvmSerializationBindings getSerializationBindings() {
|
||||
return serializationBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AnnotationVisitor newAnnotation(@NotNull String desc, boolean visible) {
|
||||
return getVisitor().visitAnnotation(desc, visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
getVisitor().visitSource(sourceName, debugInfo);
|
||||
getVisitor().visitEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defineClass(
|
||||
@Nullable PsiElement origin,
|
||||
int version,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@Nullable String signature,
|
||||
@NotNull String superName,
|
||||
@NotNull String[] interfaces
|
||||
) {
|
||||
thisName = name;
|
||||
getVisitor().visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSource(@NotNull String name, @Nullable String debug) {
|
||||
assert sourceName == null || sourceName.equals(name) : "inconsistent file name: " + sourceName + " vs " + name;
|
||||
sourceName = name;
|
||||
debugInfo = debug;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSMAP(@NotNull SourceMapper smap, boolean backwardsCompatibleSyntax) {
|
||||
if (!GENERATE_SMAP) return;
|
||||
|
||||
List<FileMapping> fileMappings = smap.getResultMappings();
|
||||
if (fileMappings.isEmpty()) return;
|
||||
|
||||
visitSource(fileMappings.get(0).getName(), SMAPBuilder.INSTANCE.build(fileMappings, backwardsCompatibleSyntax));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) {
|
||||
getVisitor().visitOuterClass(owner, name, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(@NotNull String name, @Nullable String outerName, @Nullable String innerName, int access) {
|
||||
getVisitor().visitInnerClass(name, outerName, innerName, access);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getThisName() {
|
||||
assert thisName != null : "This name isn't set";
|
||||
return thisName;
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,10 @@ package org.jetbrains.kotlin.codegen;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.inline.FileMapping;
|
||||
import org.jetbrains.kotlin.codegen.inline.SourceMapper;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
public interface ClassBuilder {
|
||||
@NotNull
|
||||
@@ -49,6 +45,12 @@ public interface ClassBuilder {
|
||||
@Nullable String[] exceptions
|
||||
);
|
||||
|
||||
@NotNull RecordComponentVisitor newRecordComponent(
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature
|
||||
);
|
||||
|
||||
@NotNull
|
||||
JvmSerializationBindings getSerializationBindings();
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.inline.SourceMapper;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
public interface ClassBuilder {
|
||||
@NotNull
|
||||
FieldVisitor newField(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable Object value
|
||||
);
|
||||
|
||||
@NotNull
|
||||
MethodVisitor newMethod(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable String[] exceptions
|
||||
);
|
||||
|
||||
@NotNull
|
||||
JvmSerializationBindings getSerializationBindings();
|
||||
|
||||
@NotNull
|
||||
AnnotationVisitor newAnnotation(@NotNull String desc, boolean visible);
|
||||
|
||||
void done();
|
||||
|
||||
@NotNull
|
||||
ClassVisitor getVisitor();
|
||||
|
||||
void defineClass(
|
||||
@Nullable PsiElement origin,
|
||||
int version,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@Nullable String signature,
|
||||
@NotNull String superName,
|
||||
@NotNull String[] interfaces
|
||||
);
|
||||
|
||||
void visitSource(@NotNull String name, @Nullable String debug);
|
||||
|
||||
void visitSMAP(@NotNull SourceMapper smap, boolean backwardsCompatibleSyntax);
|
||||
|
||||
void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc);
|
||||
|
||||
void visitInnerClass(@NotNull String name, @Nullable String outerName, @Nullable String innerName, int access);
|
||||
|
||||
@NotNull
|
||||
String getThisName();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
fun ClassBuilder.addRecordComponent(name: String, desc: String, signature: String?) {
|
||||
newRecordComponent(name, desc, signature)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
fun ClassBuilder.addRecordComponent(name: String, desc: String, signature: String?) {
|
||||
// newRecordComponent(name, desc, signature)
|
||||
}
|
||||
@@ -19,14 +19,10 @@ package org.jetbrains.kotlin.codegen;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.inline.FileMapping;
|
||||
import org.jetbrains.kotlin.codegen.inline.SourceMapper;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
public abstract class DelegatingClassBuilder implements ClassBuilder {
|
||||
@NotNull
|
||||
@@ -58,6 +54,14 @@ public abstract class DelegatingClassBuilder implements ClassBuilder {
|
||||
return getDelegate().newMethod(origin, access, name, desc, signature, exceptions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RecordComponentVisitor newRecordComponent(
|
||||
@NotNull String name, @NotNull String desc, @Nullable String signature
|
||||
) {
|
||||
return getDelegate().newRecordComponent(name, desc, signature);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JvmSerializationBindings getSerializationBindings() {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.inline.SourceMapper;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
public abstract class DelegatingClassBuilder implements ClassBuilder {
|
||||
@NotNull
|
||||
protected abstract ClassBuilder getDelegate();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FieldVisitor newField(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable Object value
|
||||
) {
|
||||
return getDelegate().newField(origin, access, name, desc, signature, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MethodVisitor newMethod(
|
||||
@NotNull JvmDeclarationOrigin origin,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@NotNull String desc,
|
||||
@Nullable String signature,
|
||||
@Nullable String[] exceptions
|
||||
) {
|
||||
return getDelegate().newMethod(origin, access, name, desc, signature, exceptions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JvmSerializationBindings getSerializationBindings() {
|
||||
return getDelegate().getSerializationBindings();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnnotationVisitor newAnnotation(@NotNull String desc, boolean visible) {
|
||||
return getDelegate().newAnnotation(desc, visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
getDelegate().done();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassVisitor getVisitor() {
|
||||
return getDelegate().getVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defineClass(
|
||||
@Nullable PsiElement origin,
|
||||
int version,
|
||||
int access,
|
||||
@NotNull String name,
|
||||
@Nullable String signature,
|
||||
@NotNull String superName,
|
||||
@NotNull String[] interfaces
|
||||
) {
|
||||
getDelegate().defineClass(origin, version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSource(@NotNull String name, @Nullable String debug) {
|
||||
getDelegate().visitSource(name, debug);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSMAP(@NotNull SourceMapper smap, boolean backwardsCompatibleSyntax) {
|
||||
getDelegate().visitSMAP(smap, backwardsCompatibleSyntax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) {
|
||||
getDelegate().visitOuterClass(owner, name, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(@NotNull String name, @Nullable String outerName, @Nullable String innerName, int access) {
|
||||
getDelegate().visitInnerClass(name, outerName, innerName, access);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getThisName() {
|
||||
return getDelegate().getThisName();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.Synthetic
|
||||
@@ -55,6 +56,13 @@ class ErasedInlineClassBodyCodegen(
|
||||
generateUnboxMethod()
|
||||
generateFunctionsFromAny()
|
||||
generateSpecializedEqualsStub()
|
||||
generateJvmInlineAnnotation()
|
||||
}
|
||||
|
||||
private fun generateJvmInlineAnnotation() {
|
||||
if (descriptor.isInline) {
|
||||
v.newAnnotation(JVM_INLINE_ANNOTATION_FQ_NAME.topLevelClassAsmType().descriptor, true).visitEnd()
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateFunctionsFromAny() {
|
||||
|
||||
@@ -1221,7 +1221,12 @@ public class FunctionCodegen {
|
||||
|
||||
// 'null' because the "could not find expected declaration" error has been already reported in isDefaultNeeded earlier
|
||||
List<ValueParameterDescriptor> valueParameters =
|
||||
CodegenUtil.getFunctionParametersForDefaultValueGeneration(functionDescriptor, null);
|
||||
functionDescriptor.isSuspend()
|
||||
? CollectionsKt.plus(
|
||||
CodegenUtil.getFunctionParametersForDefaultValueGeneration(
|
||||
CoroutineCodegenUtilKt.unwrapInitialDescriptorForSuspendFunction(functionDescriptor), null),
|
||||
CollectionsKt.last(functionDescriptor.getValueParameters()))
|
||||
: CodegenUtil.getFunctionParametersForDefaultValueGeneration(functionDescriptor, null);
|
||||
|
||||
boolean isStatic = isStaticMethod(methodContext.getContextKind(), functionDescriptor);
|
||||
FrameMap frameMap = createFrameMap(state, signature, functionDescriptor.getExtensionReceiverParameter(), valueParameters, isStatic);
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JvmAnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature;
|
||||
@@ -221,6 +222,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
access |= ACC_ENUM;
|
||||
}
|
||||
|
||||
if (JvmAnnotationUtilKt.isJvmRecord(descriptor)) {
|
||||
access |= VersionIndependentOpcodes.ACC_RECORD;
|
||||
}
|
||||
|
||||
v.defineClass(
|
||||
myClass.getPsiOrParent(),
|
||||
state.getClassFileVersion(),
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JvmAnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
@@ -435,9 +436,10 @@ public class PropertyCodegen {
|
||||
v.getSerializationBindings().put(FIELD_FOR_PROPERTY, propertyDescriptor, new Pair<>(type, name));
|
||||
|
||||
if (isBackingFieldOwner) {
|
||||
String signature = isDelegate ? null : typeMapper.mapFieldSignature(kotlinType, propertyDescriptor);
|
||||
FieldVisitor fv = builder.newField(
|
||||
JvmDeclarationOriginKt.OtherOrigin(propertyDescriptor), modifiers, name, type.getDescriptor(),
|
||||
isDelegate ? null : typeMapper.mapFieldSignature(kotlinType, propertyDescriptor), defaultValue
|
||||
signature, defaultValue
|
||||
);
|
||||
|
||||
if (annotatedField != null) {
|
||||
@@ -450,6 +452,10 @@ public class PropertyCodegen {
|
||||
AnnotationCodegen.forField(fv, memberCodegen, state, skipNullabilityAnnotations)
|
||||
.genAnnotations(annotatedField, type, propertyDescriptor.getType(), null, additionalVisibleAnnotations);
|
||||
}
|
||||
|
||||
if (propertyDescriptor.getContainingDeclaration() instanceof ClassDescriptor && JvmAnnotationUtilKt.isJvmRecord((ClassDescriptor) propertyDescriptor.getContainingDeclaration())) {
|
||||
ClassBuilderRecordKt.addRecordComponent(builder, name, type.getDescriptor(), signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicArrayConstructors
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.Position
|
||||
import org.jetbrains.kotlin.incremental.components.ScopeKind
|
||||
@@ -513,7 +514,6 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
internal fun createInlineMethodNode(
|
||||
functionDescriptor: FunctionDescriptor,
|
||||
methodOwner: Type,
|
||||
@@ -529,10 +529,15 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
return SMAPAndMethodNode(intrinsic, createDefaultFakeSMAP())
|
||||
}
|
||||
|
||||
val asmMethod = if (callDefault)
|
||||
state.typeMapper.mapDefaultMethod(functionDescriptor, sourceCompilerForInline.contextKind)
|
||||
else
|
||||
mangleSuspendInlineFunctionAsmMethodIfNeeded(functionDescriptor, jvmSignature.asmMethod)
|
||||
var asmMethod = mapMethod(state, functionDescriptor, sourceCompilerForInline, jvmSignature, callDefault)
|
||||
if (asmMethod.name.contains("-") &&
|
||||
!state.configuration.getBoolean(JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME) &&
|
||||
classFileContainsMethod(functionDescriptor, state, asmMethod) == false
|
||||
) {
|
||||
state.typeMapper.useOldManglingRulesForFunctionAcceptingInlineClass = true
|
||||
asmMethod = mapMethod(state, functionDescriptor, sourceCompilerForInline, jvmSignature, callDefault)
|
||||
state.typeMapper.useOldManglingRulesForFunctionAcceptingInlineClass = false
|
||||
}
|
||||
|
||||
val directMember = getDirectMemberAndCallableFromObject(functionDescriptor)
|
||||
if (!isBuiltInArrayIntrinsic(functionDescriptor) && directMember !is DescriptorWithContainerSource) {
|
||||
@@ -544,6 +549,16 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
return getCompiledMethodNodeInner(functionDescriptor, directMember, asmMethod, methodOwner, state, jvmSignature)
|
||||
}
|
||||
|
||||
private fun mapMethod(
|
||||
state: GenerationState,
|
||||
functionDescriptor: FunctionDescriptor,
|
||||
sourceCompiler: SourceCompilerForInline,
|
||||
jvmSignature: JvmMethodSignature,
|
||||
callDefault: Boolean
|
||||
): Method =
|
||||
if (callDefault) state.typeMapper.mapDefaultMethod(functionDescriptor, sourceCompiler.contextKind)
|
||||
else mangleSuspendInlineFunctionAsmMethodIfNeeded(functionDescriptor, jvmSignature.asmMethod)
|
||||
|
||||
internal fun createSpecialInlineMethodNodeFromBinaries(functionDescriptor: FunctionDescriptor, state: GenerationState): MethodNode {
|
||||
val directMember = getDirectMemberAndCallableFromObject(functionDescriptor)
|
||||
assert(directMember is DescriptorWithContainerSource) {
|
||||
|
||||
@@ -130,7 +130,9 @@ fun <T, R : DefaultLambda> expandMaskConditionsAndUpdateVariableNodes(
|
||||
node.instructions.insert(position, newInsn)
|
||||
}
|
||||
|
||||
node.localVariables.removeIf { it.start in toDelete && it.end in toDelete }
|
||||
node.localVariables.removeIf {
|
||||
(it.start in toDelete && it.end in toDelete) || defaultLambdas.contains(it.index)
|
||||
}
|
||||
|
||||
node.remove(toDelete)
|
||||
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
@@ -44,6 +41,10 @@ fun CallableDescriptor.isGenericParameter(): Boolean {
|
||||
fun classFileContainsMethod(descriptor: FunctionDescriptor, state: GenerationState, method: Method): Boolean? {
|
||||
if (descriptor !is DeserializedSimpleFunctionDescriptor) return null
|
||||
|
||||
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
return descriptor.overriddenDescriptors.any { classFileContainsMethod(it, state, method) == true }
|
||||
}
|
||||
|
||||
val classId: ClassId = when {
|
||||
descriptor.containingDeclaration is DeserializedClassDescriptor -> {
|
||||
(descriptor.containingDeclaration as DeserializedClassDescriptor).classId ?: return null
|
||||
|
||||
@@ -201,7 +201,7 @@ class GenerationState private constructor(
|
||||
|
||||
val target = configuration.get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT
|
||||
val runtimeStringConcat =
|
||||
if (target.bytecodeVersion >= JvmTarget.JVM_9.bytecodeVersion)
|
||||
if (target.majorVersion >= JvmTarget.JVM_9.majorVersion)
|
||||
configuration.get(JVMConfigurationKeys.STRING_CONCAT) ?: JvmStringConcat.INLINE
|
||||
else JvmStringConcat.INLINE
|
||||
|
||||
@@ -272,7 +272,10 @@ class GenerationState private constructor(
|
||||
|
||||
val rootContext: CodegenContext<*> = RootContext(this)
|
||||
|
||||
val classFileVersion: Int = target.bytecodeVersion
|
||||
val classFileVersion: Int = run {
|
||||
val minorVersion = if (configuration.getBoolean(JVMConfigurationKeys.ENABLE_JVM_PREVIEW)) 0xffff else 0
|
||||
(minorVersion shl 16) + target.majorVersion
|
||||
}
|
||||
|
||||
val generateParametersMetadata: Boolean = configuration.getBoolean(JVMConfigurationKeys.PARAMETERS_METADATA)
|
||||
|
||||
@@ -295,7 +298,7 @@ class GenerationState private constructor(
|
||||
?: if (languageVersionSettings.languageVersion >= LanguageVersion.LATEST_STABLE) JvmMetadataVersion.INSTANCE
|
||||
else JvmMetadataVersion(1, 1, 18)
|
||||
|
||||
val isIrWithStableAbi = configuration.getBoolean(JVMConfigurationKeys.IS_IR_WITH_STABLE_ABI)
|
||||
val abiStability = configuration.get(JVMConfigurationKeys.ABI_STABILITY)
|
||||
|
||||
val globalSerializationBindings = JvmSerializationBindings()
|
||||
var mapInlineClass: (ClassDescriptor) -> Type = { descriptor -> typeMapper.mapType(descriptor.defaultType) }
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils.getDelegationConstructorCall
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils.isBoxedLocalCapturedInClosure
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
@@ -60,6 +61,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isPublishedApi
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.DEFAULT_CONSTRUCTOR_MARKER
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
|
||||
import org.jetbrains.kotlin.resolve.jvm.JAVA_LANG_RECORD_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefault
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
||||
@@ -563,10 +565,16 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
||||
return when {
|
||||
descriptor is PropertyAccessorDescriptor -> {
|
||||
val property = descriptor.correspondingProperty
|
||||
if (isAnnotationClass(property.containingDeclaration)) {
|
||||
val containingDeclaration = property.containingDeclaration
|
||||
|
||||
if (isAnnotationClass(containingDeclaration) &&
|
||||
(!property.hasJvmStaticAnnotation() && !descriptor.hasJvmStaticAnnotation())
|
||||
) {
|
||||
return property.name.asString()
|
||||
}
|
||||
|
||||
if ((containingDeclaration as? ClassDescriptor)?.hasJavaLangRecordSupertype() == true) return property.name.asString()
|
||||
|
||||
val isAccessor = property is AccessorForPropertyDescriptor
|
||||
val propertyName = if (isAccessor)
|
||||
(property as AccessorForPropertyDescriptor).accessorSuffix
|
||||
@@ -601,6 +609,9 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassDescriptor.hasJavaLangRecordSupertype() =
|
||||
typeConstructor.supertypes.any { KotlinBuiltIns.isConstructedFromGivenClass(it, JAVA_LANG_RECORD_FQ_NAME) }
|
||||
|
||||
private val shouldMangleByReturnType =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses)
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ if "%_KOTLIN_RUNNER%"=="1" (
|
||||
"%_JAVACMD%" %JAVA_OPTS% "-Dkotlin.home=%_KOTLIN_HOME%" -cp "%_KOTLIN_HOME%\lib\kotlin-runner.jar" ^
|
||||
org.jetbrains.kotlin.runner.Main %KOTLIN_OPTS%
|
||||
) else (
|
||||
setlocal EnableDelayedExpansion
|
||||
SET _ADDITIONAL_CLASSPATH=
|
||||
|
||||
if not "%_KOTLIN_TOOL%"=="" (
|
||||
@@ -56,7 +57,7 @@ if "%_KOTLIN_RUNNER%"=="1" (
|
||||
)
|
||||
|
||||
"%_JAVACMD%" %JAVA_OPTS% -noverify -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^
|
||||
org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar%_ADDITIONAL_CLASSPATH%" ^
|
||||
org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar!_ADDITIONAL_CLASSPATH!" ^
|
||||
%_KOTLIN_COMPILER% %KOTLIN_OPTS%
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<id>org.jetbrains.kotlin</id>
|
||||
<version>1.2</version>
|
||||
|
||||
<!-- Don't add more extension points here! Logic in KotlinCoreEnvironment assumes that there is only one EP. -->
|
||||
<!-- And this file should be removed once 202 is no longer supported -->
|
||||
<extensionPoints>
|
||||
<extensionPoint qualifiedName="com.intellij.psi.classFileDecompiler"
|
||||
interface="com.intellij.psi.compiled.ClassFileDecompilers$Decompiler"
|
||||
|
||||
@@ -85,8 +85,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xuse-ir", description = "Use the IR backend")
|
||||
var useIR: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xno-use-ir", description = "Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default")
|
||||
var noUseIR: Boolean by FreezableVar(false)
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@Argument(value = "-Xuse-old-backend", description = "Use the old JVM backend")
|
||||
var useOldBackend: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-check-local-names",
|
||||
@@ -95,18 +96,20 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
var irCheckLocalNames: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xallow-jvm-ir-dependencies",
|
||||
description = "When not using the IR backend, do not report errors on those classes in dependencies, " +
|
||||
"which were compiled by the IR backend"
|
||||
value = "-Xallow-unstable-dependencies",
|
||||
description = "Do not report errors on classes in dependencies, which were compiled by an unstable version of the Kotlin compiler"
|
||||
)
|
||||
var allowJvmIrDependencies: Boolean by FreezableVar(false)
|
||||
var allowUnstableDependencies: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-binary-with-stable-abi",
|
||||
description = "When using the IR backend, produce binaries which can be read by non-IR backend.\n" +
|
||||
"The author is responsible for verifying that the resulting binaries do indeed have the correct ABI"
|
||||
value = "-Xabi-stability",
|
||||
valueDescription = "{stable|unstable}",
|
||||
description = "When using unstable compiler features such as FIR, use 'stable' to mark generated class files as stable\n" +
|
||||
"to prevent diagnostics from stable compilers at the call site.\n" +
|
||||
"When using the JVM IR backend, conversely, use 'unstable' to mark generated class files as unstable\n" +
|
||||
"to force diagnostics to be reported."
|
||||
)
|
||||
var isIrWithStableAbi: Boolean by FreezableVar(false)
|
||||
var abiStability: String? by FreezableVar(null)
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-do-not-clear-binding-context",
|
||||
@@ -312,6 +315,13 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var jvmDefault: String by FreezableVar(JvmDefaultMode.DEFAULT.description)
|
||||
|
||||
@Argument(
|
||||
value = "-Xdefault-script-extension",
|
||||
valueDescription = "<script filename extension>",
|
||||
description = "Compile expressions and unrecognized scripts passed with the -script argument as scripts with given filename extension"
|
||||
)
|
||||
var defaultScriptExtension: String? by FreezableVar(null)
|
||||
|
||||
@Argument(value = "-Xdisable-standard-script", description = "Disable standard kotlin script support")
|
||||
var disableStandardScript: Boolean by FreezableVar(false)
|
||||
|
||||
@@ -418,6 +428,13 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var useOldInlineClassesManglingScheme: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xjvm-enable-preview",
|
||||
description = "Allow using features from Java language that are in preview phase.\n" +
|
||||
"Works as `--enable-preview` in Java. All class files are marked as preview-generated thus it won't be possible to use them in release environment"
|
||||
)
|
||||
var enableJvmPreview: Boolean by FreezableVar(false)
|
||||
|
||||
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
val result = super.configureAnalysisFlags(collector)
|
||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||
@@ -438,7 +455,8 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
result[JvmAnalysisFlags.sanitizeParentheses] = sanitizeParentheses
|
||||
result[JvmAnalysisFlags.suppressMissingBuiltinsError] = suppressMissingBuiltinsError
|
||||
result[JvmAnalysisFlags.irCheckLocalNames] = irCheckLocalNames
|
||||
result[AnalysisFlags.reportErrorsOnIrDependencies] = !useIR && !useFir && !allowJvmIrDependencies
|
||||
result[JvmAnalysisFlags.enableJvmPreview] = enableJvmPreview
|
||||
result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useFir
|
||||
result[JvmAnalysisFlags.disableUltraLightClasses] = disableUltraLightClasses
|
||||
return result
|
||||
}
|
||||
@@ -452,7 +470,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
}
|
||||
|
||||
override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) {
|
||||
if (!useIR) return
|
||||
if (!useIR || useOldBackend) return
|
||||
|
||||
if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_3
|
||||
|| languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
|
||||
|
||||
@@ -34,22 +34,36 @@ object Main {
|
||||
KOTLIN_HOME = File(home)
|
||||
}
|
||||
|
||||
enum class HowToRun(val argName: String) {
|
||||
GUESS("guess"),
|
||||
CLASSFILE("classfile"),
|
||||
JAR("jar"),
|
||||
SCRIPT("script");
|
||||
// TODO: consider implementing REPL as well
|
||||
|
||||
companion object {
|
||||
val validValues = "${GUESS.argName} (default), ${CLASSFILE.argName}, ${JAR.argName}, ${SCRIPT.argName} (or .<script filename extension>)"
|
||||
|
||||
fun fromArg(name: String): HowToRun? =
|
||||
HowToRun.values().find { it.argName == name }
|
||||
}
|
||||
}
|
||||
|
||||
private fun run(args: Array<String>) {
|
||||
val classpath = arrayListOf<URL>()
|
||||
val compilerClasspath = arrayListOf<URL>()
|
||||
var runner: Runner? = null
|
||||
var collectingArguments = false
|
||||
var collectingExpressions = false
|
||||
var needsCompiler = false
|
||||
val arguments = arrayListOf<String>()
|
||||
var expression: String? = null
|
||||
val compilerArguments = arrayListOf<String>()
|
||||
var noStdLib = false
|
||||
var noReflect = false
|
||||
var howtorun = HowToRun.GUESS
|
||||
|
||||
fun setExpression(expr: String) {
|
||||
if (expression == null) {
|
||||
expression = expr
|
||||
fun setRunner(newRunner: Runner) {
|
||||
if (runner == null) {
|
||||
runner = newRunner
|
||||
} else {
|
||||
throw RunnerException("Only single -e/-expression argument supported")
|
||||
throw AssertionError("conflicting runner settings")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,20 +78,8 @@ object Main {
|
||||
return args[i]
|
||||
}
|
||||
|
||||
if (collectingExpressions) {
|
||||
if ("-expression" == arg || "-e" == arg) {
|
||||
setExpression(next())
|
||||
i++
|
||||
continue
|
||||
} else {
|
||||
collectingArguments = true
|
||||
}
|
||||
}
|
||||
|
||||
if (collectingArguments) {
|
||||
arguments.add(arg)
|
||||
i++
|
||||
continue
|
||||
fun restAsArguments() {
|
||||
arguments.addAll(args.copyOfRange(i+1, args.size))
|
||||
}
|
||||
|
||||
if ("-help" == arg || "-h" == arg) {
|
||||
@@ -96,29 +98,55 @@ object Main {
|
||||
compilerClasspath.addPath(path)
|
||||
}
|
||||
}
|
||||
else if ("-howtorun" == arg) {
|
||||
if (howtorun != HowToRun.GUESS) {
|
||||
throw RunnerException("-howtorun is already set to ${howtorun.argName}")
|
||||
}
|
||||
val howToRunArg = next()
|
||||
if (howToRunArg.startsWith(".")) {
|
||||
howtorun = HowToRun.SCRIPT
|
||||
compilerArguments.add("-Xdefault-script-extension=$howToRunArg")
|
||||
} else {
|
||||
howtorun = HowToRun.fromArg(howToRunArg)
|
||||
?: throw RunnerException("invalid argument to the option -howtorun $howToRunArg, valid arguments are: ${HowToRun.validValues}")
|
||||
}
|
||||
}
|
||||
else if ("-expression" == arg || "-e" == arg) {
|
||||
setExpression(next())
|
||||
collectingExpressions = true
|
||||
needsCompiler = true
|
||||
if (howtorun != HowToRun.GUESS && howtorun != HowToRun.SCRIPT) {
|
||||
throw RunnerException("expression evaluation is not compatible with -howtorun argument ${howtorun.argName}")
|
||||
}
|
||||
setRunner(ExpressionRunner(next()))
|
||||
restAsArguments()
|
||||
break
|
||||
}
|
||||
else if ("-no-stdlib" == arg) {
|
||||
noStdLib = true
|
||||
compilerArguments.add(arg)
|
||||
}
|
||||
else if ("-no-reflect" == arg) {
|
||||
noReflect = true
|
||||
compilerArguments.add(arg)
|
||||
}
|
||||
else if (arg.startsWith("-X")) {
|
||||
compilerArguments.add(arg)
|
||||
}
|
||||
else if (arg.startsWith("-")) {
|
||||
throw RunnerException("unsupported argument: $arg")
|
||||
throw RunnerException("unknown option: $arg")
|
||||
}
|
||||
else if (arg.endsWith(".jar")) {
|
||||
runner = JarRunner(arg)
|
||||
collectingArguments = true
|
||||
else if (howtorun == HowToRun.JAR || (howtorun == HowToRun.GUESS && arg.endsWith(".jar"))) {
|
||||
setRunner(JarRunner(arg))
|
||||
restAsArguments()
|
||||
break
|
||||
}
|
||||
else if (arg.endsWith(".kts")) {
|
||||
runner = ScriptRunner(arg)
|
||||
collectingArguments = true
|
||||
needsCompiler = true
|
||||
else if (howtorun == HowToRun.SCRIPT || (howtorun == HowToRun.GUESS && arg.endsWith(".kts"))) {
|
||||
setRunner(ScriptRunner(arg))
|
||||
restAsArguments()
|
||||
break
|
||||
}
|
||||
else {
|
||||
runner = MainClassRunner(arg)
|
||||
collectingArguments = true
|
||||
setRunner(MainClassRunner(arg))
|
||||
restAsArguments()
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
@@ -127,26 +155,25 @@ object Main {
|
||||
classpath.addPath(".")
|
||||
}
|
||||
|
||||
classpath.addPath("$KOTLIN_HOME/lib/kotlin-stdlib.jar")
|
||||
if (!noStdLib) {
|
||||
classpath.addPath("$KOTLIN_HOME/lib/kotlin-stdlib.jar")
|
||||
}
|
||||
|
||||
if (!noReflect) {
|
||||
classpath.addPath("$KOTLIN_HOME/lib/kotlin-reflect.jar")
|
||||
}
|
||||
|
||||
if (expression != null) {
|
||||
runner = ExpressionRunner(expression!!)
|
||||
} else if (runner == null) {
|
||||
runner = ReplRunner()
|
||||
needsCompiler = true
|
||||
if (runner == null) {
|
||||
setRunner(ReplRunner())
|
||||
}
|
||||
|
||||
if (needsCompiler && compilerClasspath.isEmpty()) {
|
||||
if (runner is RunnerWithCompiler && compilerClasspath.isEmpty()) {
|
||||
findCompilerJar(this::class.java, KOTLIN_HOME.resolve("lib")).forEach {
|
||||
compilerClasspath.add(it.absoluteFile.toURI().toURL())
|
||||
}
|
||||
}
|
||||
|
||||
runner.run(classpath, arguments, compilerClasspath)
|
||||
runner!!.run(classpath, compilerArguments, arguments, compilerClasspath)
|
||||
}
|
||||
|
||||
private fun MutableList<URL>.addPath(path: String) {
|
||||
@@ -167,21 +194,31 @@ object Main {
|
||||
private fun printUsageAndExit() {
|
||||
println("""kotlin: run Kotlin programs, scripts or REPL.
|
||||
|
||||
Usage: kotlin <options> <command> <arguments>
|
||||
where command may be one of:
|
||||
foo.Bar Runs the 'main' function from the class with the given qualified name
|
||||
app.jar Runs the given JAR file as 'java -jar' would do
|
||||
(-classpath argument is ignored and no Kotlin runtime is added to the classpath)
|
||||
""" +
|
||||
// script.kts Compiles and runs the given script
|
||||
// -expression (-e) '2+2' Evaluates the expression and prints the result
|
||||
"""and possible options include:
|
||||
Usage: kotlin <options> <command> [<arguments>]
|
||||
where possible options include:
|
||||
-howtorun <value> How to run the supplied command with arguments,
|
||||
valid values: ${HowToRun.validValues}
|
||||
-classpath (-cp) <path> Paths where to find user class files
|
||||
-Dname=value Set a system JVM property
|
||||
-J<option> Pass an option directly to JVM
|
||||
-no-stdlib Don't include Kotlin standard library into classpath
|
||||
-no-reflect Don't include Kotlin reflection implementation into classpath
|
||||
-compiler-path Kotlin compiler classpath for compiling script or expression or running REPL
|
||||
If not specified, try to find the compiler in the environment
|
||||
-X<flag>[=value] Pass -X argument to the compiler
|
||||
-version Display Kotlin version
|
||||
-help (-h) Print a synopsis of options
|
||||
and command is interpreted according to the -howtorun option argument
|
||||
or, in case of guess, according to the following rules:
|
||||
foo.Bar Runs the 'main' function from the class with the given qualified name
|
||||
(compiler arguments are ignored)
|
||||
app.jar Runs the given JAR file as 'java -jar' would do
|
||||
(compiler arguments are ignored and no Kotlin stdlib is added to the classpath)
|
||||
script.kts Compiles and runs the given script, passing <arguments> to it
|
||||
-expression (-e) '2+2' Evaluates the expression and prints the result, passing <arguments> to it
|
||||
<no command> Runs Kotlin REPL
|
||||
arguments are passed to the main function when running class or jar file, and for standard script definitions
|
||||
as the 'args' parameter when running script or expression
|
||||
""")
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.net.URL
|
||||
interface Runner {
|
||||
fun run(
|
||||
classpath: List<URL>,
|
||||
compilerArguments: List<String>,
|
||||
arguments: List<String>,
|
||||
compilerClasspath: List<URL>
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class AbstractRunner : Runner {
|
||||
|
||||
protected abstract fun createClassLoader(classpath: List<URL>): ClassLoader
|
||||
|
||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val classLoader = createClassLoader(classpath)
|
||||
|
||||
val mainClass = try {
|
||||
@@ -127,39 +127,45 @@ private fun MutableList<String>.addClasspathArgIfNeeded(classpath: List<URL>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ArrayList<String>.addScriptArguments(arguments: List<String>) {
|
||||
if (arguments.isNotEmpty() && arguments.first() != "--") {
|
||||
add("--")
|
||||
}
|
||||
addAll(arguments)
|
||||
}
|
||||
|
||||
class ReplRunner : RunnerWithCompiler() {
|
||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val compilerArgs = ArrayList<String>()
|
||||
compilerArgs.addClasspathArgIfNeeded(classpath)
|
||||
override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val compilerArgs = ArrayList<String>().apply {
|
||||
addClasspathArgIfNeeded(classpath)
|
||||
addAll(compilerArguments)
|
||||
addScriptArguments(arguments)
|
||||
}
|
||||
runCompiler(compilerClasspath, compilerArgs)
|
||||
}
|
||||
}
|
||||
|
||||
class ScriptRunner(private val path: String) : RunnerWithCompiler() {
|
||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val compilerArgs = ArrayList<String>().apply {
|
||||
addClasspathArgIfNeeded(classpath)
|
||||
addAll(compilerArguments)
|
||||
add("-script")
|
||||
add(path)
|
||||
if (arguments.isNotEmpty() && arguments.first() != "--") {
|
||||
add("--")
|
||||
}
|
||||
addAll(arguments)
|
||||
addScriptArguments(arguments)
|
||||
}
|
||||
runCompiler(compilerClasspath, compilerArgs)
|
||||
}
|
||||
}
|
||||
|
||||
class ExpressionRunner(private val code: String) : RunnerWithCompiler() {
|
||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val compilerArgs = ArrayList<String>().apply {
|
||||
addClasspathArgIfNeeded(classpath)
|
||||
addAll(compilerArguments)
|
||||
add("-expression")
|
||||
add(code)
|
||||
if (arguments.isNotEmpty() && arguments.first() != "--") {
|
||||
add("--")
|
||||
}
|
||||
addAll(arguments)
|
||||
addScriptArguments(arguments)
|
||||
}
|
||||
runCompiler(compilerClasspath, compilerArgs)
|
||||
}
|
||||
|
||||
@@ -182,11 +182,19 @@ class AnalyzerWithCompilerReport(
|
||||
)
|
||||
}
|
||||
|
||||
if (diagnostics.any { it.factory == Errors.IR_COMPILED_CLASS }) {
|
||||
if (diagnostics.any { it.factory == Errors.IR_WITH_UNSTABLE_ABI_COMPILED_CLASS }) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Classes compiled by a new Kotlin compiler backend were found in dependencies. " +
|
||||
"Remove them from the classpath or use '-Xallow-jvm-ir-dependencies' to suppress errors"
|
||||
"Classes compiled by an unstable version of the Kotlin compiler were found in dependencies. " +
|
||||
"Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors"
|
||||
)
|
||||
}
|
||||
|
||||
if (diagnostics.any { it.factory == Errors.FIR_COMPILED_CLASS }) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Classes compiled by the new Kotlin compiler frontend were found in dependencies. " +
|
||||
"Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
|
||||
fun Project.setupHighestLanguageLevel() {
|
||||
LanguageLevelProjectExtension.getInstance(this).languageLevel = LanguageLevel.JDK_15_PREVIEW
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
|
||||
fun Project.setupHighestLanguageLevel() {
|
||||
// LanguageLevelProjectExtension.getInstance(this).languageLevel = LanguageLevel.JDK_15_PREVIEW
|
||||
}
|
||||
@@ -33,13 +33,16 @@ import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.extensions.ExtensionsArea
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.*
|
||||
import com.intellij.openapi.vfs.impl.ZipHandler
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.compiled.ClassFileDecompilers
|
||||
import com.intellij.psi.impl.JavaClassSupersImpl
|
||||
import com.intellij.psi.impl.PsiElementFinderImpl
|
||||
import com.intellij.psi.impl.PsiTreeChangePreprocessor
|
||||
@@ -249,6 +252,8 @@ class KotlinCoreEnvironment private constructor(
|
||||
project.putUserData(APPEND_JAVA_SOURCE_ROOTS_HANDLER_KEY, fun(roots: List<File>) {
|
||||
updateClasspath(roots.map { JavaSourceRoot(it, null) })
|
||||
})
|
||||
|
||||
project.setupHighestLanguageLevel()
|
||||
}
|
||||
|
||||
private fun collectAdditionalSources(project: MockProject) {
|
||||
@@ -509,7 +514,11 @@ class KotlinCoreEnvironment private constructor(
|
||||
val applicationEnvironment = KotlinCoreApplicationEnvironment.create(parentDisposable, unitTestMode)
|
||||
|
||||
registerApplicationExtensionPointsAndExtensionsFrom(configuration, "extensions/compiler.xml")
|
||||
registerApplicationExtensionPointsAndExtensionsFrom(configuration, "extensions/core.xml")
|
||||
// FIX ME WHEN BUNCH 202 REMOVED: this code is required to support compiler bundled to both 202 and 203.
|
||||
// Please, remove "com.intellij.psi.classFileDecompiler" EP registration once 202 is no longer supported by the compiler
|
||||
if (!Extensions.getRootArea().hasExtensionPoint("com.intellij.psi.classFileDecompiler")) {
|
||||
registerApplicationExtensionPointsAndExtensionsFrom(configuration, "extensions/core.xml")
|
||||
}
|
||||
|
||||
registerApplicationServicesForCLI(applicationEnvironment)
|
||||
registerApplicationServices(applicationEnvironment)
|
||||
|
||||
@@ -649,8 +649,10 @@ class KotlinCoreEnvironment private constructor(
|
||||
registerService(CliLightClassGenerationSupport::class.java, cliLightClassGenerationSupport)
|
||||
registerService(KotlinAsJavaSupport::class.java, kotlinAsJavaSupport)
|
||||
registerService(CodeAnalyzerInitializer::class.java, traceHolder)
|
||||
@Suppress("UnstableApiUsage")
|
||||
registerService(DumbUtil::class.java, KotlinCoreDumbUtil())
|
||||
if (getService(DumbUtil::class.java) == null) {
|
||||
@Suppress("UnstableApiUsage")
|
||||
registerService(DumbUtil::class.java, KotlinCoreDumbUtil())
|
||||
}
|
||||
|
||||
val area = Extensions.getArea(this)
|
||||
|
||||
|
||||
@@ -52,10 +52,10 @@ import org.jetbrains.kotlin.codegen.state.GenerationStateEventCallback
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.fir.analysis.FirAnalyzerFacade
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirMetadataSerializer
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendExtension
|
||||
import org.jetbrains.kotlin.fir.checkers.registerExtendedCommonCheckers
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.session.FirJvmModuleInfo
|
||||
@@ -389,10 +389,8 @@ object KotlinToJVMBytecodeCompiler {
|
||||
performanceManager?.notifyIRGenerationStarted()
|
||||
generationState.beforeCompile()
|
||||
codegenFactory.generateModuleInFrontendIRMode(
|
||||
generationState, moduleFragment, symbolTable, sourceManager, extensions
|
||||
) { context, irClass, _, serializationBindings, parent ->
|
||||
FirMetadataSerializer(session, context, irClass, serializationBindings, parent)
|
||||
}
|
||||
generationState, moduleFragment, symbolTable, sourceManager, extensions, FirJvmBackendExtension(session, components)
|
||||
)
|
||||
CodegenFactory.doCheckCancelled(generationState)
|
||||
generationState.factory.done()
|
||||
|
||||
@@ -463,6 +461,10 @@ object KotlinToJVMBytecodeCompiler {
|
||||
environment.updateClasspath(result.additionalJavaRoots.map { JavaSourceRoot(it, null) })
|
||||
}
|
||||
|
||||
if (result.additionalClassPathRoots.isNotEmpty()) {
|
||||
environment.updateClasspath(result.additionalClassPathRoots.map { JvmClasspathRoot(it, false) })
|
||||
}
|
||||
|
||||
if (result.additionalKotlinRoots.isNotEmpty()) {
|
||||
environment.addKotlinSourceRoots(result.additionalKotlinRoots)
|
||||
}
|
||||
@@ -472,8 +474,8 @@ object KotlinToJVMBytecodeCompiler {
|
||||
// Clear all diagnostic messages
|
||||
configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]?.clear()
|
||||
|
||||
// Repeat analysis with additional Java roots (kapt generated sources)
|
||||
return analyze(environment)
|
||||
// Repeat analysis with additional source roots generated by compiler plugins.
|
||||
return repeatAnalysisIfNeeded(analyze(environment), environment)
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -568,8 +570,6 @@ object KotlinToJVMBytecodeCompiler {
|
||||
sourceFiles: List<KtFile>,
|
||||
module: Module?
|
||||
): GenerationState {
|
||||
val isIR = (configuration.getBoolean(JVMConfigurationKeys.IR) ||
|
||||
configuration.getBoolean(CommonConfigurationKeys.USE_FIR))
|
||||
val generationState = GenerationState.Builder(
|
||||
environment.project,
|
||||
ClassBuilderFactories.BINARIES,
|
||||
@@ -579,13 +579,12 @@ object KotlinToJVMBytecodeCompiler {
|
||||
configuration
|
||||
)
|
||||
.codegenFactory(
|
||||
if (isIR) JvmIrCodegenFactory(
|
||||
if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory(
|
||||
configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases)
|
||||
) else DefaultCodegenFactory
|
||||
)
|
||||
.withModule(module)
|
||||
.onIndependentPartCompilationEnd(createOutputFilesFlushingCallbackIfPossible(configuration))
|
||||
.isIrBackend(isIR)
|
||||
.build()
|
||||
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.getLibraryFromHome
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
||||
@@ -19,9 +20,6 @@ import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.io.File
|
||||
|
||||
fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArguments) {
|
||||
|
||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
put(JVMConfigurationKeys.INCLUDE_RUNTIME, arguments.includeRuntime)
|
||||
|
||||
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
|
||||
@@ -39,7 +37,7 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
}
|
||||
|
||||
val jvmTarget = get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT
|
||||
if (jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion) {
|
||||
if (jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion) {
|
||||
val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
|
||||
if (jvmDefaultMode.forAllMethodsWithBody) {
|
||||
messageCollector.report(
|
||||
@@ -53,7 +51,7 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
val runtimeStringConcat = JvmStringConcat.fromString(arguments.stringConcat!!)
|
||||
if (runtimeStringConcat != null) {
|
||||
put(JVMConfigurationKeys.STRING_CONCAT, runtimeStringConcat)
|
||||
if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmStringConcat.INLINE) {
|
||||
if (jvmTarget.majorVersion < JvmTarget.JVM_9.majorVersion && runtimeStringConcat != JvmStringConcat.INLINE) {
|
||||
messageCollector.report(
|
||||
WARNING,
|
||||
"`-Xstring-concat=${arguments.stringConcat}` does nothing with JVM target `${jvmTarget.description}`."
|
||||
@@ -71,9 +69,6 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): Boolean {
|
||||
|
||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
if (arguments.noJdk) {
|
||||
put(JVMConfigurationKeys.NO_JDK, true)
|
||||
|
||||
@@ -84,7 +79,7 @@ fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): B
|
||||
}
|
||||
|
||||
if (arguments.jdkHome != null) {
|
||||
val jdkHome = File(arguments.jdkHome)
|
||||
val jdkHome = File(arguments.jdkHome!!)
|
||||
if (!jdkHome.exists()) {
|
||||
messageCollector.report(ERROR, "JDK home directory does not exist: $jdkHome")
|
||||
return false
|
||||
@@ -114,7 +109,6 @@ fun CompilerConfiguration.configureExplicitContentRoots(arguments: K2JVMCompiler
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
val isModularJava = isModularJava()
|
||||
|
||||
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
||||
@@ -171,8 +165,38 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
|
||||
put(JVMConfigurationKeys.PARAMETERS_METADATA, arguments.javaParameters)
|
||||
|
||||
put(JVMConfigurationKeys.IR, arguments.useIR && !arguments.noUseIR)
|
||||
put(JVMConfigurationKeys.IS_IR_WITH_STABLE_ABI, arguments.isIrWithStableAbi)
|
||||
val useIR = arguments.useFir ||
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.JvmIrEnabledByDefault)) {
|
||||
!arguments.useOldBackend
|
||||
} else {
|
||||
arguments.useIR && !arguments.useOldBackend
|
||||
}
|
||||
|
||||
if (arguments.useIR && arguments.useOldBackend) {
|
||||
messageCollector.report(
|
||||
STRONG_WARNING,
|
||||
"Both -Xuse-ir and -Xuse-old-backend are passed. This is an inconsistent configuration. " +
|
||||
"The compiler will use the ${if (useIR) "JVM IR" else "old JVM"} backend"
|
||||
)
|
||||
}
|
||||
messageCollector.report(LOGGING, "Using ${if (useIR) "JVM IR" else "old JVM"} backend")
|
||||
|
||||
put(JVMConfigurationKeys.IR, useIR)
|
||||
|
||||
val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability)
|
||||
if (arguments.abiStability != null) {
|
||||
if (abiStability == null) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Unknown ABI stability mode: ${arguments.abiStability}, supported modes: ${JvmAbiStability.values().map { it.description }}"
|
||||
)
|
||||
} else if (!useIR && abiStability == JvmAbiStability.UNSTABLE) {
|
||||
messageCollector.report(ERROR, "-Xabi-stability=unstable is not supported in the old JVM backend")
|
||||
} else {
|
||||
put(JVMConfigurationKeys.ABI_STABILITY, abiStability)
|
||||
}
|
||||
}
|
||||
|
||||
put(JVMConfigurationKeys.DO_NOT_CLEAR_BINDING_CONTEXT, arguments.doNotClearBindingContext)
|
||||
put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, arguments.noCallAssertions)
|
||||
put(JVMConfigurationKeys.DISABLE_RECEIVER_ASSERTIONS, arguments.noReceiverAssertions)
|
||||
@@ -189,57 +213,54 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
put(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS, arguments.noUnifiedNullChecks)
|
||||
|
||||
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " +
|
||||
"supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}"
|
||||
)
|
||||
}
|
||||
|
||||
val constructorCallNormalizationMode =
|
||||
JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
|
||||
val constructorCallNormalizationMode = JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
|
||||
if (constructorCallNormalizationMode != null) {
|
||||
put(
|
||||
JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
|
||||
constructorCallNormalizationMode
|
||||
)
|
||||
put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, constructorCallNormalizationMode)
|
||||
}
|
||||
|
||||
val assertionsMode =
|
||||
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
|
||||
if (assertionsMode == null) {
|
||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"Unknown assertions mode: ${arguments.assertionsMode}, " +
|
||||
"supported modes: ${JVMAssertionsMode.values().map { it.description }}"
|
||||
"Unknown assertions mode: ${arguments.assertionsMode}, supported modes: ${JVMAssertionsMode.values().map { it.description }}"
|
||||
)
|
||||
}
|
||||
put(
|
||||
JVMConfigurationKeys.ASSERTIONS_MODE,
|
||||
assertionsMode ?: JVMAssertionsMode.DEFAULT
|
||||
)
|
||||
put(JVMConfigurationKeys.ASSERTIONS_MODE, assertionsMode ?: JVMAssertionsMode.DEFAULT)
|
||||
|
||||
put(JVMConfigurationKeys.USE_TYPE_TABLE, arguments.useTypeTable)
|
||||
put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck)
|
||||
put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, arguments.useOldClassFilesReading)
|
||||
|
||||
if (arguments.useOldClassFilesReading) {
|
||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
.report(INFO, "Using the old java class files reading implementation")
|
||||
messageCollector.report(INFO, "Using the old java class files reading implementation")
|
||||
}
|
||||
|
||||
put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
|
||||
put(JVMConfigurationKeys.USE_SINGLE_MODULE, arguments.singleModule)
|
||||
put(JVMConfigurationKeys.USE_OLD_SPILLED_VAR_TYPE_ANALYSIS, arguments.useOldSpilledVarTypeAnalysis)
|
||||
put(JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME, arguments.useOldInlineClassesManglingScheme)
|
||||
put(JVMConfigurationKeys.ENABLE_JVM_PREVIEW, arguments.enableJvmPreview)
|
||||
|
||||
if (arguments.enableJvmPreview) {
|
||||
messageCollector.report(INFO, "Using preview Java language features")
|
||||
}
|
||||
|
||||
arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) {
|
||||
assert(arguments.useIR || arguments.klibLibraries == null) { "Klib libraries can only be used with IR backend" }
|
||||
arguments.klibLibraries?.split(File.pathSeparator.toRegex())
|
||||
?.toTypedArray()
|
||||
?.filterNot { it.isEmpty() }
|
||||
?.let { put(JVMConfigurationKeys.KLIB_PATHS, it) }
|
||||
}
|
||||
val libraries = arguments.klibLibraries ?: return
|
||||
assert(arguments.useIR && !arguments.useOldBackend) { "Klib libraries can only be used with IR backend" }
|
||||
put(JVMConfigurationKeys.KLIB_PATHS, libraries.split(File.pathSeparator.toRegex()).filterNot(String::isEmpty))
|
||||
}
|
||||
|
||||
private val CompilerConfiguration.messageCollector: MessageCollector
|
||||
get() = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
@@ -117,8 +117,8 @@ public class JVMConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<List<String>> KLIB_PATHS =
|
||||
CompilerConfigurationKey.create("Paths to .klib libraries");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> IS_IR_WITH_STABLE_ABI =
|
||||
CompilerConfigurationKey.create("Is IR with stable ABI");
|
||||
public static final CompilerConfigurationKey<JvmAbiStability> ABI_STABILITY =
|
||||
CompilerConfigurationKey.create("ABI stability of class files produced by JVM IR and/or FIR");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> DO_NOT_CLEAR_BINDING_CONTEXT =
|
||||
CompilerConfigurationKey.create("When using the IR backend, do not clear BindingContext between psi2ir and lowerings");
|
||||
@@ -140,4 +140,7 @@ public class JVMConfigurationKeys {
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> USE_OLD_INLINE_CLASSES_MANGLING_SCHEME =
|
||||
CompilerConfigurationKey.create("Use old, 1.4 version of inline classes mangling scheme");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> ENABLE_JVM_PREVIEW =
|
||||
CompilerConfigurationKey.create("Enable Java language preview features");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
enum class JvmAbiStability(val description: String) {
|
||||
STABLE("stable"),
|
||||
UNSTABLE("unstable"),
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromStringOrNull(string: String?): JvmAbiStability? =
|
||||
values().find { it.description == string }
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,9 @@ object JvmAnalysisFlags {
|
||||
@JvmStatic
|
||||
val disableUltraLightClasses by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@JvmStatic
|
||||
val enableJvmPreview by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
private object Delegates {
|
||||
object JavaTypeEnhancementStateWarnByDefault {
|
||||
operator fun provideDelegate(instance: Any?, property: KProperty<*>): AnalysisFlag.Delegate<JavaTypeEnhancementState> =
|
||||
|
||||
@@ -19,32 +19,21 @@ package org.jetbrains.kotlin.config
|
||||
import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
enum class JvmTarget(override val description: String) : TargetPlatformVersion {
|
||||
JVM_1_6("1.6"),
|
||||
JVM_1_8("1.8"),
|
||||
JVM_9("9"),
|
||||
JVM_10("10"),
|
||||
JVM_11("11"),
|
||||
JVM_12("12"),
|
||||
JVM_13("13"),
|
||||
JVM_14("14"),
|
||||
JVM_15("15"),
|
||||
enum class JvmTarget(
|
||||
override val description: String,
|
||||
val majorVersion: Int,
|
||||
) : TargetPlatformVersion {
|
||||
JVM_1_6("1.6", Opcodes.V1_6),
|
||||
JVM_1_8("1.8", Opcodes.V1_8),
|
||||
JVM_9("9", Opcodes.V9),
|
||||
JVM_10("10", Opcodes.V10),
|
||||
JVM_11("11", Opcodes.V11),
|
||||
JVM_12("12", Opcodes.V12),
|
||||
JVM_13("13", Opcodes.V12 + 1),
|
||||
JVM_14("14", Opcodes.V12 + 2),
|
||||
JVM_15("15", Opcodes.V12 + 3),
|
||||
;
|
||||
|
||||
val bytecodeVersion: Int by lazy {
|
||||
when (this) {
|
||||
JVM_1_6 -> Opcodes.V1_6
|
||||
JVM_1_8 -> Opcodes.V1_8
|
||||
JVM_9 -> Opcodes.V9
|
||||
JVM_10 -> Opcodes.V10
|
||||
JVM_11 -> Opcodes.V11
|
||||
JVM_12 -> Opcodes.V12
|
||||
JVM_13 -> Opcodes.V12 + 1
|
||||
JVM_14 -> Opcodes.V12 + 2
|
||||
JVM_15 -> Opcodes.V12 + 3
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val DEFAULT = JVM_1_6
|
||||
@@ -52,14 +41,14 @@ enum class JvmTarget(override val description: String) : TargetPlatformVersion {
|
||||
@JvmStatic
|
||||
fun fromString(string: String) = values().find { it.description == string }
|
||||
|
||||
fun getDescription(bytecodeVersion: Int): String {
|
||||
val platformDescription = values().find { it.bytecodeVersion == bytecodeVersion }?.description ?: when (bytecodeVersion) {
|
||||
fun getDescription(majorVersion: Int): String {
|
||||
val platformDescription = values().find { it.majorVersion == majorVersion }?.description ?: when (majorVersion) {
|
||||
Opcodes.V1_7 -> "1.7"
|
||||
else -> null
|
||||
}
|
||||
|
||||
return if (platformDescription != null) "JVM target $platformDescription"
|
||||
else "JVM bytecode version $bytecodeVersion"
|
||||
else "JVM bytecode version $majorVersion"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ object AnalysisFlags {
|
||||
val ideMode by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@JvmStatic
|
||||
val reportErrorsOnIrDependencies by AnalysisFlag.Delegates.Boolean
|
||||
val allowUnstableDependencies by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@JvmStatic
|
||||
val libraryToSourceAnalysis by AnalysisFlag.Delegates.Boolean
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class Test : R|kotlin/Any| {
|
||||
|
||||
}
|
||||
|
||||
public final inline class Z : R|kotlin/Any| {
|
||||
@R|kotlin/jvm/JvmInline|() public final inline class Z : R|kotlin/Any| {
|
||||
public open operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean|
|
||||
|
||||
public open fun hashCode(): R|kotlin/Int|
|
||||
@@ -41,3 +41,4 @@ public final inline class Z : R|kotlin/Any| {
|
||||
public constructor(x: R|kotlin/Int|): R|test/Z|
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public final inline class Z : R|kotlin/Any| {
|
||||
@R|kotlin/jvm/JvmInline|() public final inline class Z : R|kotlin/Any| {
|
||||
public open operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean|
|
||||
|
||||
public open fun hashCode(): R|kotlin/Int|
|
||||
@@ -11,3 +11,4 @@ public final inline class Z : R|kotlin/Any| {
|
||||
@R|kotlin/PublishedApi|() internal constructor(value: R|kotlin/Int|): R|test/Z|
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7892,6 +7892,24 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/exceptions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Exceptions extends AbstractFirOldFrontendDiagnosticsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInExceptions() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/exceptions"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("kt24158.kt")
|
||||
public void testKt24158() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/exceptions/kt24158.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/exposed")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -10527,6 +10545,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/reportAboutUnresolvedReferenceAsUnresolved.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt")
|
||||
public void testReportNotEnoughTypeInformationErrorsOnBlockExpressions() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resolveWithUnknownLambdaParameterType.kt")
|
||||
public void testResolveWithUnknownLambdaParameterType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/resolveWithUnknownLambdaParameterType.kt");
|
||||
@@ -10537,14 +10560,9 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/returningLambdaInSuspendContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
|
||||
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
|
||||
@TestMetadata("specialCallsWithCallableReferences.kt")
|
||||
public void testSpecialCallsWithCallableReferences() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("starApproximation.kt")
|
||||
@@ -10602,6 +10620,59 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/useFunctionLiteralsToInferType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class BuilderInference extends AbstractFirOldFrontendDiagnosticsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuilderInference() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
|
||||
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferences.kt")
|
||||
public void testSpecialCallsWithCallableReferences() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt")
|
||||
public void testSpecialCallsWithCallableReferencesDontCareTypeInBlockExression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesDontRewriteAtSlice.kt")
|
||||
public void testSpecialCallsWithCallableReferencesDontRewriteAtSlice() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontRewriteAtSlice.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesErrorType.kt")
|
||||
public void testSpecialCallsWithCallableReferencesErrorType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesNonStrictOnlyInputTypes.kt")
|
||||
public void testSpecialCallsWithCallableReferencesNonStrictOnlyInputTypes() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesNonStrictOnlyInputTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithLambdas.kt")
|
||||
public void testSpecialCallsWithLambdas() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -10659,6 +10730,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedFlexibleIntersectionTypesWithDifferentBounds.kt")
|
||||
public void testCapturedFlexibleIntersectionTypesWithDifferentBounds() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedFlexibleIntersectionTypesWithDifferentBounds.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedFlexibleIntersectionTypesWithDifferentConstructors.kt")
|
||||
public void testCapturedFlexibleIntersectionTypesWithDifferentConstructors() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedFlexibleIntersectionTypesWithDifferentConstructors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedType.kt")
|
||||
public void testCapturedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.kt");
|
||||
@@ -10684,6 +10765,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypesSubstitutionIntoAbbreviation.kt")
|
||||
public void testCapturedTypesSubstitutionIntoAbbreviation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypesSubstitutionIntoAbbreviation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturingFromArgumentOfFlexibleType.kt")
|
||||
public void testCapturingFromArgumentOfFlexibleType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt");
|
||||
@@ -12200,6 +12286,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
public void testSubstitutionIntoInnerClass() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/substitutions/substitutionIntoInnerClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substitutionOfTypeEnhancement.kt")
|
||||
public void testSubstitutionOfTypeEnhancement() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/substitutions/substitutionOfTypeEnhancement.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/upperBounds")
|
||||
@@ -12907,6 +12998,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/inlineClassesInsideAnnotations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassInsideInlineClass.kt")
|
||||
public void testInnerClassInsideInlineClass() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/innerClassInsideInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lateinitInlineClasses.kt")
|
||||
public void testLateinitInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/lateinitInlineClasses.kt");
|
||||
@@ -12942,6 +13038,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/unsignedLiteralsWithoutArtifactOnClasspath.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("varPropertyWithInlineClassReceiver.kt")
|
||||
public void testVarPropertyWithInlineClassReceiver() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/varPropertyWithInlineClassReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("varargsOnParametersOfInlineClassType.kt")
|
||||
public void testVarargsOnParametersOfInlineClassType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/varargsOnParametersOfInlineClassType.kt");
|
||||
@@ -17728,6 +17829,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/platformTypes/typeEnhancement"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("buildFlexibleEnhancement.kt")
|
||||
public void testBuildFlexibleEnhancement() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/buildFlexibleEnhancement.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overriddenExtensions.kt")
|
||||
public void testOverriddenExtensions() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/overriddenExtensions.kt");
|
||||
@@ -19051,6 +19157,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resolveCollectionLiteralInsideLambda.kt")
|
||||
public void testResolveCollectionLiteralInsideLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/regressions/resolveCollectionLiteralInsideLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("resolveSubclassOfList.kt")
|
||||
public void testResolveSubclassOfList() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.kt");
|
||||
@@ -19542,6 +19653,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/invoke/kt9805.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reportFunctionExpectedOnSimpleUnresolved.kt")
|
||||
public void testReportFunctionExpectedOnSimpleUnresolved() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedOnSimpleUnresolved.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reportFunctionExpectedWhenOneInvokeExist.kt")
|
||||
public void testReportFunctionExpectedWhenOneInvokeExist() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/invoke/reportFunctionExpectedWhenOneInvokeExist.kt");
|
||||
@@ -20743,6 +20859,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveWhenWithElse.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExhaustiveWithFreedom.kt")
|
||||
public void testExhaustiveWithFreedom() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveWithFreedom.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritorInDifferentModule.kt")
|
||||
public void testInheritorInDifferentModule() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/inheritorInDifferentModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Local.kt")
|
||||
public void testLocal() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/Local.kt");
|
||||
@@ -20753,11 +20879,21 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/LocalSealed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultipleFiles_enabled.kt")
|
||||
public void testMultipleFiles_enabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/MultipleFiles_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedSealed.kt")
|
||||
public void testNestedSealed() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/NestedSealed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedSealedWithoutRestrictions.kt")
|
||||
public void testNestedSealedWithoutRestrictions() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/NestedSealedWithoutRestrictions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NeverConstructed.kt")
|
||||
public void testNeverConstructed() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/NeverConstructed.kt");
|
||||
@@ -20857,6 +20993,34 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
public void testWithInterface() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/WithInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/sealed/interfaces")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Interfaces extends AbstractFirOldFrontendDiagnosticsTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInInterfaces() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/sealed/interfaces"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritorInDifferentModule.kt")
|
||||
public void testInheritorInDifferentModule() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/inheritorInDifferentModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sealedInterfacesDisabled.kt")
|
||||
public void testSealedInterfacesDisabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/sealedInterfacesDisabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleSealedInterface.kt")
|
||||
public void testSimpleSealedInterface() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/simpleSealedInterface.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/secondaryConstructors")
|
||||
@@ -24403,6 +24567,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasRHS.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("boundsViolationRecursive.kt")
|
||||
public void testBoundsViolationRecursive() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/boundsViolationRecursive.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturingTypeParametersFromOuterClass.kt")
|
||||
public void testCapturingTypeParametersFromOuterClass() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.kt");
|
||||
@@ -24548,6 +24717,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/kt14518.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt14612.kt")
|
||||
public void testKt14612() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/kt14612.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt14641.kt")
|
||||
public void testKt14641() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typealias/kt14641.kt");
|
||||
|
||||
@@ -201,6 +201,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmRecordWithoutJdk15.kt")
|
||||
public void testJvmRecordWithoutJdk15() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmRecordWithoutJdk15.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
||||
public void testJvmSyntheticOnDelegate() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendExtension
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MetadataSerializer
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings
|
||||
import org.jetbrains.kotlin.config.JvmAbiStability
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
class FirJvmBackendExtension(private val session: FirSession, private val components: Fir2IrComponents) : JvmBackendExtension {
|
||||
override fun createSerializer(
|
||||
context: JvmBackendContext,
|
||||
klass: IrClass,
|
||||
type: Type,
|
||||
bindings: JvmSerializationBindings,
|
||||
parentSerializer: MetadataSerializer?
|
||||
): MetadataSerializer {
|
||||
return FirMetadataSerializer(session, context, klass, bindings, parentSerializer)
|
||||
}
|
||||
|
||||
override fun generateMetadataExtraFlags(abiStability: JvmAbiStability?): Int =
|
||||
JvmAnnotationNames.METADATA_JVM_IR_FLAG or
|
||||
JvmAnnotationNames.METADATA_FIR_FLAG or
|
||||
(if (abiStability == JvmAbiStability.STABLE) JvmAnnotationNames.METADATA_JVM_IR_STABLE_ABI_FLAG else 0)
|
||||
}
|
||||
@@ -338,7 +338,8 @@ internal fun IrDeclarationParent.declareThisReceiverParameter(
|
||||
symbolTable.irFactory.createValueParameter(
|
||||
startOffset, endOffset, thisOrigin, symbol,
|
||||
Name.special("<this>"), UNDEFINED_PARAMETER_INDEX, thisType,
|
||||
varargElementType = null, isCrossinline = false, isNoinline = false, isAssignable = false
|
||||
varargElementType = null, isCrossinline = false, isNoinline = false,
|
||||
isHidden = false, isAssignable = false
|
||||
).apply {
|
||||
this.parent = this@declareThisReceiverParameter
|
||||
receiverDescriptor.bind(this)
|
||||
|
||||
@@ -269,7 +269,8 @@ class Fir2IrDeclarationStorage(
|
||||
startOffset, endOffset, IrDeclarationOrigin.DEFINED, symbol,
|
||||
Name.special("<set-?>"), 0, type,
|
||||
varargElementType = null,
|
||||
isCrossinline = false, isNoinline = false, isAssignable = false
|
||||
isCrossinline = false, isNoinline = false,
|
||||
isHidden = false, isAssignable = false
|
||||
).apply {
|
||||
this.parent = parent
|
||||
descriptor.bind(this)
|
||||
@@ -899,7 +900,8 @@ class Fir2IrDeclarationStorage(
|
||||
valueParameter.name, index, type,
|
||||
if (!valueParameter.isVararg) null
|
||||
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext),
|
||||
valueParameter.isCrossinline, valueParameter.isNoinline
|
||||
isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline,
|
||||
isHidden = false, isAssignable = false
|
||||
).apply {
|
||||
descriptor.bind(this)
|
||||
if (valueParameter.defaultValue.let {
|
||||
|
||||
@@ -266,6 +266,7 @@ internal class AdapterGenerator(
|
||||
varargElementType = null,
|
||||
isCrossinline = false,
|
||||
isNoinline = false,
|
||||
isHidden = false,
|
||||
isAssignable = false
|
||||
).also { irAdapterValueParameter ->
|
||||
descriptor.bind(irAdapterValueParameter)
|
||||
|
||||
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeStarProjection
|
||||
@@ -37,7 +35,6 @@ import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
/**
|
||||
@@ -84,11 +81,11 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
override fun getBackingField(parameter: ValueParameterDescriptor?, irValueParameter: IrValueParameter?): IrField? =
|
||||
override fun getProperty(parameter: ValueParameterDescriptor?, irValueParameter: IrValueParameter?): IrProperty? =
|
||||
irValueParameter?.let {
|
||||
irClass.properties.single { irProperty ->
|
||||
irProperty.name == irValueParameter.name && irProperty.backingField?.type == irValueParameter.type
|
||||
}.backingField
|
||||
}
|
||||
}
|
||||
|
||||
override fun transform(typeParameterDescriptor: TypeParameterDescriptor): IrType {
|
||||
@@ -216,8 +213,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
fun generateComponentBody(irFunction: IrFunction) {
|
||||
val index = getComponentIndex(irFunction)!!
|
||||
val valueParameter = irClass.primaryConstructor!!.valueParameters[index - 1]
|
||||
val backingField = irDataClassMembersGenerator.getBackingField(null, valueParameter)!!
|
||||
irDataClassMembersGenerator.generateComponentFunction(irFunction, backingField)
|
||||
val irProperty = irDataClassMembersGenerator.getProperty(null, valueParameter)!!
|
||||
irDataClassMembersGenerator.generateComponentFunction(irFunction, irProperty)
|
||||
}
|
||||
|
||||
fun generateCopyBody(irFunction: IrFunction) =
|
||||
@@ -295,7 +292,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
) { symbol ->
|
||||
components.irFactory.createValueParameter(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, symbol, name, index, type, null,
|
||||
isCrossinline = false, isNoinline = false, isAssignable = false
|
||||
isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
|
||||
)
|
||||
}.apply {
|
||||
parent = irFunction
|
||||
|
||||
@@ -148,11 +148,21 @@ public class FirCompileKotlinAgainstKotlinTestGenerated extends AbstractFirCompi
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassFakeOverrideMangling.kt")
|
||||
public void testInlineClassFakeOverrideMangling() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/inlineClassFakeOverrideMangling.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassFromBinaryDependencies.kt")
|
||||
public void testInlineClassFromBinaryDependencies() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/inlineClassFromBinaryDependencies.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassInlineFunctionCall.kt")
|
||||
public void testInlineClassInlineFunctionCall() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/inlineClassInlineFunctionCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassInlineProperty.kt")
|
||||
public void testInlineClassInlineProperty() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/inlineClassInlineProperty.kt");
|
||||
|
||||
@@ -1731,49 +1731,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/builderInference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class BuilderInference extends AbstractFirBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuilderInference() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lackOfNullCheckOnNullableInsideBuild.kt")
|
||||
public void testLackOfNullCheckOnNullableInsideBuild() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteStubTypeIntoCR.kt")
|
||||
public void testSubstituteStubTypeIntoCR() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/substituteStubTypeIntoCR.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteStubTypeIntolambdaParameterDescriptor.kt")
|
||||
public void testSubstituteStubTypeIntolambdaParameterDescriptor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/substituteStubTypeIntolambdaParameterDescriptor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteTypeVariableIntolambdaParameterDescriptor.kt")
|
||||
public void testSubstituteTypeVariableIntolambdaParameterDescriptor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/substituteTypeVariableIntolambdaParameterDescriptor.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/builtinStubMethods")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -3840,6 +3797,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/classes/exceptionConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunWithDefaultParam.kt")
|
||||
public void testExtensionFunWithDefaultParam() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/classes/extensionFunWithDefaultParam.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionOnNamedClassObject.kt")
|
||||
public void testExtensionOnNamedClassObject() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/classes/extensionOnNamedClassObject.kt");
|
||||
@@ -5018,6 +4980,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/collections/inheritFromHashtable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("internalRemove.kt")
|
||||
public void testInternalRemove() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/collections/internalRemove.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("internalRemoveFromJava.kt")
|
||||
public void testInternalRemoveFromJava() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/collections/internalRemoveFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("irrelevantImplCharSequence.kt")
|
||||
public void testIrrelevantImplCharSequence() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/collections/irrelevantImplCharSequence.kt");
|
||||
@@ -7341,6 +7313,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultExpect.kt")
|
||||
public void testDefaultExpect() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegate.kt")
|
||||
public void testDelegate_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");
|
||||
@@ -9838,6 +9815,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/covariantOverrideGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultLambdaInline.kt")
|
||||
public void testDefaultLambdaInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/defaultLambdaInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionManyArgs.kt")
|
||||
public void testExtensionFunctionManyArgs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/function/extensionFunctionManyArgs.kt");
|
||||
@@ -11140,6 +11122,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/enum/classForEnumEntry.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("companionAccessingEnumValue.kt")
|
||||
public void testCompanionAccessingEnumValue() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/companionAccessingEnumValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectInEnum.kt")
|
||||
public void testCompanionObjectInEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/companionObjectInEnum.kt");
|
||||
@@ -12572,6 +12559,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/functions/bigArity/javaLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedBigArityFunCalls.kt")
|
||||
public void testNestedBigArityFunCalls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/bigArity/nestedBigArityFunCalls.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subclass.kt")
|
||||
public void testSubclass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/bigArity/subclass.kt");
|
||||
@@ -13349,6 +13341,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inference/capturedStarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypesSubstitutionIntoAbbreviation.kt")
|
||||
public void testCapturedTypesSubstitutionIntoAbbreviation() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/capturedTypesSubstitutionIntoAbbreviation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("coercionToUnitForLambdaReturnTypeWithFlexibleConstraint.kt")
|
||||
public void testCoercionToUnitForLambdaReturnTypeWithFlexibleConstraint() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/coercionToUnitForLambdaReturnTypeWithFlexibleConstraint.kt");
|
||||
@@ -13469,6 +13466,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferences.kt")
|
||||
public void testSpecialCallsWithCallableReferences() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subtypingOfIntersectionIltInsideFlexible.kt")
|
||||
public void testSubtypingOfIntersectionIltInsideFlexible() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/subtypingOfIntersectionIltInsideFlexible.kt");
|
||||
@@ -13483,6 +13485,74 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testUnsafeVarianceCodegen() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inference/builderInference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class BuilderInference extends AbstractFirBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBuilderInference() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt41164.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lackOfNullCheckOnNullableInsideBuild.kt")
|
||||
public void testLackOfNullCheckOnNullableInsideBuild() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferences.kt")
|
||||
public void testSpecialCallsWithCallableReferences() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/specialCallsWithCallableReferences.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesDontCareTypeInBlockExpression.kt")
|
||||
public void testSpecialCallsWithCallableReferencesDontCareTypeInBlockExpression() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesErrorType.kt")
|
||||
public void testSpecialCallsWithCallableReferencesErrorType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/specialCallsWithCallableReferencesErrorType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithCallableReferencesNonStrictOnlyInputTypes.kt")
|
||||
public void testSpecialCallsWithCallableReferencesNonStrictOnlyInputTypes() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/specialCallsWithCallableReferencesNonStrictOnlyInputTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("specialCallsWithLambdas.kt")
|
||||
public void testSpecialCallsWithLambdas() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/specialCallsWithLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteStubTypeIntoCR.kt")
|
||||
public void testSubstituteStubTypeIntoCR() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/substituteStubTypeIntoCR.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteStubTypeIntolambdaParameterDescriptor.kt")
|
||||
public void testSubstituteStubTypeIntolambdaParameterDescriptor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/substituteStubTypeIntolambdaParameterDescriptor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("substituteTypeVariableIntolambdaParameterDescriptor.kt")
|
||||
public void testSubstituteTypeVariableIntolambdaParameterDescriptor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inference/builderInference/substituteTypeVariableIntolambdaParameterDescriptor.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses")
|
||||
@@ -14142,6 +14212,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/multifileClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedInlineClass.kt")
|
||||
public void testNestedInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/nestedInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noAssertionsOnInlineClassBasedOnNullableType.kt")
|
||||
public void testNoAssertionsOnInlineClassBasedOnNullableType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/noAssertionsOnInlineClassBasedOnNullableType.kt");
|
||||
@@ -15154,6 +15229,59 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jvm8DefaultInterfaceMethods extends AbstractFirBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJvm8DefaultInterfaceMethods() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("javaDefaultMethod.kt")
|
||||
public void testJavaDefaultMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/javaDefaultMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaDefaultMethodOverriddenByKotlin.kt")
|
||||
public void testJavaDefaultMethodOverriddenByKotlin() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/javaDefaultMethodOverriddenByKotlin.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultAll.kt")
|
||||
public void testJvmDefaultAll() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultAll.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultAllPrimaryProperty.kt")
|
||||
public void testJvmDefaultAllPrimaryProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultAllPrimaryProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultAllProperty.kt")
|
||||
public void testJvmDefaultAllProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultAllProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultEnable.kt")
|
||||
public void testJvmDefaultEnable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultEnable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultEnablePrimaryProperty.kt")
|
||||
public void testJvmDefaultEnablePrimaryProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultEnablePrimaryProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmDefaultEnableProperty.kt")
|
||||
public void testJvmDefaultEnableProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/jvm8DefaultInterfaceMethods/jvmDefaultEnableProperty.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/propertyDelegation")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -17914,6 +18042,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/jvmStatic/kt21246a.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt31389.kt")
|
||||
public void testKt31389() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmStatic/kt31389.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35716.kt")
|
||||
public void testKt35716() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmStatic/kt35716.kt");
|
||||
@@ -21463,6 +21596,31 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/properties/kt9603.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lazyInitialization.kt")
|
||||
public void testLazyInitialization() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lazyInitialization.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lazyInitializationCyclicImports.kt")
|
||||
public void testLazyInitializationCyclicImports() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lazyInitializationCyclicImports.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lazyInitializationMultiModule.kt")
|
||||
public void testLazyInitializationMultiModule() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lazyInitializationMultiModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lazyInitializationOrder.kt")
|
||||
public void testLazyInitializationOrder() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lazyInitializationOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lazyInitializationSplitPerModule.kt")
|
||||
public void testLazyInitializationSplitPerModule() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lazyInitializationSplitPerModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveOverrideDefaultAccessor.kt")
|
||||
public void testPrimitiveOverrideDefaultAccessor() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDefaultAccessor.kt");
|
||||
@@ -30117,6 +30275,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/sealed"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleFiles_enabled.kt")
|
||||
public void testMultipleFiles_enabled() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sealed/multipleFiles_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objects.kt")
|
||||
public void testObjects() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sealed/objects.kt");
|
||||
@@ -32036,6 +32199,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("evaluateConstructorOfUnsignedArrayType.kt")
|
||||
public void testEvaluateConstructorOfUnsignedArrayType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedArrayType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("evaluateConstructorOfUnsignedType.kt")
|
||||
public void testEvaluateConstructorOfUnsignedType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
|
||||
@@ -32215,6 +32383,59 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testWhenByUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/whenByUnsigned.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Jvm8Intrinsics extends AbstractFirBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJvm8Intrinsics() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedIntCompare_jvm8.kt")
|
||||
public void testUnsignedIntCompare_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedIntCompare_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedIntDivide_jvm8.kt")
|
||||
public void testUnsignedIntDivide_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedIntDivide_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedIntRemainder_jvm8.kt")
|
||||
public void testUnsignedIntRemainder_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedIntRemainder_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedIntToString_jvm8.kt")
|
||||
public void testUnsignedIntToString_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedIntToString_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedLongCompare_jvm8.kt")
|
||||
public void testUnsignedLongCompare_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedLongCompare_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedLongDivide_jvm8.kt")
|
||||
public void testUnsignedLongDivide_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedLongDivide_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedLongRemainder_jvm8.kt")
|
||||
public void testUnsignedLongRemainder_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedLongRemainder_jvm8.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedLongToString_jvm8.kt")
|
||||
public void testUnsignedLongToString_jvm8() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/jvm8Intrinsics/unsignedLongToString_jvm8.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/vararg")
|
||||
|
||||
@@ -4210,6 +4210,16 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/properties"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("dataClass.kt")
|
||||
public void testDataClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/properties/dataClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("openDataClass.kt")
|
||||
public void testOpenDataClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/properties/openDataClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeText/properties/lateinit")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -221,6 +221,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
runTest("compiler/testData/ir/irText/classes/objectWithInitializers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("openDataClass.kt")
|
||||
public void testOpenDataClass() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/classes/openDataClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("outerClassAccess.kt")
|
||||
public void testOuterClassAccess() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/classes/outerClassAccess.kt");
|
||||
@@ -2205,6 +2210,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
runTest("compiler/testData/ir/irText/types/starProjection_OI.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasWithUnsafeVariance.kt")
|
||||
public void testTypeAliasWithUnsafeVariance() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/types/typeAliasWithUnsafeVariance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/ir/irText/types/nullChecks")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.frontend.di.configureIncrementalCompilation
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.frontend.di.configureStandardResolveComponents
|
||||
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.java.AbstractJavaClassFinder
|
||||
@@ -41,10 +42,8 @@ import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitsExtensionsResolutionFilter
|
||||
import org.jetbrains.kotlin.resolve.createContainer
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmDiagnosticComponents
|
||||
import org.jetbrains.kotlin.resolve.jvm.multiplatform.OptionalAnnotationPackageFragmentProvider
|
||||
@@ -68,8 +67,12 @@ fun createContainerForLazyResolveWithJava(
|
||||
configureJavaClassFinder: (StorageComponentContainer.() -> Unit)? = null,
|
||||
javaClassTracker: JavaClassesTracker? = null,
|
||||
implicitsResolutionFilter: ImplicitsExtensionsResolutionFilter? = null,
|
||||
sealedInheritorsProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider
|
||||
): StorageComponentContainer = createContainer("LazyResolveWithJava", JvmPlatformAnalyzerServices) {
|
||||
configureModule(moduleContext, jvmPlatform, JvmPlatformAnalyzerServices, bindingTrace, languageVersionSettings)
|
||||
configureModule(
|
||||
moduleContext, jvmPlatform, JvmPlatformAnalyzerServices, bindingTrace, languageVersionSettings,
|
||||
sealedInheritorsProvider
|
||||
)
|
||||
|
||||
configureIncrementalCompilation(lookupTracker, expectActualTracker)
|
||||
configureStandardResolveComponents()
|
||||
@@ -124,7 +127,7 @@ fun StorageComponentContainer.configureJavaSpecificComponents(
|
||||
useInstance(languageVersionSettings.getFlag(JvmAnalysisFlags.javaTypeEnhancementState))
|
||||
|
||||
if (useBuiltInsProvider) {
|
||||
useInstance((moduleContext.module.builtIns as JvmBuiltIns).settings)
|
||||
useInstance((moduleContext.module.builtIns as JvmBuiltIns).customizer)
|
||||
useImpl<JvmBuiltInsPackageFragmentProvider>()
|
||||
}
|
||||
useImpl<OptionalAnnotationPackageFragmentProvider>()
|
||||
@@ -134,6 +137,7 @@ fun StorageComponentContainer.configureJavaSpecificComponents(
|
||||
JavaResolverSettings.create(
|
||||
isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines),
|
||||
correctNullabilityForNotNullTypeParameter = languageVersionSettings.supportsFeature(LanguageFeature.ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated),
|
||||
typeEnhancementImprovements = languageVersionSettings.supportsFeature(LanguageFeature.ImprovementsAroundTypeEnhancement)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -23,19 +23,18 @@ import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMember
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaMethodImpl
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
|
||||
class LazyResolveBasedCache(resolveSession: ResolveSession) : AbstractJavaResolverCache(resolveSession) {
|
||||
|
||||
override fun recordMethod(method: JavaMethod, descriptor: SimpleFunctionDescriptor) {
|
||||
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, (method as? JavaMethodImpl)?.psi ?: return, descriptor)
|
||||
override fun recordMethod(member: JavaMember, descriptor: SimpleFunctionDescriptor) {
|
||||
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, (member as? JavaElementImpl<*>)?.psi ?: return, descriptor)
|
||||
}
|
||||
|
||||
override fun recordConstructor(element: JavaElement, descriptor: ConstructorDescriptor) {
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
@NotNull Kind kind,
|
||||
@NotNull JavaMethodDescriptor declaration
|
||||
) {
|
||||
super(containingDeclaration, original, declaration.getAnnotations(), declaration.getName(), kind, declaration.getSource());
|
||||
super(containingDeclaration, original, declaration.getAnnotations(), declaration.getName(), kind, declaration.getSource(), false);
|
||||
this.declaration = declaration;
|
||||
setParameterNamesStatus(declaration.hasStableParameterNames(), declaration.hasSynthesizedParameterNames());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
val JAVA_LANG_RECORD_FQ_NAME = FqName("java.lang.Record")
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.AdditionalClassPartsProvider
|
||||
import org.jetbrains.kotlin.resolve.FunctionsFromAny
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isJvmRecord
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class JvmAdditionalClassPartsProvider : AdditionalClassPartsProvider {
|
||||
override fun generateAdditionalMethods(
|
||||
thisDescriptor: ClassDescriptor,
|
||||
result: MutableCollection<SimpleFunctionDescriptor>,
|
||||
name: Name,
|
||||
location: LookupLocation,
|
||||
fromSupertypes: Collection<SimpleFunctionDescriptor>
|
||||
) {
|
||||
if (thisDescriptor.isJvmRecord()) {
|
||||
FunctionsFromAny.addFunctionFromAnyIfNeeded(thisDescriptor, result, name, fromSupertypes)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAdditionalSupertypes(
|
||||
thisDescriptor: ClassDescriptor,
|
||||
existingSupertypes: List<KotlinType>
|
||||
): List<KotlinType> {
|
||||
if (thisDescriptor.isJvmRecord() && existingSupertypes.none(::isJavaLangRecordType)) {
|
||||
thisDescriptor.module.resolveTopLevelClass(JAVA_LANG_RECORD_FQ_NAME, NoLookupLocation.FOR_DEFAULT_IMPORTS)?.defaultType?.let {
|
||||
return listOf(it)
|
||||
}
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isJavaLangRecordType(it: KotlinType) =
|
||||
KotlinBuiltIns.isConstructedFromGivenClass(it, JAVA_LANG_RECORD_FQ_NAME)
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.SealedClassInheritorsProvider
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
@@ -54,7 +55,8 @@ class JvmResolverForModuleFactory(
|
||||
moduleContext: ModuleContext,
|
||||
moduleContent: ModuleContent<M>,
|
||||
resolverForProject: ResolverForProject<M>,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sealedInheritorsProvider: SealedClassInheritorsProvider
|
||||
): ResolverForModule {
|
||||
val (moduleInfo, syntheticFiles, moduleContentScope) = moduleContent
|
||||
val project = moduleContext.project
|
||||
@@ -108,6 +110,7 @@ class JvmResolverForModuleFactory(
|
||||
ExpectActualTracker.DoNothing,
|
||||
packagePartProvider,
|
||||
languageVersionSettings,
|
||||
sealedInheritorsProvider = sealedInheritorsProvider,
|
||||
useBuiltInsProvider = false // TODO: load built-ins from module dependencies in IDE
|
||||
)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ val JVM_OVERLOADS_FQ_NAME = FqName("kotlin.jvm.JvmOverloads")
|
||||
|
||||
@JvmField
|
||||
val JVM_SYNTHETIC_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmSynthetic")
|
||||
val JVM_RECORD_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmRecord")
|
||||
|
||||
@JvmField
|
||||
val SYNCHRONIZED_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.Synchronized")
|
||||
@@ -92,3 +93,5 @@ fun DeclarationDescriptor.findStrictfpAnnotation(): AnnotationDescriptor? =
|
||||
|
||||
fun DeclarationDescriptor.findSynchronizedAnnotation(): AnnotationDescriptor? =
|
||||
annotations.findAnnotation(SYNCHRONIZED_ANNOTATION_FQ_NAME)
|
||||
|
||||
fun ClassDescriptor.isJvmRecord(): Boolean = annotations.hasAnnotation(JVM_RECORD_ANNOTATION_FQ_NAME)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getAbbreviatedTypeOrType
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||
|
||||
object ClassInheritsJavaSealedClassChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (descriptor !is ClassDescriptor || declaration !is KtClassOrObject) return
|
||||
for (superTypeListEntry in declaration.superTypeListEntries) {
|
||||
val typeReference = superTypeListEntry.typeReference ?: continue
|
||||
val superType = typeReference.getAbbreviatedTypeOrType(context.trace.bindingContext)?.unwrap() ?: continue
|
||||
val superClass = superType.constructor.declarationDescriptor as? LazyJavaClassDescriptor ?: continue
|
||||
if (superClass.jClass.isSealed) {
|
||||
context.trace.report(Errors.CLASS_INHERITS_JAVA_SEALED_CLASS.on(typeReference))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class InlinePlatformCompatibilityChecker(val jvmTarget: JvmTarget, languageVersi
|
||||
|
||||
val propertyOrFun = DescriptorUtils.getDirectMember(resultingDescriptor)
|
||||
|
||||
val compilingBytecodeVersion = jvmTarget.bytecodeVersion
|
||||
val compilingBytecodeVersion = jvmTarget.majorVersion
|
||||
if (!properError) {
|
||||
val inliningBytecodeVersion = getBytecodeVersionIfDeserializedDescriptor(propertyOrFun, false)
|
||||
if (inliningBytecodeVersion != null && compilingBytecodeVersion < inliningBytecodeVersion) {
|
||||
|
||||
@@ -37,8 +37,11 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.ClassicTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.SenselessComparisonChecker
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
|
||||
class JavaNullabilityChecker : AdditionalTypeChecker {
|
||||
|
||||
@@ -53,7 +56,7 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
|
||||
}
|
||||
|
||||
if (isWrongTypeParameterNullabilityForSubtyping(expressionType, c) { dataFlowValue }) {
|
||||
c.trace.report(ErrorsJvm.NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER.on(expression, c.expectedType, expressionType))
|
||||
c.trace.report(ErrorsJvm.NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER.on(expression, expressionType))
|
||||
}
|
||||
doCheckType(
|
||||
expressionType,
|
||||
@@ -187,8 +190,7 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
|
||||
receiverParameter.type,
|
||||
{ dataFlowValue },
|
||||
c.dataFlowInfo
|
||||
) { expectedType,
|
||||
actualType ->
|
||||
) { expectedType, actualType ->
|
||||
val receiverExpression = (receiverArgument as? ExpressionReceiver)?.expression
|
||||
if (receiverExpression != null) {
|
||||
c.trace.report(ErrorsJvm.RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(receiverExpression, actualType))
|
||||
@@ -202,43 +204,81 @@ class JavaNullabilityChecker : AdditionalTypeChecker {
|
||||
private fun doCheckType(
|
||||
expressionType: KotlinType,
|
||||
expectedType: KotlinType,
|
||||
dataFlowValue: () -> DataFlowValue,
|
||||
expressionTypeDataFlowValue: () -> DataFlowValue,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
reportWarning: (expectedType: KotlinType, actualType: KotlinType) -> Unit
|
||||
) {
|
||||
if (TypeUtils.noExpectedType(expectedType)) {
|
||||
return
|
||||
}
|
||||
if (TypeUtils.noExpectedType(expectedType)) return
|
||||
|
||||
val expectedMustNotBeNull = expectedType.mustNotBeNull() ?: return
|
||||
val actualMayBeNull = expressionType.mayBeNull() ?: return
|
||||
if (expectedMustNotBeNull.isFromKotlin && actualMayBeNull.isFromKotlin) {
|
||||
// a type mismatch error will be reported elsewhere
|
||||
return
|
||||
}
|
||||
val doesExpectedTypeContainsEnhancement = expectedType.contains { it is TypeWithEnhancement }
|
||||
val doesExpressionTypeContainsEnhancement = expressionType.contains { it is TypeWithEnhancement }
|
||||
|
||||
if (dataFlowInfo.getStableNullability(dataFlowValue()) != Nullability.NOT_NULL) {
|
||||
reportWarning(expectedMustNotBeNull.enhancedType, actualMayBeNull.enhancedType)
|
||||
if (!doesExpectedTypeContainsEnhancement && !doesExpressionTypeContainsEnhancement) return
|
||||
|
||||
val enhancedExpectedType = if (doesExpectedTypeContainsEnhancement) buildTypeWithEnhancement(expectedType) else expectedType
|
||||
val enhancedExpressionType = enhanceExpressionTypeByDataFlowNullability(
|
||||
if (doesExpressionTypeContainsEnhancement) buildTypeWithEnhancement(expressionType) else expressionType,
|
||||
expressionTypeDataFlowValue,
|
||||
dataFlowInfo
|
||||
)
|
||||
|
||||
val isEnhancedExpectedTypeSubtypeOfExpressionType =
|
||||
KotlinTypeChecker.DEFAULT.isSubtypeOf(enhancedExpressionType, enhancedExpectedType)
|
||||
|
||||
if (isEnhancedExpectedTypeSubtypeOfExpressionType) return
|
||||
|
||||
val isExpectedTypeSubtypeOfExpressionType = KotlinTypeChecker.DEFAULT.isSubtypeOf(expressionType, expectedType)
|
||||
|
||||
if (!isEnhancedExpectedTypeSubtypeOfExpressionType && isExpectedTypeSubtypeOfExpressionType) {
|
||||
reportWarning(enhancedExpectedType, enhancedExpressionType)
|
||||
}
|
||||
}
|
||||
|
||||
private fun enhanceExpressionTypeByDataFlowNullability(
|
||||
expressionType: KotlinType,
|
||||
expressionTypeDataFlowValue: () -> DataFlowValue,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
): KotlinType {
|
||||
val isNotNullByDataFlowInfo = dataFlowInfo.getStableNullability(expressionTypeDataFlowValue()) == Nullability.NOT_NULL
|
||||
return if (expressionType.isNullable() && isNotNullByDataFlowInfo) expressionType.makeNotNullable() else expressionType
|
||||
}
|
||||
|
||||
private fun <T : Any> doIfNotNull(
|
||||
type: KotlinType,
|
||||
dataFlowValue: () -> DataFlowValue,
|
||||
c: ResolutionContext<*>,
|
||||
body: () -> T
|
||||
) = if (type.mustNotBeNull()?.isFromJava == true &&
|
||||
c.dataFlowInfo.getStableNullability(dataFlowValue()).canBeNull()
|
||||
)
|
||||
) = if (type.mustNotBeNull()?.isFromJava == true && c.dataFlowInfo.getStableNullability(dataFlowValue()).canBeNull()) {
|
||||
body()
|
||||
else
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
private fun KotlinType.mayBeNull(): EnhancedNullabilityInfo? = when {
|
||||
!isError && !isFlexible() && TypeUtils.acceptsNullable(this) -> enhancementFromKotlin()
|
||||
isFlexible() && TypeUtils.acceptsNullable(asFlexibleType().lowerBound) -> enhancementFromKotlin()
|
||||
this is TypeWithEnhancement && enhancement.mayBeNull() != null -> enhancementFromJava()
|
||||
else -> null
|
||||
private fun enhanceTypeArguments(arguments: List<TypeProjection>) =
|
||||
arguments.map { argument ->
|
||||
// TODO: think about star projections with enhancement (e.g. came from Java: Foo<@NotNull ?>)
|
||||
if (argument.isStarProjection) {
|
||||
return@map argument
|
||||
}
|
||||
val argumentType = argument.type
|
||||
val enhancedArgumentType = if (argumentType is TypeWithEnhancement) argumentType.enhancement else argumentType
|
||||
val enhancedDeeplyArgumentType = buildTypeWithEnhancement(enhancedArgumentType)
|
||||
|
||||
argument.replaceType(enhancedDeeplyArgumentType)
|
||||
}
|
||||
|
||||
fun buildTypeWithEnhancement(type: KotlinType): KotlinType {
|
||||
val newArguments = enhanceTypeArguments(type.arguments)
|
||||
val newArgumentsForUpperBound =
|
||||
if (type is FlexibleType) {
|
||||
enhanceTypeArguments(type.upperBound.arguments)
|
||||
} else newArguments
|
||||
val enhancedType = if (type is TypeWithEnhancement) type.enhancement else type
|
||||
|
||||
return enhancedType.replace(
|
||||
newArguments = newArguments,
|
||||
newArgumentsForUpperBound = newArgumentsForUpperBound
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.JAVA_LANG_RECORD_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_RECORD_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isJvmRecord
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class JvmRecordApplicabilityChecker(private val jvmTarget: JvmTarget) : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (descriptor !is ClassDescriptor || declaration !is KtClassOrObject) return
|
||||
|
||||
for (supertypeEntry in declaration.superTypeListEntries) {
|
||||
val supertype = context.trace[BindingContext.TYPE, supertypeEntry.typeReference]
|
||||
if (supertype?.constructor?.declarationDescriptor?.fqNameOrNull() == JAVA_LANG_RECORD_FQ_NAME) {
|
||||
context.trace.report(ErrorsJvm.ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE.on(supertypeEntry))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (!descriptor.isJvmRecord()) return
|
||||
|
||||
val reportOn =
|
||||
declaration.annotationEntries.firstOrNull { it.shortName == JVM_RECORD_ANNOTATION_FQ_NAME.shortName() }
|
||||
?: declaration
|
||||
|
||||
if (context.moduleDescriptor.resolveTopLevelClass(JAVA_LANG_RECORD_FQ_NAME, NoLookupLocation.FOR_DEFAULT_IMPORTS) == null) {
|
||||
context.trace.report(ErrorsJvm.JVM_RECORD_REQUIRES_JDK15.on(reportOn))
|
||||
return
|
||||
}
|
||||
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.JvmRecordSupport)) {
|
||||
context.trace.report(
|
||||
Errors.UNSUPPORTED_FEATURE.on(
|
||||
reportOn,
|
||||
LanguageFeature.JvmRecordSupport to context.languageVersionSettings
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (!jvmTarget.areRecordsAllowed(context.languageVersionSettings.getFlag(JvmAnalysisFlags.enableJvmPreview))) {
|
||||
context.trace.report(
|
||||
ErrorsJvm.JVM_RECORDS_ILLEGAL_BYTECODE_TARGET.on(reportOn)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (descriptor.kind == ClassKind.ENUM_CLASS) {
|
||||
val modifierOrName =
|
||||
declaration.modifierList?.getModifier(KtTokens.ENUM_KEYWORD)
|
||||
?: declaration.nameIdentifier
|
||||
?: declaration
|
||||
|
||||
context.trace.report(ErrorsJvm.ENUM_JVM_RECORD.on(modifierOrName))
|
||||
return
|
||||
}
|
||||
|
||||
if (!descriptor.isFinalClass) {
|
||||
val modifierOrName =
|
||||
declaration.modifierList?.findOneOfModifiers(KtTokens.ABSTRACT_KEYWORD, KtTokens.OPEN_KEYWORD, KtTokens.SEALED_KEYWORD)
|
||||
?: declaration.nameIdentifier
|
||||
?: declaration
|
||||
|
||||
context.trace.report(ErrorsJvm.NON_FINAL_JVM_RECORD.on(modifierOrName))
|
||||
return
|
||||
}
|
||||
|
||||
if (descriptor.isInner) {
|
||||
val modifierOrName =
|
||||
declaration.modifierList?.getModifier(KtTokens.INNER_KEYWORD)
|
||||
?: declaration.nameIdentifier
|
||||
?: declaration
|
||||
|
||||
context.trace.report(ErrorsJvm.INNER_JVM_RECORD.on(modifierOrName))
|
||||
return
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isLocal(descriptor)) {
|
||||
context.trace.report(ErrorsJvm.LOCAL_JVM_RECORD.on(reportOn))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
for (member in declaration.declarations) {
|
||||
if (member !is KtProperty) continue
|
||||
|
||||
val propertyDescriptor = context.trace[BindingContext.DECLARATION_TO_DESCRIPTOR, member] as? PropertyDescriptor ?: continue
|
||||
if (context.trace.bindingContext[BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor] != true && member.delegate == null) continue
|
||||
|
||||
context.trace.report(ErrorsJvm.FIELD_IN_JVM_RECORD.on(member))
|
||||
return
|
||||
}
|
||||
|
||||
for (superTypeEntry in declaration.superTypeListEntries) {
|
||||
if (superTypeEntry !is KtDelegatedSuperTypeEntry) continue
|
||||
|
||||
context.trace.report(ErrorsJvm.DELEGATION_BY_IN_JVM_RECORD.on(superTypeEntry))
|
||||
return
|
||||
}
|
||||
|
||||
for (supertype in descriptor.typeConstructor.supertypes) {
|
||||
val classDescriptor = supertype.constructor.declarationDescriptor as? ClassDescriptor ?: continue
|
||||
if (classDescriptor.kind == ClassKind.INTERFACE || classDescriptor.fqNameSafe == JAVA_LANG_RECORD_FQ_NAME) continue
|
||||
|
||||
val reportSupertypeOn = declaration.nameIdentifier ?: declaration
|
||||
context.trace.report(ErrorsJvm.JVM_RECORD_EXTENDS_CLASS.on(reportSupertypeOn, supertype))
|
||||
return
|
||||
}
|
||||
|
||||
if (!descriptor.isData) {
|
||||
context.trace.report(ErrorsJvm.NON_DATA_CLASS_JVM_RECORD.on(reportOn))
|
||||
return
|
||||
}
|
||||
|
||||
val primaryConstructor = declaration.primaryConstructor
|
||||
val parameters = primaryConstructor?.valueParameters ?: emptyList()
|
||||
if (parameters.isEmpty()) {
|
||||
(primaryConstructor?.valueParameterList ?: declaration.nameIdentifier)?.let {
|
||||
context.trace.report(ErrorsJvm.JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS.on(it))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for (parameter in parameters) {
|
||||
if (!parameter.hasValOrVar() || parameter.isMutable) {
|
||||
context.trace.report(ErrorsJvm.JVM_RECORD_NOT_VAL_PARAMETER.on(parameter))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for (parameter in parameters.dropLast(1)) {
|
||||
if (parameter.isVarArg) {
|
||||
context.trace.report(ErrorsJvm.JVM_RECORD_NOT_LAST_VARARG_PARAMETER.on(parameter))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtModifierList.findOneOfModifiers(vararg modifierTokens: KtModifierKeywordToken): PsiElement? =
|
||||
modifierTokens.firstNotNullResult(this::getModifier)
|
||||
|
||||
private fun JvmTarget.areRecordsAllowed(enableJvmPreview: Boolean): Boolean {
|
||||
if (majorVersion < JvmTarget.JVM_15.majorVersion) return false
|
||||
return enableJvmPreview || majorVersion > JvmTarget.JVM_15.majorVersion
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.JVM_STATIC_IN_PRIVATE_COMPANION
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class JvmStaticInPrivateCompanionChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
|
||||
if (containingDeclaration !is ClassDescriptor
|
||||
|| !containingDeclaration.isCompanionObject
|
||||
|| !Visibilities.isPrivate(containingDeclaration.visibility.delegate)
|
||||
) return
|
||||
|
||||
val jvmStaticAnnotation = descriptor.annotations.findAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) ?: return
|
||||
|
||||
val reportTarget = jvmStaticAnnotation.source.safeAs<KotlinSourceElement>()?.psi ?: return
|
||||
context.trace.report(JVM_STATIC_IN_PRIVATE_COMPANION.on(reportTarget))
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class LocalFunInlineChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
class JvmStaticChecker(jvmTarget: JvmTarget, languageVersionSettings: LanguageVersionSettings) : DeclarationChecker {
|
||||
private val isLessJVM18 = jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion
|
||||
private val isLessJVM18 = jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion
|
||||
|
||||
private val supportJvmStaticInInterface = languageVersionSettings.supportsFeature(LanguageFeature.JvmStaticInInterface)
|
||||
|
||||
|
||||
@@ -86,8 +86,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
|
||||
MAP.put(NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER,
|
||||
"Type mismatch: type parameter with nullable bounds is used {1} is used where {0} was expected. This warning will become an error soon",
|
||||
RENDER_TYPE, RENDER_TYPE
|
||||
"Type mismatch: value of a nullable type {0} is used where non-nullable type is expected. " +
|
||||
"This warning will become an error soon. " +
|
||||
"See https://youtrack.jetbrains.com/issue/KT-36770 for details",
|
||||
RENDER_TYPE
|
||||
);
|
||||
MAP.put(RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS,
|
||||
"Unsafe use of a nullable receiver of type {0}", RENDER_TYPE);
|
||||
@@ -152,6 +154,21 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
MAP.put(SUSPENSION_POINT_INSIDE_MONITOR, "A suspension point at {0} is inside a critical section", STRING);
|
||||
MAP.put(SUSPENSION_POINT_INSIDE_CRITICAL_SECTION, "The ''{0}'' suspension point is inside a critical section", NAME);
|
||||
|
||||
MAP.put(LOCAL_JVM_RECORD, "Local @JvmRecord classes are not allowed");
|
||||
MAP.put(NON_FINAL_JVM_RECORD, "@JvmRecord class should be final");
|
||||
MAP.put(ENUM_JVM_RECORD, "@JvmRecord class should not be an enum");
|
||||
MAP.put(JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS, "Primary constructor with parameters is required for @JvmRecord class");
|
||||
MAP.put(JVM_RECORD_NOT_VAL_PARAMETER, "Constructor parameter of @JvmRecord class should be a val");
|
||||
MAP.put(JVM_RECORD_NOT_LAST_VARARG_PARAMETER, "Only the last constructor parameter of @JvmRecord may be a vararg");
|
||||
MAP.put(JVM_RECORD_EXTENDS_CLASS, "Record cannot inherit a class" , RENDER_TYPE);
|
||||
MAP.put(JVM_RECORD_REQUIRES_JDK15, "Using @JvmRecords requires at least JDK 15");
|
||||
MAP.put(INNER_JVM_RECORD, "@JvmRecord class should not be inner");
|
||||
MAP.put(FIELD_IN_JVM_RECORD, "It's not allowed to have non-constructor properties with backing filed in @JvmRecord class");
|
||||
MAP.put(DELEGATION_BY_IN_JVM_RECORD, "Delegation is not allowed for @JvmRecord classes");
|
||||
MAP.put(NON_DATA_CLASS_JVM_RECORD, "Only data classes are allowed to be marked as @JvmRecord");
|
||||
MAP.put(ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE, "Classes cannot have explicit 'java.lang.Record' supertype");
|
||||
MAP.put(JVM_RECORDS_ILLEGAL_BYTECODE_TARGET, "Using @JvmRecord is only allowed with -jvm-target 15 and -Xjvm-enable-preview flag enabled");
|
||||
|
||||
String MESSAGE_FOR_CONCURRENT_HASH_MAP_CONTAINS =
|
||||
"Method 'contains' from ConcurrentHashMap may have unexpected semantics: it calls 'containsValue' instead of 'containsKey'. " +
|
||||
"Use explicit form of the call to 'containsKey'/'containsValue'/'contains' or cast the value to kotlin.collections.Map instead. " +
|
||||
|
||||
@@ -115,6 +115,21 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory0<KtDeclaration> JVM_DEFAULT_THROUGH_INHERITANCE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<PsiElement> USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> LOCAL_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> NON_FINAL_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ENUM_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_RECORD_NOT_VAL_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_RECORD_NOT_LAST_VARARG_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> JVM_RECORD_EXTENDS_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_RECORD_REQUIRES_JDK15 = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INNER_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> FIELD_IN_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> DELEGATION_BY_IN_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> NON_DATA_CLASS_JVM_RECORD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_RECORDS_ILLEGAL_BYTECODE_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtDeclaration> NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<KtAnnotationEntry> EXPLICIT_METADATA_IS_DISALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
@@ -122,8 +137,8 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
|
||||
= DiagnosticFactory2.create(WARNING);
|
||||
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER
|
||||
= DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory1<KtElement, KotlinType> NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER
|
||||
= DiagnosticFactory1.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtElement, KotlinType> RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
|
||||
= DiagnosticFactory1.create(WARNING);
|
||||
|
||||
@@ -88,7 +88,8 @@ public class SignaturesPropagationData {
|
||||
Annotations.Companion.getEMPTY(),
|
||||
method.getName(),
|
||||
//TODO: what to do?
|
||||
SourceElement.NO_SOURCE
|
||||
SourceElement.NO_SOURCE,
|
||||
false
|
||||
);
|
||||
autoMethodDescriptor.initialize(
|
||||
null,
|
||||
|
||||
@@ -42,6 +42,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
||||
SynchronizedOnInlineMethodChecker,
|
||||
DefaultCheckerInTailrec,
|
||||
FunctionDelegateMemberNameClashChecker,
|
||||
ClassInheritsJavaSealedClassChecker
|
||||
),
|
||||
|
||||
additionalCallCheckers = listOf(
|
||||
@@ -96,7 +97,6 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useImpl<JvmStaticChecker>()
|
||||
container.useImpl<JvmStaticInPrivateCompanionChecker>()
|
||||
container.useImpl<JvmReflectionAPICallChecker>()
|
||||
container.useImpl<JavaSyntheticScopes>()
|
||||
container.useImpl<SamConversionResolverImpl>()
|
||||
@@ -109,6 +109,8 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
||||
container.useImpl<JvmPlatformOverloadsSpecificityComparator>()
|
||||
container.useImpl<JvmDefaultSuperCallChecker>()
|
||||
container.useImpl<JvmSamConversionOracle>()
|
||||
container.useImpl<JvmAdditionalClassPartsProvider>()
|
||||
container.useImpl<JvmRecordApplicabilityChecker>()
|
||||
container.useInstance(FunctionWithBigAritySupport.LanguageVersionDependent)
|
||||
container.useInstance(GenericArrayClassLiteralSupport.Enabled)
|
||||
container.useInstance(JavaActualAnnotationArgumentExtractor())
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -92,7 +94,11 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor, SyntheticPropert
|
||||
}
|
||||
}
|
||||
|
||||
class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope.Default() {
|
||||
class JavaSyntheticPropertiesScope(
|
||||
storageManager: StorageManager,
|
||||
private val lookupTracker: LookupTracker,
|
||||
private val supportJavaRecords: Boolean,
|
||||
) : SyntheticScope.Default() {
|
||||
private val syntheticPropertyInClass =
|
||||
storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
|
||||
syntheticPropertyInClassNotCached(pair.first, pair.second)
|
||||
@@ -113,20 +119,37 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
}
|
||||
|
||||
private fun syntheticPropertyInClassNotCached(ownerClass: ClassDescriptor, name: Name): SyntheticPropertyHolder {
|
||||
val forBean = syntheticPropertyHolderForBeanConvention(name, ownerClass)
|
||||
if (forBean.descriptor != null) return forBean
|
||||
|
||||
fun result(descriptor: PropertyDescriptor?, getterNames: List<Name>, setterName: Name? = null): SyntheticPropertyHolder {
|
||||
if (lookupTracker === LookupTracker.DO_NOTHING) {
|
||||
return if (descriptor == null) SyntheticPropertyHolder.EMPTY else SyntheticPropertyHolder(descriptor, emptyList())
|
||||
}
|
||||
if (!ownerClass.isRecord()) return forBean
|
||||
|
||||
val names = ArrayList<Name>(getterNames.size + (setterName?.let { 1 } ?: 0))
|
||||
val propertyForComponent = syntheticPropertyDescriptorForRecordComponent(name, ownerClass)
|
||||
|
||||
names.addAll(getterNames)
|
||||
names.addIfNotNull(setterName)
|
||||
return createSyntheticPropertyHolder(propertyForComponent, forBean.lookedNames, name)
|
||||
}
|
||||
|
||||
return SyntheticPropertyHolder(descriptor, names)
|
||||
private fun createSyntheticPropertyHolder(
|
||||
descriptor: PropertyDescriptor?,
|
||||
lookedNames: List<Name>,
|
||||
additionalName: Name? = null
|
||||
): SyntheticPropertyHolder {
|
||||
if (lookupTracker === LookupTracker.DO_NOTHING) {
|
||||
return if (descriptor == null) SyntheticPropertyHolder.EMPTY else SyntheticPropertyHolder(descriptor, emptyList())
|
||||
}
|
||||
|
||||
val names = ArrayList<Name>(lookedNames.size + (additionalName?.let { 1 } ?: 0))
|
||||
|
||||
names.addAll(lookedNames)
|
||||
names.addIfNotNull(additionalName)
|
||||
|
||||
return SyntheticPropertyHolder(descriptor, names)
|
||||
}
|
||||
|
||||
private fun syntheticPropertyHolderForBeanConvention(
|
||||
name: Name,
|
||||
ownerClass: ClassDescriptor
|
||||
): SyntheticPropertyHolder {
|
||||
if (name.isSpecial) return SyntheticPropertyHolder.EMPTY
|
||||
|
||||
val identifier = name.identifier
|
||||
@@ -142,7 +165,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
.flatMap { memberScope.getContributedFunctions(it, NoLookupLocation.FROM_SYNTHETIC_SCOPE) }
|
||||
.singleOrNull {
|
||||
it.hasJavaOriginInHierarchy() && isGoodGetMethod(it)
|
||||
} ?: return result(null, possibleGetMethodNames)
|
||||
} ?: return createSyntheticPropertyHolder(null, possibleGetMethodNames)
|
||||
|
||||
|
||||
val setMethodName = setMethodName(getMethod.name)
|
||||
@@ -152,7 +175,27 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
val propertyType = getMethod.returnType!!
|
||||
|
||||
val descriptor = MyPropertyDescriptor.create(ownerClass, getMethod.original, setMethod?.original, name, propertyType)
|
||||
return result(descriptor, possibleGetMethodNames, setMethodName)
|
||||
return createSyntheticPropertyHolder(descriptor, possibleGetMethodNames, setMethodName)
|
||||
}
|
||||
|
||||
private fun syntheticPropertyDescriptorForRecordComponent(
|
||||
name: Name,
|
||||
ownerClass: ClassDescriptor
|
||||
): PropertyDescriptor? {
|
||||
if (!supportJavaRecords) return null
|
||||
|
||||
val componentLikeMethod =
|
||||
ownerClass.unsubstitutedMemberScope
|
||||
.getContributedFunctions(name, NoLookupLocation.FROM_SYNTHETIC_SCOPE)
|
||||
.singleOrNull(this::isGoodGetMethod) ?: return null
|
||||
|
||||
if (componentLikeMethod !is JavaMethodDescriptor || !componentLikeMethod.isForRecordComponent) {
|
||||
return null
|
||||
}
|
||||
|
||||
val propertyType = componentLikeMethod.returnType!!
|
||||
|
||||
return MyPropertyDescriptor.create(ownerClass, componentLikeMethod.original, null, name, propertyType)
|
||||
}
|
||||
|
||||
private fun isGoodGetMethod(descriptor: FunctionDescriptor): Boolean {
|
||||
@@ -249,8 +292,14 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
if (classifier is ClassDescriptor) {
|
||||
for (descriptor in classifier.unsubstitutedMemberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)) {
|
||||
if (descriptor is FunctionDescriptor) {
|
||||
val propertyName = SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue
|
||||
addIfNotNull(syntheticPropertyInClass(Pair(classifier, propertyName)).descriptor)
|
||||
val propertyName = SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName())
|
||||
if (propertyName != null) {
|
||||
addIfNotNull(syntheticPropertyInClass(Pair(classifier, propertyName)).descriptor)
|
||||
}
|
||||
|
||||
if (classifier.isRecord()) {
|
||||
addIfNotNull(syntheticPropertyInClass(Pair(classifier, descriptor.name)).descriptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -258,6 +307,9 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassifierDescriptor.isRecord() =
|
||||
this is JavaClassDescriptor && isRecord
|
||||
|
||||
private fun SmartList<PropertyDescriptor>?.add(property: PropertyDescriptor?): SmartList<PropertyDescriptor>? {
|
||||
if (property == null) return this
|
||||
val list = if (this != null) this else SmartList()
|
||||
@@ -280,15 +332,15 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
}
|
||||
|
||||
private class MyPropertyDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
original: PropertyDescriptor?,
|
||||
annotations: Annotations,
|
||||
modality: Modality,
|
||||
visibility: DescriptorVisibility,
|
||||
isVar: Boolean,
|
||||
name: Name,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
source: SourceElement
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
original: PropertyDescriptor?,
|
||||
annotations: Annotations,
|
||||
modality: Modality,
|
||||
visibility: DescriptorVisibility,
|
||||
isVar: Boolean,
|
||||
name: Name,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
source: SourceElement
|
||||
) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(
|
||||
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
|
||||
/* lateInit = */ false, /* isConst = */ false, /* isExpect = */ false, /* isActual = */ false, /* isExternal = */ false,
|
||||
@@ -374,13 +426,13 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
}
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
newModality: Modality,
|
||||
newVisibility: DescriptorVisibility,
|
||||
original: PropertyDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name,
|
||||
source: SourceElement
|
||||
newOwner: DeclarationDescriptor,
|
||||
newModality: Modality,
|
||||
newVisibility: DescriptorVisibility,
|
||||
original: PropertyDescriptor?,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
newName: Name,
|
||||
source: SourceElement
|
||||
): PropertyDescriptorImpl {
|
||||
return MyPropertyDescriptor(newOwner, this, annotations, newModality, newVisibility, isVar, newName, kind, this.source).apply {
|
||||
getMethod = this@MyPropertyDescriptor.getMethod
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionOracle
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.resolve.scopes.synthetic.FunInterfaceConstructorsSyntheticScope
|
||||
@@ -52,7 +52,11 @@ class JavaSyntheticScopes(
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument) &&
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
||||
|
||||
val javaSyntheticPropertiesScope = JavaSyntheticPropertiesScope(storageManager, lookupTracker)
|
||||
val javaSyntheticPropertiesScope =
|
||||
JavaSyntheticPropertiesScope(
|
||||
storageManager, lookupTracker,
|
||||
supportJavaRecords = languageVersionSettings.supportsFeature(LanguageFeature.JvmRecordSupport)
|
||||
)
|
||||
val scopesFromExtensions = SyntheticScopeProviderExtension
|
||||
.getInstances(project)
|
||||
.flatMap { it.getScopes(moduleDescriptor, javaSyntheticPropertiesScope) }
|
||||
@@ -100,4 +104,4 @@ interface SyntheticScopeProviderExtension {
|
||||
)
|
||||
|
||||
fun getScopes(moduleDescriptor: ModuleDescriptor, javaSyntheticPropertiesScope: JavaSyntheticPropertiesScope): List<SyntheticScope>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
|
||||
assert(moduleInfoToResolvableInfo.values.toSet() == modules.toSet())
|
||||
}
|
||||
|
||||
abstract fun sdkDependency(module: M): M?
|
||||
abstract fun sdkDependency(module: M, ownerModuleDescriptor: ModuleDescriptorImpl?): M?
|
||||
abstract fun modulesContent(module: M): ModuleContent<M>
|
||||
abstract fun builtInsForModule(module: M): KotlinBuiltIns
|
||||
abstract fun createResolverForModule(descriptor: ModuleDescriptor, moduleInfo: M): ResolverForModule
|
||||
@@ -68,7 +68,7 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
|
||||
LazyModuleDependencies(
|
||||
projectContext.storageManager,
|
||||
module,
|
||||
sdkDependency(module),
|
||||
sdkDependency(module, moduleDescriptor),
|
||||
this
|
||||
)
|
||||
)
|
||||
|
||||
@@ -72,6 +72,7 @@ open class AnalysisResult protected constructor(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
val additionalJavaRoots: List<File>,
|
||||
val additionalKotlinRoots: List<File>,
|
||||
val additionalClassPathRoots: List<File> = emptyList(),
|
||||
val addToEnvironment: Boolean = true
|
||||
) : AnalysisResult(bindingContext, moduleDescriptor)
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.SealedClassInheritorsProvider
|
||||
import org.jetbrains.kotlin.resolve.CliSealedClassInheritorsProvider
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import java.util.*
|
||||
@@ -119,7 +121,8 @@ abstract class ResolverForModuleFactory {
|
||||
moduleContext: ModuleContext,
|
||||
moduleContent: ModuleContent<M>,
|
||||
resolverForProject: ResolverForProject<M>,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sealedInheritorsProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider
|
||||
): ResolverForModule
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class ResolverForSingleModuleProject<M : ModuleInfo>(
|
||||
EmptyResolverForProject(),
|
||||
PackageOracleFactory.OptimisticFactory
|
||||
) {
|
||||
override fun sdkDependency(module: M): M? = sdkDependency
|
||||
override fun sdkDependency(module: M, ownerModuleDescriptor: ModuleDescriptorImpl?): M? = sdkDependency
|
||||
|
||||
init {
|
||||
knownDependencyModuleDescriptors.forEach { (module, descriptor) ->
|
||||
@@ -61,4 +61,4 @@ class ResolverForSingleModuleProject<M : ModuleInfo>(
|
||||
this,
|
||||
languageVersionSettings
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,8 @@ class CommonResolverForModuleFactory(
|
||||
moduleContext: ModuleContext,
|
||||
moduleContent: ModuleContent<M>,
|
||||
resolverForProject: ResolverForProject<M>,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sealedInheritorsProvider: SealedClassInheritorsProvider
|
||||
): ResolverForModule {
|
||||
val (moduleInfo, syntheticFiles, moduleContentScope) = moduleContent
|
||||
val project = moduleContext.project
|
||||
|
||||
@@ -146,10 +146,23 @@ internal abstract class WhenOnClassExhaustivenessChecker : WhenExhaustivenessChe
|
||||
else -> null
|
||||
}
|
||||
|
||||
protected val ClassDescriptor.deepSealedSubclasses: List<ClassDescriptor>
|
||||
get() = this.sealedSubclasses.flatMap {
|
||||
if (it.modality == Modality.SEALED) it.deepSealedSubclasses
|
||||
else setOf(it)
|
||||
protected val ClassDescriptor.enumEntries: Set<ClassDescriptor>
|
||||
get() = DescriptorUtils.getAllDescriptors(this.unsubstitutedInnerClassesScope)
|
||||
.filter(::isEnumEntry)
|
||||
.filterIsInstance<ClassDescriptor>()
|
||||
.toSet()
|
||||
|
||||
|
||||
protected val ClassDescriptor.deepSealedSubclasses: Set<ClassDescriptor>
|
||||
get() = this.sealedSubclasses.flatMapTo(mutableSetOf()) {
|
||||
it.subclasses
|
||||
}
|
||||
|
||||
private val ClassDescriptor.subclasses: Set<ClassDescriptor>
|
||||
get() = when {
|
||||
this.modality == Modality.SEALED -> this.deepSealedSubclasses
|
||||
this.kind == ClassKind.ENUM_CLASS -> this.enumEntries
|
||||
else -> setOf(this)
|
||||
}
|
||||
|
||||
private val KtWhenCondition.negated
|
||||
@@ -189,9 +202,7 @@ internal abstract class WhenOnClassExhaustivenessChecker : WhenExhaustivenessChe
|
||||
for (condition in whenEntry.conditions) {
|
||||
val negated = condition.negated
|
||||
val checkedDescriptor = condition.getCheckedDescriptor(context) ?: continue
|
||||
val checkedDescriptorSubclasses =
|
||||
if (checkedDescriptor.modality == Modality.SEALED) checkedDescriptor.deepSealedSubclasses
|
||||
else listOf(checkedDescriptor)
|
||||
val checkedDescriptorSubclasses = checkedDescriptor.subclasses
|
||||
|
||||
// Checks are important only for nested subclasses of the sealed class
|
||||
// In additional, check without "is" is important only for objects
|
||||
@@ -220,12 +231,7 @@ private object WhenOnEnumExhaustivenessChecker : WhenOnClassExhaustivenessChecke
|
||||
nullable: Boolean
|
||||
): List<WhenMissingCase> {
|
||||
assert(isEnumClass(subjectDescriptor)) { "isWhenOnEnumExhaustive should be called with an enum class descriptor" }
|
||||
val entryDescriptors =
|
||||
DescriptorUtils.getAllDescriptors(subjectDescriptor!!.unsubstitutedInnerClassesScope)
|
||||
.filter(::isEnumEntry)
|
||||
.filterIsInstance<ClassDescriptor>()
|
||||
.toSet()
|
||||
return getMissingClassCases(expression, entryDescriptors, context) +
|
||||
return getMissingClassCases(expression, subjectDescriptor!!.enumEntries, context) +
|
||||
WhenOnNullableExhaustivenessChecker.getMissingCases(expression, context, nullable)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,11 @@ public abstract class DiagnosticFactoryWithPsiElement<E extends PsiElement, D ex
|
||||
protected boolean isValid(ParametrizedDiagnostic<E> diagnostic) {
|
||||
return positioningStrategy.isValid(diagnostic.getPsiElement());
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodOverloadsMethodOfSuperclass")
|
||||
@Deprecated
|
||||
// ABI-compatibility only (used in Android plugin)
|
||||
public D cast(Diagnostic d) {
|
||||
return super.cast(d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, String> MISSING_IMPORTED_SCRIPT_PSI = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_PROVIDED_PROPERTY_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> IR_COMPILED_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> IR_WITH_UNSTABLE_ABI_COMPILED_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> FIR_COMPILED_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, String, IncompatibleVersionErrorData<?>> INCOMPATIBLE_CLASS = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
|
||||
@@ -285,7 +286,6 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, String> EXPERIMENTAL_UNSIGNED_LITERALS_ERROR = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> NON_PARENTHESIZED_ANNOTATIONS_ON_FUNCTIONAL_TYPES = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JVM_STATIC_IN_PRIVATE_COMPANION = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Const
|
||||
DiagnosticFactory0<PsiElement> CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT = DiagnosticFactory0.create(ERROR);
|
||||
@@ -347,7 +347,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> NON_PRIVATE_CONSTRUCTOR_IN_ENUM = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> NON_PRIVATE_CONSTRUCTOR_IN_SEALED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Inline classes
|
||||
// Inline and value classes
|
||||
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_FINAL = DiagnosticFactory0.create(ERROR);
|
||||
@@ -355,6 +355,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtElement> INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtParameter> INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtProperty> PROPERTY_WITH_BACKING_FIELD_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<PsiElement> RESERVED_VAR_PROPERTY_OF_VALUE_CLASS = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> DELEGATED_PROPERTY_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<KtTypeReference, KotlinType> INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION = DiagnosticFactory0.create(ERROR);
|
||||
@@ -362,6 +363,8 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtTypeReference> INLINE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> RESERVED_MEMBER_INSIDE_INLINE_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> VALUE_CLASS_CANNOT_BE_CLONEABLE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Result class
|
||||
|
||||
@@ -423,6 +426,9 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtCallExpression> SEALED_CLASS_CONSTRUCTOR_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> SEALED_SUPERTYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> SEALED_SUPERTYPE_IN_LOCAL_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, FqName, FqName> SEALED_INHERITOR_IN_DIFFERENT_PACKAGE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> SEALED_INHERITOR_IN_DIFFERENT_MODULE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> CLASS_INHERITS_JAVA_SEALED_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Companion objects
|
||||
|
||||
@@ -797,6 +803,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> TYPE_INFERENCE_CANDIDATE_WITH_SAM_AND_VARARG = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtExpression> TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT = DiagnosticFactory0.create(ERROR, SPECIAL_CONSTRUCT_TOKEN);
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.config.LanguageVersion;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.diagnostics.UnboundDiagnostic;
|
||||
@@ -170,7 +169,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(EXPERIMENTAL_UNSIGNED_LITERALS_ERROR, "{0}", STRING);
|
||||
|
||||
MAP.put(NON_PARENTHESIZED_ANNOTATIONS_ON_FUNCTIONAL_TYPES, "Non-parenthesized annotations on function types without receiver aren't yet supported (see KT-31734 for details)");
|
||||
MAP.put(JVM_STATIC_IN_PRIVATE_COMPANION, "@JvmStatic is prohibited in private companion objects. This warning will become an error in the next major version");
|
||||
|
||||
MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
|
||||
MAP.put(REDUNDANT_OPEN_IN_INTERFACE, "Modifier 'open' is redundant for abstract interface members");
|
||||
@@ -402,7 +400,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MISSING_IMPORTED_SCRIPT_PSI, "Imported script file ''{0}'' is not loaded. Check your script imports", TO_STRING);
|
||||
MAP.put(MISSING_SCRIPT_PROVIDED_PROPERTY_CLASS, "Cannot access script provided property class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
|
||||
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
|
||||
MAP.put(IR_COMPILED_CLASS, "{0} is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler", TO_STRING);
|
||||
MAP.put(IR_WITH_UNSTABLE_ABI_COMPILED_CLASS, "{0} is compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler", TO_STRING);
|
||||
MAP.put(FIR_COMPILED_CLASS, "{0} is compiled by the new Kotlin compiler frontend and cannot be loaded by the old compiler", TO_STRING);
|
||||
MAP.put(INCOMPATIBLE_CLASS,
|
||||
"{0} was compiled with an incompatible version of Kotlin. {1}",
|
||||
TO_STRING,
|
||||
@@ -633,6 +632,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES, "Data class inheritance from other classes is forbidden");
|
||||
MAP.put(SEALED_SUPERTYPE, "This type is sealed, so it can be inherited by only its own nested classes or objects");
|
||||
MAP.put(SEALED_SUPERTYPE_IN_LOCAL_CLASS, "Local class cannot extend a sealed class");
|
||||
MAP.put(SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, "Inheritor of sealed class or interface declared in package {0} but it must be in package {1} where base class is declared", TO_STRING, TO_STRING);
|
||||
MAP.put(SEALED_INHERITOR_IN_DIFFERENT_MODULE, "Inheritance of sealed classes or interfaces from different module is prohibited");
|
||||
MAP.put(CLASS_INHERITS_JAVA_SEALED_CLASS, "Inheritance of java sealed classes is prohibited");
|
||||
MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton");
|
||||
MAP.put(CLASS_CANNOT_BE_EXTENDED_DIRECTLY, "Class {0} cannot be extended directly", NAME);
|
||||
|
||||
@@ -704,12 +706,13 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NON_PRIVATE_CONSTRUCTOR_IN_ENUM, "Constructor must be private in enum class");
|
||||
MAP.put(NON_PRIVATE_CONSTRUCTOR_IN_SEALED, "Constructor must be private in sealed class");
|
||||
|
||||
MAP.put(INLINE_CLASS_NOT_TOP_LEVEL, "Inline classes are only allowed on top level");
|
||||
MAP.put(INLINE_CLASS_NOT_TOP_LEVEL, "Inline classes cannot be local or inner");
|
||||
MAP.put(INLINE_CLASS_NOT_FINAL, "Inline classes can be only final");
|
||||
MAP.put(ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS, "Primary constructor is required for inline class");
|
||||
MAP.put(INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE, "Inline class must have exactly one primary constructor parameter");
|
||||
MAP.put(INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER, "Value class primary constructor must have only final read-only (val) property parameter");
|
||||
MAP.put(PROPERTY_WITH_BACKING_FIELD_INSIDE_INLINE_CLASS, "Inline class cannot have properties with backing fields");
|
||||
MAP.put(RESERVED_VAR_PROPERTY_OF_VALUE_CLASS, "'var' properties with value class receivers are reserved for future use");
|
||||
MAP.put(DELEGATED_PROPERTY_INSIDE_INLINE_CLASS, "Inline class cannot have delegated properties");
|
||||
MAP.put(INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE, "Inline class cannot have value parameter of type ''{0}''", RENDER_TYPE);
|
||||
MAP.put(INLINE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION, "Inline class cannot implement an interface by delegation");
|
||||
@@ -717,6 +720,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INLINE_CLASS_CANNOT_BE_RECURSIVE, "Inline class cannot be recursive");
|
||||
MAP.put(RESERVED_MEMBER_INSIDE_INLINE_CLASS, "Member with the name ''{0}'' is reserved for future releases", STRING);
|
||||
MAP.put(SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS, "Secondary constructors with bodies are reserved for for future releases");
|
||||
MAP.put(INNER_CLASS_INSIDE_INLINE_CLASS, "Inline class cannot have inner classes");
|
||||
MAP.put(VALUE_CLASS_CANNOT_BE_CLONEABLE, "Value class cannot be Cloneable");
|
||||
|
||||
MAP.put(RESULT_CLASS_IN_RETURN_TYPE, "'kotlin.Result' cannot be used as a return type");
|
||||
MAP.put(RESULT_CLASS_WITH_NULLABLE_OPERATOR, "Expression of type 'kotlin.Result' cannot be used as a left operand of ''{0}''", STRING);
|
||||
@@ -894,6 +899,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPE_INFERENCE_UPPER_BOUND_VIOLATED, "{0}", TYPE_INFERENCE_UPPER_BOUND_VIOLATED_RENDERER);
|
||||
MAP.put(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, "Type inference failed. Expected type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(TYPE_INFERENCE_CANDIDATE_WITH_SAM_AND_VARARG, "Please use spread operator to pass an array as vararg. It will be an error in 1.5.");
|
||||
MAP.put(TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE, "Postponed type variable (type variable of the builder inference) can't be used in the receiver type. Use a member function instead of extension one or specify type arguments of a function which uses the builder inference, explicitly.");
|
||||
|
||||
MAP.put(TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT, "Type inference for control flow expression failed. Please specify its type explicitly.");
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.context.ModuleContext
|
||||
import org.jetbrains.kotlin.contracts.ContractDeserializerImpl
|
||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -51,8 +52,10 @@ fun StorageComponentContainer.configureModule(
|
||||
platform: TargetPlatform,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sealedProvider: SealedClassInheritorsProvider = CliSealedClassInheritorsProvider
|
||||
) {
|
||||
useInstance(sealedProvider)
|
||||
useInstance(moduleContext)
|
||||
useInstance(moduleContext.module)
|
||||
useInstance(moduleContext.project)
|
||||
@@ -152,10 +155,12 @@ fun createContainerForLazyBodyResolve(
|
||||
bodyResolveCache: BodyResolveCache,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
moduleStructureOracle: ModuleStructureOracle
|
||||
moduleStructureOracle: ModuleStructureOracle,
|
||||
mainFunctionDetectorFactory: MainFunctionDetector.Factory
|
||||
): StorageComponentContainer = createContainer("LazyBodyResolve", analyzerServices) {
|
||||
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
|
||||
|
||||
useInstance(mainFunctionDetectorFactory)
|
||||
useInstance(kotlinCodeAnalyzer)
|
||||
useInstance(kotlinCodeAnalyzer.fileScopeProvider)
|
||||
useInstance(bodyResolveCache)
|
||||
@@ -199,6 +204,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
|
||||
useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>()
|
||||
useImpl<LocalLazyDeclarationResolver>()
|
||||
|
||||
|
||||
useInstance(statementFilter)
|
||||
}
|
||||
|
||||
@@ -217,6 +223,7 @@ fun createContainerForLazyResolve(
|
||||
|
||||
useInstance(declarationProviderFactory)
|
||||
|
||||
|
||||
targetEnvironment.configure(this)
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
@@ -202,4 +203,18 @@ class MainFunctionDetector {
|
||||
private fun hasAnnotationWithExactNumberOfArguments(function: KtNamedFunction, number: Int) =
|
||||
function.annotationEntries.any { it.valueArguments.size == number }
|
||||
}
|
||||
|
||||
interface Factory {
|
||||
fun createMainFunctionDetector(trace: BindingTrace, languageVersionSettings: LanguageVersionSettings): MainFunctionDetector
|
||||
|
||||
class Ordinary : Factory {
|
||||
override fun createMainFunctionDetector(
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): MainFunctionDetector {
|
||||
return MainFunctionDetector(trace.bindingContext, languageVersionSettings)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.config.LanguageFeature.AllowSealedInheritorsInDifferentFilesOfSamePackage;
|
||||
import static org.jetbrains.kotlin.config.LanguageFeature.TopLevelSealedInheritance;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||
@@ -635,7 +636,12 @@ public class BodyResolver {
|
||||
containingDescriptor = containingDescriptor.getContainingDeclaration();
|
||||
}
|
||||
if (containingDescriptor == null) {
|
||||
trace.report(SEALED_SUPERTYPE.on(typeReference));
|
||||
if (
|
||||
!languageVersionSettings.supportsFeature(AllowSealedInheritorsInDifferentFilesOfSamePackage) ||
|
||||
DescriptorUtils.isLocal(supertypeOwner)
|
||||
) {
|
||||
trace.report(SEALED_SUPERTYPE.on(typeReference));
|
||||
}
|
||||
}
|
||||
else {
|
||||
trace.report(SEALED_SUPERTYPE_IN_LOCAL_CLASS.on(typeReference));
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.resolve.BindingContext.COLLECTION_LITERAL_CALL
|
||||
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
||||
@@ -93,12 +94,16 @@ class CollectionLiteralResolver(
|
||||
}
|
||||
|
||||
private fun getArrayFunctionCallName(expectedType: KotlinType): Name {
|
||||
if (NO_EXPECTED_TYPE === expectedType || !KotlinBuiltIns.isPrimitiveArray(expectedType)) {
|
||||
if (TypeUtils.noExpectedType(expectedType) ||
|
||||
!(KotlinBuiltIns.isPrimitiveArray(expectedType) || KotlinBuiltIns.isUnsignedArrayType(expectedType))
|
||||
) {
|
||||
return ArrayFqNames.ARRAY_OF_FUNCTION
|
||||
}
|
||||
|
||||
val descriptor = expectedType.constructor.declarationDescriptor ?: return ArrayFqNames.ARRAY_OF_FUNCTION
|
||||
|
||||
return ArrayFqNames.PRIMITIVE_TYPE_TO_ARRAY[KotlinBuiltIns.getPrimitiveArrayType(descriptor)] ?: ArrayFqNames.ARRAY_OF_FUNCTION
|
||||
return ArrayFqNames.PRIMITIVE_TYPE_TO_ARRAY[KotlinBuiltIns.getPrimitiveArrayType(descriptor)]
|
||||
?: UnsignedTypes.unsignedArrayTypeToArrayCall[UnsignedTypes.toUnsignedArrayType(descriptor)]
|
||||
?: ArrayFqNames.ARRAY_OF_FUNCTION
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,11 @@ public class CompileTimeConstantUtils {
|
||||
"kotlin.shortArrayOf",
|
||||
"kotlin.byteArrayOf",
|
||||
"kotlin.booleanArrayOf",
|
||||
"kotlin.emptyArray"
|
||||
"kotlin.emptyArray",
|
||||
"kotlin.ubyteArrayOf",
|
||||
"kotlin.ushortArrayOf",
|
||||
"kotlin.uintArrayOf",
|
||||
"kotlin.ulongArrayOf"
|
||||
);
|
||||
|
||||
public static void checkConstructorParametersType(@NotNull List<KtParameter> parameters, @NotNull BindingTrace trace) {
|
||||
@@ -91,7 +95,8 @@ public class CompileTimeConstantUtils {
|
||||
KotlinBuiltIns.isPrimitiveArray(parameterType) ||
|
||||
KotlinBuiltIns.isPrimitiveType(parameterType) ||
|
||||
KotlinBuiltIns.isString(parameterType) ||
|
||||
UnsignedTypes.INSTANCE.isUnsignedType(parameterType)) {
|
||||
UnsignedTypes.isUnsignedType(parameterType) ||
|
||||
UnsignedTypes.isUnsignedArrayType(parameterType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class CompilerDeserializationConfiguration(languageVersionSettings: LanguageVers
|
||||
override val reportErrorsOnPreReleaseDependencies =
|
||||
!skipPrereleaseCheck && !languageVersionSettings.isPreRelease() && !KotlinCompilerVersion.isPreRelease()
|
||||
|
||||
override val reportErrorsOnIrDependencies = languageVersionSettings.getFlag(AnalysisFlags.reportErrorsOnIrDependencies)
|
||||
override val allowUnstableDependencies = languageVersionSettings.getFlag(AnalysisFlags.allowUnstableDependencies)
|
||||
|
||||
override val typeAliasesAllowed = languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||
import org.jetbrains.kotlin.resolve.lazy.CompilerLocalDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler
|
||||
|
||||
@@ -28,5 +29,6 @@ object CompilerEnvironment : TargetEnvironment("Compiler") {
|
||||
container.useImpl<CompilerLocalDescriptorResolver>()
|
||||
container.useImpl<BasicAbsentDescriptorHandler>()
|
||||
container.useInstance(ModuleStructureOracle.SingleModule)
|
||||
container.useImpl<MainFunctionDetector.Factory.Ordinary>()
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,7 @@ public class DescriptorResolver {
|
||||
private final DeclarationReturnTypeSanitizer declarationReturnTypeSanitizer;
|
||||
private final DataFlowValueFactory dataFlowValueFactory;
|
||||
private final Iterable<DeclarationSignatureAnonymousTypeTransformer> anonymousTypeTransformers;
|
||||
private final AdditionalClassPartsProvider additionalClassPartsProvider;
|
||||
|
||||
public DescriptorResolver(
|
||||
@NotNull AnnotationResolver annotationResolver,
|
||||
@@ -111,7 +112,8 @@ public class DescriptorResolver {
|
||||
@NotNull TypeApproximator approximator,
|
||||
@NotNull DeclarationReturnTypeSanitizer declarationReturnTypeSanitizer,
|
||||
@NotNull DataFlowValueFactory dataFlowValueFactory,
|
||||
@NotNull Iterable<DeclarationSignatureAnonymousTypeTransformer> anonymousTypeTransformers
|
||||
@NotNull Iterable<DeclarationSignatureAnonymousTypeTransformer> anonymousTypeTransformers,
|
||||
@NotNull AdditionalClassPartsProvider additionalClassPartsProvider
|
||||
) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
this.builtIns = builtIns;
|
||||
@@ -131,6 +133,7 @@ public class DescriptorResolver {
|
||||
this.declarationReturnTypeSanitizer = declarationReturnTypeSanitizer;
|
||||
this.dataFlowValueFactory = dataFlowValueFactory;
|
||||
this.anonymousTypeTransformers = anonymousTypeTransformers;
|
||||
this.additionalClassPartsProvider = additionalClassPartsProvider;
|
||||
}
|
||||
|
||||
public List<KotlinType> resolveSupertypes(
|
||||
@@ -156,6 +159,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
syntheticResolveExtension.addSyntheticSupertypes(classDescriptor, supertypes);
|
||||
supertypes.addAll(additionalClassPartsProvider.getAdditionalSupertypes(classDescriptor, supertypes));
|
||||
|
||||
if (supertypes.isEmpty()) {
|
||||
addValidSupertype(supertypes, getDefaultSupertype(classDescriptor));
|
||||
@@ -324,7 +328,8 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
destructuringVariables = () -> {
|
||||
assert owner.getDispatchReceiverParameter() == null
|
||||
ReceiverParameterDescriptor dispatchReceiver = owner.getDispatchReceiverParameter();
|
||||
assert dispatchReceiver == null || dispatchReceiver.getContainingDeclaration() instanceof ScriptDescriptor
|
||||
: "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver";
|
||||
LexicalScope scopeForDestructuring =
|
||||
ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter());
|
||||
|
||||
@@ -323,7 +323,8 @@ class FunctionDescriptorResolver(
|
||||
scope: LexicalScope,
|
||||
classDescriptor: ClassDescriptor,
|
||||
classElement: KtPureClassOrObject,
|
||||
trace: BindingTrace
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): ClassConstructorDescriptorImpl? {
|
||||
if (classDescriptor.kind == ClassKind.ENUM_ENTRY || !classElement.hasPrimaryConstructor()) return null
|
||||
return createConstructorDescriptor(
|
||||
@@ -333,7 +334,8 @@ class FunctionDescriptorResolver(
|
||||
classElement.primaryConstructorModifierList,
|
||||
classElement.primaryConstructor ?: classElement,
|
||||
classElement.primaryConstructorParameters,
|
||||
trace
|
||||
trace,
|
||||
languageVersionSettings
|
||||
)
|
||||
}
|
||||
|
||||
@@ -341,7 +343,8 @@ class FunctionDescriptorResolver(
|
||||
scope: LexicalScope,
|
||||
classDescriptor: ClassDescriptor,
|
||||
constructor: KtSecondaryConstructor,
|
||||
trace: BindingTrace
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): ClassConstructorDescriptorImpl {
|
||||
return createConstructorDescriptor(
|
||||
scope,
|
||||
@@ -350,7 +353,8 @@ class FunctionDescriptorResolver(
|
||||
constructor.modifierList,
|
||||
constructor,
|
||||
constructor.valueParameters,
|
||||
trace
|
||||
trace,
|
||||
languageVersionSettings
|
||||
)
|
||||
}
|
||||
|
||||
@@ -361,7 +365,8 @@ class FunctionDescriptorResolver(
|
||||
modifierList: KtModifierList?,
|
||||
declarationToTrace: KtPureElement,
|
||||
valueParameters: List<KtParameter>,
|
||||
trace: BindingTrace
|
||||
trace: BindingTrace,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): ClassConstructorDescriptorImpl {
|
||||
val constructorDescriptor = ClassConstructorDescriptorImpl.create(
|
||||
classDescriptor,
|
||||
@@ -387,7 +392,7 @@ class FunctionDescriptorResolver(
|
||||
resolveValueParameters(constructorDescriptor, parameterScope, valueParameters, trace, null),
|
||||
resolveVisibilityFromModifiers(
|
||||
modifierList,
|
||||
DescriptorUtils.getDefaultConstructorVisibility(classDescriptor)
|
||||
DescriptorUtils.getDefaultConstructorVisibility(classDescriptor, languageVersionSettings.supportsFeature(LanguageFeature.AllowSealedInheritorsInDifferentFilesOfSamePackage))
|
||||
)
|
||||
)
|
||||
constructor.returnType = classDescriptor.defaultType
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user