Compare commits

...

59 Commits

Author SHA1 Message Date
Alexander Gorshenev
e0e9518bb8 Fixing a bug with private accessors in IR fake override construction 2020-06-08 20:56:14 +03:00
Abduqodiri Qurbonzoda
e540cfd1a5 Deprecate old CharArray to String conversion api #KT-31343
(cherry picked from commit 6a2fed33d3)
2020-06-08 20:08:23 +03:00
Abduqodiri Qurbonzoda
a027df67c1 Promote scanReduce deprecation level to error
(cherry picked from commit 820353ee0e)
2020-06-08 20:08:20 +03:00
Abduqodiri Qurbonzoda
b860872df5 Promote randomOrNull, reduceOrNull, scan to stable
(cherry picked from commit 4e820edd1f)
2020-06-08 20:08:18 +03:00
Abduqodiri Qurbonzoda
b03970ba08 Remove experimental status from Array.associateWith
(cherry picked from commit 094dbf4c2d)
2020-06-08 20:08:15 +03:00
Abduqodiri Qurbonzoda
500414ae5a Promote String <-> utf8 and CharArray conversions to stable
(cherry picked from commit 46297645a4)
2020-06-08 20:08:13 +03:00
Abduqodiri Qurbonzoda
bd1dcb72e3 Promote KClass.cast/safeCast, KAnnotatedElement.hasAnnotation() to stable
(cherry picked from commit e3fb74b656)
2020-06-08 20:08:12 +03:00
Dmitry Petrov
7ca0547d1d Bootstrap: 1.4.20-dev-117 2020-06-08 15:36:55 +03:00
Konstantin Tskhovrebov
311df7bcb0 Hide commonizer import error message for unsupported kotlin plugin.
(cherry picked from commit c3802891fc)
2020-06-08 15:10:50 +03:00
Pavel Kirpichenkov
ae6e459015 Avoid persisting default anchor configuration
#KT-24309 In Progress
2020-06-08 11:31:51 +03:00
Pavel Kirpichenkov
0e45def480 Update library to source analysis mode configuration
Persist analysis flag in the same xml where anchor mapping reside instead
of using properties. This makes it possible to save config in VCS.

#KT-24309 In Progress
2020-06-08 11:31:51 +03:00
Pavel Kirpichenkov
7990399e0d Clean up API of AbstractResolverForProject
Resolution anchors are IDE-specific.
Creating dedicated methods for them in AbstractResolverForProject leads to meaningless
implementation in non-IDE resolvers. Now this method is implemented only
for IDE resolver and accessed through JvmPlatformParameters.

#KT-24309 In Progress
2020-06-08 11:31:51 +03:00
Pavel Kirpichenkov
15bbac7e75 Optimize synchronization for resolution anchors
Use volatile state instead of synchronized access to it.
This should be enough as the component's state is only read
by the component users and never changed.
2020-06-08 11:31:51 +03:00
Pavel Kirpichenkov
5aa7adcd01 Add cancelation check when building anchor mappings 2020-06-08 11:31:51 +03:00
Pavel Kirpichenkov
123c3e4c78 Changes after review
- Replace leaking ModuleResolverTracker with use of ModuleDescriptor.Capabilies
- Provide API for retrieving ResolverForProject from ResolutionFacade
- Update names
2020-06-08 11:31:50 +03:00
Pavel Kirpichenkov
c2495dbe5f Introduce components for library-to-source resolution in IDE
#KT-24309 In progress
2020-06-08 11:31:50 +03:00
Mikhail Zarechenskiy
2d78aa2148 Update forgotten FIR test
(cherry picked from commit a086d9f7df)
2020-06-08 00:00:31 +03:00
Mikhail Zarechenskiy
bc34d69d56 Don't apply Unit-conversion for expressions that return Nothing type
(cherry picked from commit 22b558110d)
2020-06-08 00:00:28 +03:00
Mikhail Zarechenskiy
b74e24b819 Don't allow coercing receivers from signed to unsigned constants
(cherry picked from commit e72401c5f4)
2020-06-08 00:00:25 +03:00
Mikhail Zarechenskiy
47e76c260b Introduce call checker for Unit-conversions
(cherry picked from commit bfa648972f)
2020-06-08 00:00:22 +03:00
Mikhail Zarechenskiy
441e86e892 Allow suspend-conversion for callable references as part of adaptation
(cherry picked from commit 6b0a803d14)
2020-06-08 00:00:19 +03:00
Mikhail Zarechenskiy
14cd518aa9 Fix chained conversions for subtypes of functional types
(cherry picked from commit 6b58be377e)
2020-06-08 00:00:16 +03:00
Mikhail Zarechenskiy
74b35939fa Introduce Unit-conversions for simple arguments
(cherry picked from commit 71cbe97688)
2020-06-08 00:00:13 +03:00
Mikhail Zarechenskiy
8d91ce5774 Refactoring: rename files to avoid "util" suffixes
(cherry picked from commit f08a45f2d4)
2020-06-08 00:00:09 +03:00
Mikhail Zarechenskiy
dc2440185b Narrow down the range for compatibility warning to callee expression
(cherry picked from commit a4af833d55)
2020-06-08 00:00:07 +03:00
Mikhail Zarechenskiy
2262f0a4ef Refactoring: rename method to make it more specific
(cherry picked from commit 4bd622c1c5)
2020-06-08 00:00:04 +03:00
Mikhail Zarechenskiy
65b282bada Compatibility warning for references to companion via name (KT-13934)
(cherry picked from commit 718f23b34f)
2020-06-08 00:00:00 +03:00
Anton Bannykh
a62fbd7fa1 JS: fix explicit cross-module SAM constructor calls
(cherry picked from commit bd2a0563ad)
2020-06-06 17:48:45 +03:00
Anton Bannykh
d08260d60c Add stdlib API test + remove some extra IR stdlib API's
(cherry picked from commit a18bfad53a)
2020-06-06 17:48:45 +03:00
Ilya Muradyan
56cf876cb8 Add info about the end of range in scripting REPL compiler messages 2020-06-05 22:05:01 +02:00
Ilya Chernikov
61f8953bd3 Extract interface from CompilerMessageLocation to ease extension
The CompilerMessageLocation is an implicit part of the binary daemon
protocol so changing it breaks compatibility with older daemons.
This change allows to extend location for non-daemon uses without
breaking the binary protocol.
2020-06-05 22:05:00 +02:00
Ilya Kirillov
b185884005 Wizard: use cache redirector on project importing tests
(cherry picked from commit 8a4521864e)
2020-06-05 13:04:23 +03:00
Ilya Kirillov
eba09719d2 Wizard: download latest dev version for tests from bintray
(cherry picked from commit cce5a9a1ca)
2020-06-05 13:04:22 +03:00
Dmitry Petrov
70e928f4d9 Fix stdlib compilation after updated @JvmName check
Previously, extension receiver type was not taken into account when
checking for @JvmName annotation applicability to possibly mangled
functions (such functions, however, were mangled).
This bug was fixed, but, unfortunately, not before such functions were
added to stdlib ('sumOf' family).
2020-06-05 10:43:52 +03:00
Dmitry Petrov
7029e78ca2 Forward compatibility hacks for Result.{success, failure}
Don't mangled functions annotated with @JvmName.
Annotate 'Result.success' and 'Result.failure' with @JvmName and
@Suppress("INAPPLICABLE_JVM_NAME").
NB this would require bootstrap.

(cherry picked from commit 202bbdf8dd)
2020-06-05 10:38:49 +03:00
Roman Artemev
a394de00c5 [JS IR] Greenify failing (in 1.4.0 branch) tests 2020-06-04 16:53:20 +03:00
Roman Artemev
d29251f507 [PLUGIN API] Implement custom linkage for plugin extensions
(cherry picked from commit 5eae262264)
2020-06-04 15:32:49 +03:00
Roman Artemev
e61f5956cb [PLUGIN API] Add extension point to customize linkage process
(cherry picked from commit a401374ed4)
2020-06-04 15:32:48 +03:00
Roman Artemev
740bbaeb8c [IR] Move IrProvider and 'IrDeserializer' into separate package
(cherry picked from commit f9c2c846f7)
2020-06-04 15:32:48 +03:00
Alexander Udalov
6851607a04 JVM IR: do not generate DefaultImpls delegate for collection fake overrides
In the newly added test, prior to this change, JVM IR was generating
DefaultImpls classes with calls to things like
`kotlin/collections/MutableList$DefaultImpls.spliterator` and other
default methods present in JDK 8+. This obviously didn't make much
sense. Although these weren't explicitly mentioned anywhere in the
bytecode, they caused some validation tools to report errors (e.g.
animalsniffer used in arrow).

(cherry picked from commit 5647a935a2)
2020-06-04 14:28:07 +02:00
Ilya Goncharov
5b5684cd5d [Gradle, JS] Fix test after changing type of IR link task on mode
(cherry picked from commit 74e4a817cb)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
a6a9427757 [Gradle, JS] Webpack on file providers for task configuration avoidance
(cherry picked from commit 426f164e02)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
52dace2970 [Gradle, JS] Make destinationDir as var
(cherry picked from commit 01f3e4b083)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
3716d2c4e7 [Gradle, JS] Use RegularFile to not explicit dependsOn
^KT-32273 fixed
^KT-36451 fixed
^KT-37258 fixed

(cherry picked from commit 402dfd5da7)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
4f96393f14 [Gradle, JS] Add dependency on dce task
^KT-32273 fixed
^KT-36451 fixed
^KT-37258 fixed

(cherry picked from commit e27bd04ba2)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
6995eb87df [Gradle, JS] JsBinaryType to KotlinJsBinaryType
(cherry picked from commit d3260bca27)
2020-06-04 11:07:06 +03:00
Ilya Goncharov
f94653fd49 [Gradle, JS] KotlinJsType to KotlinJsMode
(cherry picked from commit d27ad99daa)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
007b3d97d6 [Gradle, JS] Move common part of webpack configuration to separate fun
^KT-32273 fixed
^KT-36451 fixed
^KT-37258 fixed

(cherry picked from commit a5e46568ee)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
b8918eab5d [Gradle, JS] Add resolveFromModulesFirst to build tasks
(cherry picked from commit ef63d6f84c)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
aaa2747a4e [Gradle, JS] Use property for webpack entry
(cherry picked from commit d4d8495840)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
5c40432b4e [Gradle, JS] Add dce to development
^KT-32273 fixed
^KT-36451 fixed
^KT-37258 fixed

(cherry picked from commit 65db6bb2a5)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
6fe1c56c32 [Gradle, JS] Use API form Gradle 5.0
(cherry picked from commit 9d8eb65a5e)
2020-06-04 11:07:05 +03:00
Ilya Goncharov
130eeff06e [Gradle, JS] Add index.html to Kotlin DSL wizard
^KT-39275 fixed

(cherry picked from commit bd194686df)
2020-06-04 11:06:45 +03:00
Ilya Goncharov
385498aa78 [Gradle, JS] Fix grammar in methods for JS import
(cherry picked from commit 890da492fb)
2020-06-04 11:05:59 +03:00
Ilya Goncharov
6ec97cc85f [Gradle, JS] Fix grammar on comment
(cherry picked from commit bc4d7e0020)
2020-06-04 11:05:59 +03:00
Mikhail Bogdanov
328db2f0bf Remove compatibility hack
(cherry picked from commit 4f8ad6bdcb)
2020-06-04 08:03:22 +02:00
Vyacheslav Gerasimov
357203fb11 Build: Remove identifying info from build scans 2020-06-03 19:33:25 +03:00
Henrik Tunedal
f8693209ab Use system-specific user cache directory in main-kts
#KT-38222 fixed
2020-06-03 11:18:33 +02:00
Henrik Tunedal
1e9ee7014b Improve hashing of script files 2020-06-03 11:18:33 +02:00
341 changed files with 37505 additions and 1038 deletions

View File

@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.compilerRunner
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
@@ -25,7 +25,7 @@ class MessageCollectorToOutputItemsCollectorAdapter(
private val delegate: MessageCollector,
private val outputCollector: OutputItemsCollector
) : MessageCollector by delegate {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
// TODO: consider adding some other way of passing input -> output mapping from compiler, e.g. dedicated service
OutputMessageUtil.parseOutputMessage(message)?.let {
outputCollector.add(it.sourceFiles, it.outputFile)

View File

@@ -66,16 +66,10 @@ class SourceMapCopier(val parent: SourceMapper, private val smap: SMAP, val call
return mappedLineNumber
}
val newLineNumber = if (lineNumber == 65100) {
// TODO This is a compatibility hack for reading bytecode generated by 1.4-M1. Once the bootstrap
// compiler is updated to a newer version, it can be removed (as newer bytecode explicitly lists
// this range in the SMAP).
parent.mapSyntheticLineNumber(InlineOnlySmapSkipper.LOCAL_VARIABLE_INLINE_ARGUMENT_SYNTHETIC_LINE_NUMBER)
} else {
val range = lastVisitedRange?.takeIf { lineNumber in it } ?: smap.findRange(lineNumber) ?: return -1
lastVisitedRange = range
parent.mapLineNumber(range.mapDestToSource(lineNumber), callSite ?: range.callSite)
}
val range = lastVisitedRange?.takeIf { lineNumber in it } ?: smap.findRange(lineNumber) ?: return -1
lastVisitedRange = range
val newLineNumber = parent.mapLineNumber(range.mapDestToSource(lineNumber), callSite ?: range.callSite)
visitedLines.put(lineNumber, newLineNumber)
return newLineNumber
}

View File

@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyPrivateApi
import org.jetbrains.kotlin.resolve.descriptorUtil.nonSourceAnnotations
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmDefaultAnnotation
import org.jetbrains.kotlin.resolve.jvm.requiresFunctionNameManglingForParameterTypes
import org.jetbrains.kotlin.resolve.jvm.requiresFunctionNameManglingForReturnType
import org.jetbrains.kotlin.serialization.DescriptorSerializer
import org.jetbrains.kotlin.serialization.DescriptorSerializer.Companion.writeVersionRequirement
@@ -202,7 +203,10 @@ class JvmSerializerExtension @JvmOverloads constructor(
versionRequirementTable?.writeInlineParameterNullCheckRequirement(proto::addVersionRequirement)
}
if (requiresFunctionNameManglingForReturnType(descriptor)) {
if (requiresFunctionNameManglingForReturnType(descriptor) &&
!DescriptorUtils.hasJvmNameAnnotation(descriptor) &&
!requiresFunctionNameManglingForParameterTypes(descriptor)
) {
versionRequirementTable?.writeFunctionNameManglingForReturnTypeRequirement(proto::addVersionRequirement)
}
}
@@ -267,7 +271,7 @@ class JvmSerializerExtension @JvmOverloads constructor(
versionRequirementTable?.writeInlineParameterNullCheckRequirement(proto::addVersionRequirement)
}
if (requiresFunctionNameManglingForReturnType(descriptor)) {
if (!DescriptorUtils.hasJvmNameAnnotation(descriptor) && requiresFunctionNameManglingForReturnType(descriptor)) {
versionRequirementTable?.writeFunctionNameManglingForReturnTypeRequirement(proto::addVersionRequirement)
}
}

View File

@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.codegen.state
import org.jetbrains.kotlin.codegen.coroutines.unwrapInitialDescriptorForSuspendFunction
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.jvm.requiresFunctionNameManglingForParameterTypes
@@ -24,10 +25,13 @@ fun getManglingSuffixBasedOnKotlinSignature(
if (descriptor is ConstructorDescriptor) return null
if (InlineClassDescriptorResolver.isSynthesizedBoxOrUnboxMethod(descriptor)) return null
// Don't mangle functions with '@JvmName' annotation.
// Some stdlib functions ('Result.success', 'Result.failure') are annotated with '@JvmName' as a workaround for forward compatibility.
if (DescriptorUtils.hasJvmNameAnnotation(descriptor)) return null
// If a function accepts inline class parameters, mangle its name.
val actualValueParameterTypes = listOfNotNull(descriptor.extensionReceiverParameter?.type) + descriptor.valueParameters.map { it.type }
if (requiresFunctionNameManglingForParameterTypes(actualValueParameterTypes)) {
return "-" + md5base64(collectSignatureForMangling(actualValueParameterTypes))
if (requiresFunctionNameManglingForParameterTypes(descriptor)) {
return "-" + md5base64(collectSignatureForMangling(descriptor))
}
// If a class member function returns inline class value, mangle its name.
@@ -42,8 +46,10 @@ fun getManglingSuffixBasedOnKotlinSignature(
return null
}
private fun collectSignatureForMangling(types: List<KotlinType>) =
types.joinToString { getSignatureElementForMangling(it) }
private fun collectSignatureForMangling(descriptor: CallableMemberDescriptor): String {
val types = listOfNotNull(descriptor.extensionReceiverParameter?.type) + descriptor.valueParameters.map { it.type }
return types.joinToString { getSignatureElementForMangling(it) }
}
private fun getSignatureElementForMangling(type: KotlinType): String = buildString {
val descriptor = type.constructor.declarationDescriptor ?: return ""

View File

@@ -67,7 +67,7 @@ class BuiltInsSerializer(dependOnOldBuiltIns: Boolean) : MetadataSerializer(Buil
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, false),
false
) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
// Only report diagnostics without a particular location because there's plenty of errors in built-in sources
// (functions without bodies, incorrect combination of modifiers, etc.)
if (location == null) {

View File

@@ -18,24 +18,61 @@ package org.jetbrains.kotlin.cli.common.messages
import java.io.Serializable
interface CompilerMessageSourceLocation : Serializable {
val path: String
val line: Int
val column: Int
val lineEnd: Int get() = -1
val columnEnd: Int get() = -1
val lineContent: String?
}
data class CompilerMessageLocation private constructor(
val path: String,
val line: Int,
val column: Int,
val lineContent: String?
) : Serializable {
override val path: String,
override val line: Int,
override val column: Int,
override val lineContent: String?
) : CompilerMessageSourceLocation {
override fun toString(): String =
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
companion object {
@JvmStatic
fun create(path: String?): CompilerMessageLocation? =
create(path, -1, -1, null)
create(path, -1, -1, null)
@JvmStatic
fun create(path: String?, line: Int, column: Int, lineContent: String?): CompilerMessageLocation? =
if (path == null) null else CompilerMessageLocation(path, line, column, lineContent)
if (path == null) null else CompilerMessageLocation(path, line, column, lineContent)
private val serialVersionUID: Long = 8228357578L
}
}
data class CompilerMessageLocationWithRange private constructor(
override val path: String,
override val line: Int,
override val column: Int,
override val lineEnd: Int,
override val columnEnd: Int,
override val lineContent: String?
) : CompilerMessageSourceLocation {
override fun toString(): String =
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
companion object {
@JvmStatic
fun create(
path: String?,
lineStart: Int,
columnStart: Int,
lineEnd: Int?,
columnEnd: Int?,
lineContent: String?
): CompilerMessageLocationWithRange? =
if (path == null) null else CompilerMessageLocationWithRange(path, lineStart, columnStart, lineEnd ?: -1, columnEnd ?: -1, lineContent)
private val serialVersionUID: Long = 8228357578L
}
}

View File

@@ -36,7 +36,7 @@ public class FilteringMessageCollector implements MessageCollector {
}
@Override
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location) {
if (!decline.test(severity)) {
messageCollector.report(severity, message, location);
}

View File

@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class GroupingMessageCollector implements MessageCollector {
@@ -32,7 +31,7 @@ public class GroupingMessageCollector implements MessageCollector {
private final boolean treatWarningsAsErrors;
// Note that the key in this map can be null
private final Multimap<CompilerMessageLocation, Message> groupedMessages = LinkedHashMultimap.create();
private final Multimap<CompilerMessageSourceLocation, Message> groupedMessages = LinkedHashMultimap.create();
public GroupingMessageCollector(@NotNull MessageCollector delegate, boolean treatWarningsAsErrors) {
this.delegate = delegate;
@@ -48,7 +47,7 @@ public class GroupingMessageCollector implements MessageCollector {
public void report(
@NotNull CompilerMessageSeverity severity,
@NotNull String message,
@Nullable CompilerMessageLocation location
@Nullable CompilerMessageSourceLocation location
) {
if (CompilerMessageSeverity.VERBOSE.contains(severity)) {
delegate.report(severity, message, location);
@@ -78,9 +77,9 @@ public class GroupingMessageCollector implements MessageCollector {
report(CompilerMessageSeverity.ERROR, "warnings found and -Werror specified", null);
}
List<CompilerMessageLocation> sortedKeys =
List<CompilerMessageSourceLocation> sortedKeys =
CollectionsKt.sortedWith(groupedMessages.keySet(), Comparator.nullsFirst(CompilerMessageLocationComparator.INSTANCE));
for (CompilerMessageLocation location : sortedKeys) {
for (CompilerMessageSourceLocation location : sortedKeys) {
for (Message message : groupedMessages.get(location)) {
if (!hasExplicitErrors || message.severity.isError() || message.severity == CompilerMessageSeverity.STRONG_WARNING) {
delegate.report(message.severity, message.message, message.location);
@@ -91,7 +90,7 @@ public class GroupingMessageCollector implements MessageCollector {
groupedMessages.clear();
}
private static class CompilerMessageLocationComparator implements Comparator<CompilerMessageLocation> {
private static class CompilerMessageLocationComparator implements Comparator<CompilerMessageSourceLocation> {
public static final CompilerMessageLocationComparator INSTANCE = new CompilerMessageLocationComparator();
// First, output all messages without any location information. Then, only those with the file path.
@@ -104,7 +103,7 @@ public class GroupingMessageCollector implements MessageCollector {
// foo.kt:42: error: bad line
// foo.kt:42:43: error: bad character
@Override
public int compare(CompilerMessageLocation o1, CompilerMessageLocation o2) {
public int compare(CompilerMessageSourceLocation o1, CompilerMessageSourceLocation o2) {
if (o1.getColumn() == -1 && o2.getColumn() != -1) return -1;
if (o1.getColumn() != -1 && o2.getColumn() == -1) return 1;
@@ -118,9 +117,9 @@ public class GroupingMessageCollector implements MessageCollector {
private static class Message {
private final CompilerMessageSeverity severity;
private final String message;
private final CompilerMessageLocation location;
private final CompilerMessageSourceLocation location;
private Message(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
private Message(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location) {
this.severity = severity;
this.message = message;
this.location = location;

View File

@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.cli.common.messages
interface MessageCollector {
fun clear()
fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation? = null)
fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation? = null)
fun hasErrors(): Boolean
companion object {
val NONE: MessageCollector = object : MessageCollector {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
// Do nothing
}

View File

@@ -31,6 +31,6 @@ interface MessageCollectorBasedReporter : DiagnosticMessageReporter {
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report(
AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity),
render,
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumn(diagnostic))
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic))
)
}

View File

@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.cli.common.messages
class GradleStyleMessageRenderer : MessageRenderer {
override fun render(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?): String {
override fun render(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?): String {
val prefix = when (severity) {
CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> "w"
CompilerMessageSeverity.ERROR, CompilerMessageSeverity.EXCEPTION -> "e"

View File

@@ -32,7 +32,7 @@ public interface MessageRenderer {
MessageRenderer WITHOUT_PATHS = new PlainTextMessageRenderer() {
@Nullable
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
protected String getPath(@NotNull CompilerMessageSourceLocation location) {
return null;
}
@@ -45,7 +45,7 @@ public interface MessageRenderer {
MessageRenderer PLAIN_FULL_PATHS = new PlainTextMessageRenderer() {
@NotNull
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
protected String getPath(@NotNull CompilerMessageSourceLocation location) {
return location.getPath();
}
@@ -60,7 +60,7 @@ public interface MessageRenderer {
@NotNull
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
protected String getPath(@NotNull CompilerMessageSourceLocation location) {
return FileUtilsKt.descendantRelativeTo(new File(location.getPath()), cwd).getPath();
}
@@ -75,7 +75,7 @@ public interface MessageRenderer {
@Nullable
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
protected String getPath(@NotNull CompilerMessageSourceLocation location) {
return FileUtil.toSystemIndependentName(
FileUtilsKt.descendantRelativeTo(new File(location.getPath()), cwd).getPath()
);
@@ -91,7 +91,7 @@ public interface MessageRenderer {
String renderPreamble();
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location);
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location);
String renderUsage(@NotNull String usage);

View File

@@ -32,21 +32,23 @@ public class MessageUtil {
private MessageUtil() {}
@Nullable
public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) {
public static CompilerMessageSourceLocation psiElementToMessageLocation(@Nullable PsiElement element) {
if (element == null) return null;
PsiFile file = element.getContainingFile();
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange()));
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnRangeInPsiFile(file, element.getTextRange()));
}
@Nullable
public static CompilerMessageLocation psiFileToMessageLocation(
public static CompilerMessageSourceLocation psiFileToMessageLocation(
@NotNull PsiFile file,
@Nullable String defaultValue,
@NotNull PsiDiagnosticUtils.LineAndColumn lineAndColumn
@NotNull PsiDiagnosticUtils.LineAndColumnRange range
) {
VirtualFile virtualFile = file.getVirtualFile();
String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue;
return CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn(), lineAndColumn.getLineContent());
PsiDiagnosticUtils.LineAndColumn start = range.getStart();
PsiDiagnosticUtils.LineAndColumn end = range.getEnd();
return CompilerMessageLocationWithRange.create(path, start.getLine(), start.getColumn(), end.getLine(), end.getColumn(), start.getLineContent());
}
@NotNull

View File

@@ -58,7 +58,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer {
}
@Override
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location) {
StringBuilder result = new StringBuilder();
int line = location != null ? location.getLine() : -1;
@@ -156,7 +156,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer {
}
@Nullable
protected abstract String getPath(@NotNull CompilerMessageLocation location);
protected abstract String getPath(@NotNull CompilerMessageSourceLocation location);
@Override
public String renderUsage(@NotNull String usage) {

View File

@@ -42,7 +42,7 @@ public class PrintingMessageCollector implements MessageCollector {
public void report(
@NotNull CompilerMessageSeverity severity,
@NotNull String message,
@Nullable CompilerMessageLocation location
@Nullable CompilerMessageSourceLocation location
) {
if (!verbose && CompilerMessageSeverity.VERBOSE.contains(severity)) return;

View File

@@ -27,7 +27,7 @@ public class XmlMessageRenderer implements MessageRenderer {
}
@Override
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageSourceLocation location) {
StringBuilder out = new StringBuilder();
String tagName = severity.getPresentableName();
out.append("<").append(tagName);

View File

@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.compiler.plugin.*
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.io.File
import java.net.URLClassLoader
import java.util.*
object PluginCliParser {
@JvmStatic

View File

@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.config.K2MetadataConfigurationKeys
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
import org.jetbrains.kotlin.codegen.CompilationException
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration

View File

@@ -6,19 +6,21 @@
package org.jetbrains.kotlin.daemon.client.experimental
import io.ktor.network.sockets.Socket
import kotlinx.coroutines.*
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.daemon.client.CompileServiceSessionAsync
import org.jetbrains.kotlin.daemon.client.KotlinCompilerDaemonClient
import org.jetbrains.kotlin.daemon.client.DaemonReportMessage
import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets
import org.jetbrains.kotlin.daemon.client.KotlinCompilerDaemonClient
import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.daemon.common.Profiler
import org.jetbrains.kotlin.daemon.common.experimental.*
import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Server
import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.ServerSocketWrapper
import org.jetbrains.kotlin.daemon.common.*
import java.io.File
import java.io.Serializable
import java.net.SocketException
@@ -30,7 +32,6 @@ import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
import java.util.logging.Logger
import kotlin.concurrent.thread
import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback
class KotlinCompilerClient : KotlinCompilerDaemonClient {

View File

@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.daemon
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
@@ -181,7 +181,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
}
class TestMessageCollector : MessageCollector {
data class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation?)
data class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageSourceLocation?)
val messages = arrayListOf<Message>()
@@ -189,7 +189,7 @@ class TestMessageCollector : MessageCollector {
messages.clear()
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
messages.add(Message(severity, message, location))
}

View File

@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.daemon.experimental.integration
import com.intellij.openapi.application.ApplicationManager
import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
@@ -301,7 +301,7 @@ class CompilerApiTest : KotlinIntegrationTestBase() {
}
class TestMessageCollector : MessageCollector {
data class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation?)
data class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageSourceLocation?)
val messages = arrayListOf<Message>()
@@ -309,7 +309,7 @@ class TestMessageCollector : MessageCollector {
messages.clear()
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
messages.add(Message(severity, message, location))
}

View File

@@ -168,9 +168,9 @@ internal class KeepFirstErrorMessageCollector(compilerMessagesStream: PrintStrea
private val innerCollector = PrintingMessageCollector(compilerMessagesStream, MessageRenderer.WITHOUT_PATHS, false)
internal var firstErrorMessage: String? = null
internal var firstErrorLocation: CompilerMessageLocation? = null
internal var firstErrorLocation: CompilerMessageSourceLocation? = null
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
if (firstErrorMessage == null && severity.isError) {
firstErrorMessage = message
firstErrorLocation = location

View File

@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.daemon.report
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
@@ -34,7 +34,7 @@ internal class CompileServicesFacadeMessageCollector(
hasErrors = false
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
log.info("Message: " + MessageRenderer.WITHOUT_PATHS.render(severity, message, location))
when (severity) {
CompilerMessageSeverity.OUTPUT -> {

View File

@@ -5,17 +5,14 @@
package org.jetbrains.kotlin.daemon.report.experimental
import kotlinx.coroutines.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.daemon.KotlinCompileDaemon.log
import org.jetbrains.kotlin.daemon.common.CompilationOptions
import org.jetbrains.kotlin.daemon.common.ReportCategory
import org.jetbrains.kotlin.daemon.common.ReportSeverity
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBaseAsync
import org.jetbrains.kotlin.daemon.common.report
import org.jetbrains.kotlin.daemon.common.*
internal class CompileServicesFacadeMessageCollector(
private val servicesFacade: CompilerServicesFacadeBaseAsync,
@@ -28,7 +25,7 @@ internal class CompileServicesFacadeMessageCollector(
hasErrors = false
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
GlobalScope.async {
log.info("Message: " + MessageRenderer.WITHOUT_PATHS.render(severity, message, location))
when (severity) {

View File

@@ -1939,6 +1939,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
}
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
public void testRewriteAtSliceOnGetOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
@@ -24429,6 +24439,54 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
}
}
@TestMetadata("compiler/testData/diagnostics/tests/unitConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnitConversion extends AbstractFirOldFrontendDiagnosticsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInUnitConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/unitConversion"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("chainedFunSuspendUnitConversion.kt")
public void testChainedFunSuspendUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt");
}
@TestMetadata("chainedFunUnitConversion.kt")
public void testChainedFunUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt");
}
@TestMetadata("chainedUnitSuspendConversion.kt")
public void testChainedUnitSuspendConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt");
}
@TestMetadata("unitConversionCompatibility.kt")
public void testUnitConversionCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt");
}
@TestMetadata("unitConversionDisabledForSimpleArguments.kt")
public void testUnitConversionDisabledForSimpleArguments() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionDisabledForSimpleArguments.kt");
}
@TestMetadata("unitConversionForAllKinds.kt")
public void testUnitConversionForAllKinds() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt");
}
@TestMetadata("unitConversionForSubtypes.kt")
public void testUnitConversionForSubtypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)

View File

@@ -2685,6 +2685,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
@@ -13023,6 +13028,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inlineClasses/noReturnTypeMangling.kt");
}
@TestMetadata("noReturnTypeManglingJvmName.kt")
public void testNoReturnTypeManglingJvmName() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/noReturnTypeManglingJvmName.kt");
}
@TestMetadata("nullableEqeqNonNull.kt")
public void testNullableEqeqNonNull() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/nullableEqeqNonNull.kt");

View File

@@ -6,10 +6,8 @@
package org.jetbrains.kotlin.fir
import com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys.CONTENT_ROOTS
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
@@ -17,9 +15,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind
import java.io.FileOutputStream
import java.io.PrintStream
import kotlin.system.measureNanoTime
@@ -87,7 +82,7 @@ class NonFirResolveModularizedTotalKotlinTest : AbstractModularizedTest() {
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
if (location != null)
print(location.toString())
print(":")

View File

@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.TargetEnvironment
@@ -39,7 +38,9 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
class JvmPlatformParameters(
val packagePartProviderFactory: (ModuleContent<*>) -> PackagePartProvider,
val moduleByJavaClass: (JavaClass) -> ModuleInfo?
val moduleByJavaClass: (JavaClass) -> ModuleInfo?,
// params: referenced module info of target class, context module info of current resolver
val resolverForReferencedModule: ((ModuleInfo, ModuleInfo) -> ResolverForModule?)? = null,
) : PlatformAnalysisParameters
@@ -64,13 +65,22 @@ class JvmResolverForModuleFactory(
)
val moduleClassResolver = ModuleClassResolverImpl { javaClass ->
val referencedClassModule = (platformParameters as JvmPlatformParameters).moduleByJavaClass(javaClass)
// We don't have full control over idea resolve api so we allow for a situation which should not happen in Kotlin.
// For example, type in a java library can reference a class declared in a source root (is valid but rare case)
// Providing a fallback strategy in this case can hide future problems, so we should at least log to be able to diagnose those
val referencedClassModule = platformParameters.moduleByJavaClass(javaClass)
// A type in a java library can reference a class declared in a source root (is valid but rare case).
// Resolving such a class with Kotlin resolver for libraries is guaranteed to fail, as libraries can't
// have dependencies on the source roots. The chain of resolvers (sources -> libraries -> sdk) exists to prevent
// potentially slow repetitive analysis of the same libraries after modifications in sources. The only way to mitigate
// this restriction currently is to manually configure resolution anchors for known source-dependent libraries in a project.
// See also KT-24309
@Suppress("UNCHECKED_CAST")
val resolverForReferencedModule = referencedClassModule?.let { resolverForProject.tryGetResolverForModule(it as M) }
val resolverForReferencedModule = referencedClassModule?.let { referencedModuleInfo ->
if (platformParameters.resolverForReferencedModule != null) {
platformParameters.resolverForReferencedModule.invoke(referencedModuleInfo, moduleInfo)
} else {
resolverForProject.tryGetResolverForModule(referencedModuleInfo as M)
}
}
val resolverForModule = resolverForReferencedModule?.takeIf {
referencedClassModule.platform.isJvm() || referencedClassModule.platform == null
@@ -110,12 +120,12 @@ class JvmResolverForModuleFactory(
)
providersForModule +=
PackageFragmentProviderExtension.getInstances(project)
.mapNotNull {
it.getPackageFragmentProvider(
project, moduleDescriptor, moduleContext.storageManager, trace, moduleInfo, lookupTracker
)
}
PackageFragmentProviderExtension.getInstances(project)
.mapNotNull {
it.getPackageFragmentProvider(
project, moduleDescriptor, moduleContext.storageManager, trace, moduleInfo, lookupTracker
)
}
return ResolverForModule(CompositePackageFragmentProvider(providersForModule), container)
}

View File

@@ -150,7 +150,7 @@ class JvmNameAnnotationChecker : DeclarationChecker {
if (DescriptorUtils.isOverride(descriptor) || descriptor.isOverridable) {
diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_JVM_NAME.on(annotationEntry))
} else if (descriptor.containingDeclaration.isInlineClassThatRequiresMangling() ||
requiresFunctionNameManglingForParameterTypes(descriptor.valueParameters.map { it.type }) ||
requiresFunctionNameManglingForParameterTypes(descriptor) ||
requiresFunctionNameManglingForReturnType(descriptor)
) {
diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_JVM_NAME.on(annotationEntry))

View File

@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.RESOLUTION_ANCHOR_PROVIDER_CAPABILITY
import org.jetbrains.kotlin.resolve.ResolutionAnchorProvider
abstract class AbstractResolverForProject<M : ModuleInfo>(
private val debugName: String,
@@ -21,7 +23,8 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
modules: Collection<M>,
protected val fallbackModificationTracker: ModificationTracker? = null,
private val delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
private val packageOracleFactory: PackageOracleFactory = PackageOracleFactory.OptimisticFactory
private val packageOracleFactory: PackageOracleFactory = PackageOracleFactory.OptimisticFactory,
protected val resolutionAnchorProvider: ResolutionAnchorProvider = ResolutionAnchorProvider.Default,
) : ResolverForProject<M>() {
protected class ModuleData(
@@ -54,7 +57,6 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
abstract fun modulesContent(module: M): ModuleContent<M>
abstract fun builtInsForModule(module: M): KotlinBuiltIns
abstract fun createResolverForModule(descriptor: ModuleDescriptor, moduleInfo: M): ResolverForModule
override fun tryGetResolverForModule(moduleInfo: M): ResolverForModule? {
if (!isCorrectModuleInfo(moduleInfo)) {
return null
@@ -122,6 +124,10 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
return doGetDescriptorForModule(moduleInfo)
}
override fun moduleInfoForModuleDescriptor(moduleDescriptor: ModuleDescriptor): M {
return moduleInfoByDescriptor[moduleDescriptor] ?: delegateResolver.moduleInfoForModuleDescriptor(moduleDescriptor)
}
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>): Nothing {
DiagnoseUnknownModuleInfoReporter.report(name, infos, allModules)
}
@@ -158,6 +164,7 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
val moduleData = createModuleDescriptor(module)
descriptorByModule[module] = moduleData
return moduleData
}
@@ -167,8 +174,8 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
projectContext.storageManager,
builtInsForModule(module),
module.platform,
module.capabilities,
module.stableName
module.capabilities + listOf(RESOLUTION_ANCHOR_PROVIDER_CAPABILITY to resolutionAnchorProvider),
module.stableName,
)
moduleInfoByDescriptor[moduleDescriptor] = module
setupModuleDescriptor(module, moduleDescriptor)

View File

@@ -44,6 +44,7 @@ abstract class ResolverForProject<M : ModuleInfo> {
fun resolverForModule(moduleInfo: M): ResolverForModule = resolverForModuleDescriptor(descriptorForModule(moduleInfo))
abstract fun tryGetResolverForModule(moduleInfo: M): ResolverForModule?
abstract fun descriptorForModule(moduleInfo: M): ModuleDescriptor
abstract fun moduleInfoForModuleDescriptor(moduleDescriptor: ModuleDescriptor): M
abstract fun resolverForModuleDescriptor(descriptor: ModuleDescriptor): ResolverForModule
abstract fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>): Nothing
@@ -73,6 +74,10 @@ class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
override fun descriptorForModule(moduleInfo: M) = diagnoseUnknownModuleInfo(listOf(moduleInfo))
override val allModules: Collection<M> = listOf()
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>) = throw IllegalStateException("Should not be called for $infos")
override fun moduleInfoForModuleDescriptor(descriptor: ModuleDescriptor): M {
throw IllegalStateException("$descriptor is not contained in this resolver")
}
}
data class ModuleContent<out M : ModuleInfo>(

View File

@@ -84,6 +84,24 @@ public class DiagnosticUtils {
return PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getStartOffset());
}
@NotNull
public static PsiDiagnosticUtils.LineAndColumnRange getLineAndColumnRange(@NotNull Diagnostic diagnostic) {
PsiFile file = diagnostic.getPsiFile();
List<TextRange> textRanges = diagnostic.getTextRanges();
if (textRanges.isEmpty()) return PsiDiagnosticUtils.LineAndColumnRange.NONE;
TextRange firstRange = firstRange(textRanges);
return getLineAndColumnRangeInPsiFile(file, firstRange);
}
@NotNull
public static PsiDiagnosticUtils.LineAndColumnRange getLineAndColumnRangeInPsiFile(PsiFile file, TextRange range) {
Document document = file.getViewProvider().getDocument();
return new PsiDiagnosticUtils.LineAndColumnRange(
PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getStartOffset()),
PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getEndOffset())
);
}
public static void throwIfRunningOnServer(Throwable e) {
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true") || ApplicationManager.getApplication().isUnitTestMode()) {

View File

@@ -49,7 +49,8 @@ private val DEFAULT_CALL_CHECKERS = listOf(
PrimitiveNumericComparisonCallChecker, LambdaWithSuspendModifierCallChecker,
UselessElvisCallChecker(), ResultTypeWithNullableOperatorsChecker(), NullableVarargArgumentCallChecker,
NamedFunAsExpressionChecker, ContractNotAllowedCallChecker, ReifiedTypeParameterSubstitutionChecker(),
MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker, SuspendConversionCallChecker
MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker, SuspendConversionCallChecker,
UnitConversionCallChecker
)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(

View File

@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.isNull
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.reportTrailingLambdaErrorOr
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
@@ -81,9 +82,10 @@ class DiagnosticReporterByTrackingStrategy(
trace.report(CANDIDATE_CHOSEN_USING_OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION.on(psiKotlinCall.psiCall.callElement))
}
CompatibilityWarning::class.java -> {
val callElement = psiKotlinCall.psiCall.callElement
trace.report(
COMPATIBILITY_WARNING.on(
psiKotlinCall.psiCall.callElement,
callElement.getCalleeExpressionIfAny() ?: callElement,
(diagnostic as CompatibilityWarning).candidate
)
)

View File

@@ -35,25 +35,5 @@ object SuspendConversionCallChecker : CallChecker {
)
)
}
for ((parameter, argument) in resolvedCall.argumentMappingByOriginal) {
if (!parameter.type.isSuspendFunctionType) continue
if (argument !is ResolvedCallArgument.SimpleArgument) continue
val callArgument = argument.callArgument
if (callArgument !is CallableReferenceKotlinCallArgument) continue
val callableReferenceExpression = callArgument.psiExpression as? KtCallableReferenceExpression ?: continue
val argumentCall = callableReferenceExpression.callableReference.getResolvedCall(context.trace.bindingContext) ?: continue
val target = argumentCall.resultingDescriptor as? FunctionDescriptor ?: continue
if (!target.isSuspend) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
callableReferenceExpression,
LanguageFeature.SuspendConversion to context.languageVersionSettings
)
)
}
}
}
}

View File

@@ -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.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl
import org.jetbrains.kotlin.resolve.calls.tower.psiCallArgument
object UnitConversionCallChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
if (resolvedCall !is NewResolvedCallImpl<*>) return
if (context.languageVersionSettings.supportsFeature(LanguageFeature.UnitConversion)) return
// lambdas are working since 1.0, callable references are handled as part of reference adaptation
// => here we're checking only simple argument
val argumentsWithUnitConversion = resolvedCall.resolvedCallAtom.argumentsWithUnitConversion
for (argumentWithUnitConversion in argumentsWithUnitConversion.keys) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
argumentWithUnitConversion.psiCallArgument.valueArgument.asElement(),
LanguageFeature.UnitConversion to context.languageVersionSettings
)
)
}
}
}

View File

@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
import org.jetbrains.kotlin.build.GeneratedFile
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.compilerRunner.MessageCollectorToOutputItemsCollectorAdapter
@@ -353,7 +353,7 @@ abstract class IncrementalCompilerRunner<
}
private class TemporaryMessageCollector(private val delegate: MessageCollector) : MessageCollector {
private class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation?)
private class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageSourceLocation?)
private val messages = ArrayList<Message>()
@@ -361,7 +361,7 @@ private class TemporaryMessageCollector(private val delegate: MessageCollector)
messages.clear()
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
messages.add(Message(severity, message, location))
}

View File

@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.incremental.utils
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import java.util.*
@@ -24,7 +24,7 @@ import java.util.*
class TestMessageCollector : MessageCollector {
val errors = ArrayList<String>()
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
if (severity.isError) {
errors.add(message)
}

View File

@@ -7,8 +7,9 @@ package org.jetbrains.kotlin.backend.common.extensions
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
interface IrGenerationExtension {
interface IrGenerationExtension : IrDeserializer.IrLinkerExtension {
companion object :
ProjectExtensionDescriptor<IrGenerationExtension>(
"org.jetbrains.kotlin.irGenerationExtension", IrGenerationExtension::class.java

View File

@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.IrDeserializer
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.TypeTranslator
import org.jetbrains.kotlin.name.FqName

View File

@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.psi.KtFile
@@ -83,7 +84,7 @@ object JvmBackendFacade {
stubGenerator.setIrProviders(irProviders)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, irProviders, expectDescriptorToSymbol = null)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, irProviders, pluginExtensions, expectDescriptorToSymbol = null)
irLinker.postProcess()
stubGenerator.unboundSymbolGeneration = true

View File

@@ -156,6 +156,7 @@ fun IrSimpleFunction.isCompiledToJvmDefault(jvmDefaultMode: JvmDefaultMode): Boo
assert(!isFakeOverride && parentAsClass.isInterface && modality != Modality.ABSTRACT) {
"`isCompiledToJvmDefault` should be called on non-fakeoverrides and non-abstract methods from interfaces ${ir2string(this)}"
}
if (origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) return false
if (hasJvmDefault()) return true
val parentDescriptor = propertyIfAccessor.parentAsClass.descriptor
if (parentDescriptor !is DeserializedClassDescriptor) return jvmDefaultMode.forAllMethodsWithBody

View File

@@ -171,19 +171,21 @@ private class InterfaceDefaultCallsLowering(val context: JvmBackendContext) : Ir
}
}
private fun IrSimpleFunction.isDefinitelyNotDefaultImplsMethod(jvmDefaultMode: JvmDefaultMode): Boolean {
if (resolveFakeOverride()?.run {
origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB || isCompiledToJvmDefault(
jvmDefaultMode
)
} != false) return true
return origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER ||
internal fun IrSimpleFunction.isDefinitelyNotDefaultImplsMethod(
jvmDefaultMode: JvmDefaultMode,
implementation: IrSimpleFunction? = resolveFakeOverride()
): Boolean =
implementation == null ||
implementation.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB ||
implementation.isCompiledToJvmDefault(jvmDefaultMode) ||
origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER ||
hasAnnotation(PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME) ||
(name.asString() == "clone" &&
parent.safeAs<IrClass>()?.fqNameWhenAvailable?.asString() == "kotlin.Cloneable" &&
valueParameters.isEmpty())
}
isCloneableClone()
private fun IrSimpleFunction.isCloneableClone(): Boolean =
name.asString() == "clone" &&
parent.safeAs<IrClass>()?.fqNameWhenAvailable?.asString() == "kotlin.Cloneable" &&
valueParameters.isEmpty()
internal val interfaceObjectCallsPhase = makeIrFilePhase(
lowering = ::InterfaceObjectCallsLowering,

View File

@@ -105,18 +105,17 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
when {
Visibilities.isPrivate(implementation.visibility) || implementation.isMethodOfAny() ->
continue@loop
!implementation.isCompiledToJvmDefault(jvmDefaultMode) -> {
!function.isDefinitelyNotDefaultImplsMethod(jvmDefaultMode, implementation) -> {
val defaultImpl = createDefaultImpl(function)
val superImpl = firstSuperMethodFromKotlin(function, implementation)
context.declarationFactory.getDefaultImplsFunction(superImpl.owner).also {
defaultImpl.bridgeToStatic(it)
}
}
jvmDefaultMode.isCompatibility -> {
jvmDefaultMode.isCompatibility && implementation.isCompiledToJvmDefault(jvmDefaultMode) -> {
val defaultImpl = createDefaultImpl(function)
defaultImpl.bridgeViaAccessorTo(function)
}
// else -> Do nothing.
}
}

View File

@@ -21,6 +21,8 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
@@ -56,7 +58,7 @@ class Psi2IrTranslator(
val irProviders = generateTypicalIrProviderList(
moduleDescriptor, context.irBuiltIns, context.symbolTable, extensions = generatorExtensions
)
return generateModuleFragment(context, ktFiles, irProviders)
return generateModuleFragment(context, ktFiles, irProviders, emptyList())
}
fun createGeneratorContext(
@@ -74,6 +76,7 @@ class Psi2IrTranslator(
context: GeneratorContext,
ktFiles: Collection<KtFile>,
irProviders: List<IrProvider>,
linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>,
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>? = null
): IrModuleFragment {
val moduleGenerator = ModuleGenerator(context)
@@ -84,7 +87,7 @@ class Psi2IrTranslator(
postprocess(context, irModule)
val deserializers = irProviders.filterIsInstance<IrDeserializer>()
deserializers.forEach { it.init(irModule) }
deserializers.forEach { it.init(irModule, linkerExtensions) }
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)

View File

@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext

View File

@@ -0,0 +1,20 @@
/*
* 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.ir.linkage
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.symbols.IrSymbol
interface IrDeserializer : IrProvider {
interface IrLinkerExtension {
fun resolveSymbol(symbol: IrSymbol): IrDeclaration? = null
}
fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrLinkerExtension>) {}
fun postProcess() {}
}

View File

@@ -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.ir.linkage
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.symbols.IrSymbol
interface IrProvider {
fun getDeclaration(symbol: IrSymbol): IrDeclaration?
}

View File

@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.declarations.lazy.*
import org.jetbrains.kotlin.ir.descriptors.*
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol

View File

@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult

View File

@@ -33,15 +33,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
interface IrProvider {
fun getDeclaration(symbol: IrSymbol): IrDeclaration?
}
interface IrDeserializer : IrProvider {
fun init(moduleFragment: IrModuleFragment?) {}
fun postProcess() {}
}
interface ReferenceSymbolTable {
fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol

View File

@@ -284,7 +284,7 @@ class IrOverridingUtil(
"Unexpected fake override accessor kind: $this"
}
// For descriptors it gets INVISIBLE_FAKE.
if (newVisibility == Visibilities.PRIVATE) return null
if (this.visibility == Visibilities.PRIVATE) return null
this.visibility = newVisibility
this.modality = newModality

View File

@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrLoopBase
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.symbols.impl.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.IrDeserializer
import org.jetbrains.kotlin.ir.util.NaiveSourceBasedFileEntryImpl
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.library.IrLibrary
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.protobuf.CodedInputStream
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite.newInstance
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import org.jetbrains.kotlin.backend.common.serialization.proto.Actual as ProtoActual
import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature as ProtoIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.IrConstructorCall as ProtoConstructorCall
@@ -67,6 +68,8 @@ abstract class KotlinIrLinker(
private val haveSeen = mutableSetOf<IrSymbol>()
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
abstract inner class BasicIrModuleDeserializer(moduleDescriptor: ModuleDescriptor, override val klib: IrLibrary, override val strategy: DeserializationStrategy) :
IrModuleDeserializer(moduleDescriptor) {
@@ -518,6 +521,22 @@ abstract class KotlinIrLinker(
protected open fun platformSpecificSymbol(symbol: IrSymbol): Boolean = false
private fun tryResolveCustomDeclaration(symbol: IrSymbol): IrDeclaration? {
val descriptor = symbol.descriptor
if (descriptor is WrappedDeclarationDescriptor<*>) return null
if (descriptor is CallableMemberDescriptor) {
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
// skip fake overrides
return null
}
}
return linkerExtensions.firstNotNullResult { it.resolveSymbol(symbol) }?.also {
require(symbol.owner == it)
}
}
override fun getDeclaration(symbol: IrSymbol): IrDeclaration? {
if (!symbol.isPublicApi) {
@@ -529,7 +548,7 @@ abstract class KotlinIrLinker(
}
if (!symbol.isBound) {
findDeserializedDeclarationForSymbol(symbol) ?: return null
findDeserializedDeclarationForSymbol(symbol) ?: tryResolveCustomDeclaration(symbol) ?: return null
}
// TODO: we do have serializations for those, but let's just create a stub for now.
@@ -548,7 +567,8 @@ abstract class KotlinIrLinker(
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
CurrentModuleDeserializer(moduleFragment, dependencies)
override fun init(moduleFragment: IrModuleFragment?) {
override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrDeserializer.IrLinkerExtension>) {
linkerExtensions = extensions
if (moduleFragment != null) {
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
deserializersForModules[it] ?: error("No deserializer found for $it")

View File

@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.metadata.KlibMetad
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.acceptVoid
@@ -272,7 +273,7 @@ fun loadIr(
val moduleFragment = deserializedModuleFragments.last()
irLinker.init(null)
irLinker.init(null, emptyList())
ExternalDependenciesGenerator(symbolTable, listOf(irLinker), configuration.languageVersionSettings).generateUnboundSymbolsAsDependencies()
irLinker.postProcess()
@@ -324,7 +325,7 @@ fun GeneratorContext.generateModuleFragmentWithPlugins(
}
}
return psi2Ir.generateModuleFragment(this, files, listOf(irLinker), expectDescriptorToSymbol)
return psi2Ir.generateModuleFragment(this, files, listOf(irLinker), extensions, expectDescriptorToSymbol)
}
private fun createBuiltIns(storageManager: StorageManager) = object : KotlinBuiltIns(storageManager) {}

View File

@@ -116,4 +116,35 @@ public class PsiDiagnosticUtils {
return "(" + line + "," + column + ")";
}
}
public static final class LineAndColumnRange {
public static final LineAndColumnRange NONE = new LineAndColumnRange(LineAndColumn.NONE, LineAndColumn.NONE);
private final LineAndColumn start;
private final LineAndColumn end;
public LineAndColumnRange(LineAndColumn start, LineAndColumn end) {
this.start = start;
this.end = end;
}
public LineAndColumn getStart() {
return start;
}
public LineAndColumn getEnd() {
return end;
}
// NOTE: This method is used for presenting positions to the user
@Override
public String toString() {
if (start.line == end.line) {
return "(" + start.line + "," + start.column + "-" + end.column + ")";
}
return start.toString() + " - " + end.toString();
}
}
}

View File

@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RE
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.EXTENSION_RECEIVER
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
@@ -213,7 +214,7 @@ class CallableReferencesCandidateFactory(
callComponents.builtIns
)
if (needCompatibilityWarning(callableReferenceAdaptation)) {
if (needCompatibilityResolveForCallableReference(callableReferenceAdaptation, candidateDescriptor)) {
diagnostics.add(LowerPriorityToPreserveCompatibility)
}
@@ -261,7 +262,13 @@ class CallableReferencesCandidateFactory(
)
}
private fun needCompatibilityWarning(callableReferenceAdaptation: CallableReferenceAdaptation?): Boolean {
private fun needCompatibilityResolveForCallableReference(
callableReferenceAdaptation: CallableReferenceAdaptation?,
candidate: CallableDescriptor
): Boolean {
// KT-13934: reference to companion object member via class name
if (candidate.containingDeclaration.isCompanionObject() && argument.lhsResult is LHSResult.Type) return true
if (callableReferenceAdaptation == null) return false
return callableReferenceAdaptation.defaults != 0 ||

View File

@@ -429,7 +429,7 @@ private fun KotlinResolutionCandidate.resolveKotlinArgument(
val unsubstitutedExpectedType = conversionDataBeforeSubtyping?.convertedType ?: candidateExpectedType
val expectedType = unsubstitutedExpectedType?.let { prepareExpectedType(it) }
val convertedArgument = if (expectedType != null && shouldRunConversionForConstants(expectedType)) {
val convertedArgument = if (expectedType != null && !isReceiver && shouldRunConversionForConstants(expectedType)) {
val convertedConstant = resolutionCallbacks.convertSignedConstantToUnsigned(argument)
if (convertedConstant != null) {
resolvedCall.registerArgumentWithConstantConversion(argument, convertedConstant)

View File

@@ -87,7 +87,7 @@ object SamTypeConversions : ParameterTypeConversion {
SamConversionDescription(convertedTypeByOriginal, convertedTypeByCandidate!!)
)
if (needCompatibilityResolve(candidate, expectedParameterType)) {
if (needCompatibilityResolveForSAM(candidate, expectedParameterType)) {
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
}
@@ -99,7 +99,7 @@ object SamTypeConversions : ParameterTypeConversion {
return convertedTypeByCandidate
}
private fun needCompatibilityResolve(candidate: KotlinResolutionCandidate, typeToConvert: UnwrappedType): Boolean {
private fun needCompatibilityResolveForSAM(candidate: KotlinResolutionCandidate, typeToConvert: UnwrappedType): Boolean {
// fun interfaces is a new feature with a new modifier, so no compatibility resolve is needed
val descriptor = typeToConvert.constructor.declarationDescriptor
if (descriptor is ClassDescriptor && descriptor.isFun) return false

View File

@@ -0,0 +1,86 @@
/*
* 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.calls.components
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.isUnit
object UnitTypeConversions : ParameterTypeConversion {
override fun conversionDefinitelyNotNeeded(
candidate: KotlinResolutionCandidate,
argument: KotlinCallArgument,
expectedParameterType: UnwrappedType
): Boolean {
// for callable references and lambdas it already works
if (argument !is SimpleKotlinCallArgument) return true
val receiver = argument.receiver
if (receiver.receiverValue.type.hasUnitOrSubtypeReturnType()) return true
if (receiver.typesFromSmartCasts.any { it.hasUnitOrSubtypeReturnType() }) return true
if (
!expectedParameterType.isBuiltinFunctionalType ||
!expectedParameterType.getReturnTypeFromFunctionType().isUnit()
) return true
return false
}
private fun KotlinType.hasUnitOrSubtypeReturnType(): Boolean =
isFunctionOrKFunctionTypeWithAnySuspendability && arguments.last().type.isUnitOrSubtype()
private fun KotlinType.isUnitOrSubtype(): Boolean = isUnit() || isDynamic() || isNothing()
override fun conversionIsNeededBeforeSubtypingCheck(argument: KotlinCallArgument): Boolean =
argument is SimpleKotlinCallArgument && argument.receiver.stableType.isFunctionType
override fun conversionIsNeededAfterSubtypingCheck(argument: KotlinCallArgument): Boolean {
if (argument !is SimpleKotlinCallArgument) return false
var isFunctionTypeOrSubtype = false
val hasReturnTypeInSubtypes = argument.receiver.stableType.isFunctionTypeOrSubtype {
isFunctionTypeOrSubtype = true
it.getReturnTypeFromFunctionType().isUnitOrSubtype()
}
if (!isFunctionTypeOrSubtype) return false
return !hasReturnTypeInSubtypes
}
override fun convertParameterType(
candidate: KotlinResolutionCandidate,
argument: KotlinCallArgument,
parameter: ParameterDescriptor,
expectedParameterType: UnwrappedType
): UnwrappedType? {
val nonUnitReturnedParameterType = createFunctionType(
candidate.callComponents.builtIns,
expectedParameterType.annotations,
expectedParameterType.getReceiverTypeFromFunctionType(),
expectedParameterType.getValueParameterTypesFromFunctionType().map { it.type },
parameterNames = null,
candidate.callComponents.builtIns.nullableAnyType,
suspendFunction = expectedParameterType.isSuspendFunctionType
)
candidate.resolvedCall.registerArgumentWithUnitConversion(argument, nonUnitReturnedParameterType)
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
return nonUnitReturnedParameterType
}
}

View File

@@ -40,14 +40,23 @@ object TypeConversions {
)
val suspendConversionData = performConversionBeforeSubtyping(
candidate, argument, candidateParameter, samConversionData.convertedType ?: candidateExpectedType, SuspendTypeConversions
candidate, argument, candidateParameter,
candidateExpectedType = samConversionData.convertedType ?: candidateExpectedType,
SuspendTypeConversions
)
val unitConversionData = performConversionBeforeSubtyping(
candidate, argument, candidateParameter,
candidateExpectedType = suspendConversionData.convertedType ?: samConversionData.convertedType ?: candidateExpectedType,
UnitTypeConversions
)
return ConversionData(
convertedType = suspendConversionData.convertedType ?: samConversionData.convertedType,
wasConversion = samConversionData.wasConversion || suspendConversionData.wasConversion,
convertedType = unitConversionData.convertedType ?: suspendConversionData.convertedType ?: samConversionData.convertedType,
wasConversion = samConversionData.wasConversion || suspendConversionData.wasConversion || unitConversionData.wasConversion,
conversionDefinitelyNotNeeded = samConversionData.conversionDefinitelyNotNeeded &&
suspendConversionData.conversionDefinitelyNotNeeded
suspendConversionData.conversionDefinitelyNotNeeded &&
unitConversionData.conversionDefinitelyNotNeeded
)
}
@@ -61,9 +70,19 @@ object TypeConversions {
candidate, argument, candidateParameter, candidateExpectedType, SamTypeConversions
)
if (samConvertedType != null) return samConvertedType
val suspendConvertedType = performConversionAfterSubtyping(
candidate, argument, candidateParameter,
candidateExpectedType = samConvertedType ?: candidateExpectedType,
SuspendTypeConversions
)
return performConversionAfterSubtyping(candidate, argument, candidateParameter, candidateExpectedType, SuspendTypeConversions)
val unitConvertedType = performConversionAfterSubtyping(
candidate, argument, candidateParameter,
candidateExpectedType = suspendConvertedType ?: samConvertedType ?: candidateExpectedType,
UnitTypeConversions
)
return unitConvertedType ?: suspendConvertedType ?: samConvertedType
}
private fun performConversionAfterSubtyping(

View File

@@ -69,6 +69,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() {
abstract val knownParametersSubstitutor: TypeSubstitutor
abstract val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
abstract val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
abstract val argumentsWithUnitConversion: Map<KotlinCallArgument, UnwrappedType>
abstract val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
}

View File

@@ -193,6 +193,7 @@ class MutableResolvedCallAtom(
lateinit var argumentToCandidateParameter: Map<KotlinCallArgument, ValueParameterDescriptor>
private var samAdapterMap: HashMap<KotlinCallArgument, SamConversionDescription>? = null
private var suspendAdapterMap: HashMap<KotlinCallArgument, UnwrappedType>? = null
private var unitAdapterMap: HashMap<KotlinCallArgument, UnwrappedType>? = null
private var signedUnsignedConstantConversions: HashMap<KotlinCallArgument, IntegerValueTypeConstant>? = null
val hasSamConversion: Boolean
@@ -207,6 +208,9 @@ class MutableResolvedCallAtom(
override val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
get() = suspendAdapterMap ?: emptyMap()
override val argumentsWithUnitConversion: Map<KotlinCallArgument, UnwrappedType>
get() = unitAdapterMap ?: emptyMap()
override val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
get() = signedUnsignedConstantConversions ?: emptyMap()
@@ -224,6 +228,13 @@ class MutableResolvedCallAtom(
suspendAdapterMap!![argument] = convertedType
}
fun registerArgumentWithUnitConversion(argument: KotlinCallArgument, convertedType: UnwrappedType) {
if (unitAdapterMap == null)
unitAdapterMap = hashMapOf()
unitAdapterMap!![argument] = convertedType
}
fun registerArgumentWithConstantConversion(argument: KotlinCallArgument, convertedConstant: IntegerValueTypeConstant) {
if (signedUnsignedConstantConversions == null)
signedUnsignedConstantConversions = hashMapOf()

View File

@@ -0,0 +1,32 @@
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS
class A {
companion object {
fun foo(): String = "OK"
}
}
class B {
companion object {
fun foo(): String = "Fail"
}
}
fun B.foo(): String = "OK"
fun call(f: Any): String = if (f is Function0<*>) f.invoke() as String else (f as Function1<B, String>).invoke(B())
fun box(): String {
val call1 = call(A::foo)
if (call1 != "OK") return "fail 1: $call1"
// Checking compatibility mode: should be resolved to extensions in 1.4
val call2 = call(B::foo)
if (call2 != "OK") return "fail 2: $call2"
return "OK"
}

View File

@@ -1,5 +1,6 @@
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument
// IGNORE_BACKEND_FIR: JVM_IR
// SKIP_DCE_DRIVEN
fun interface MyRunnable {
fun run()

View File

@@ -12,6 +12,8 @@ fun rn(i: I) = i.f()
inline fun rnInline(i: I) = i.f()
inline fun rnInlineCtor(s: String) = I { s + ".m1" }
// MODULE: m2(m1)
// FILE: m2.kt
@@ -19,12 +21,26 @@ fun rn2(f: () -> String) = rn(f)
inline fun rn2Inline(noinline f: () -> String) = rnInline(f)
inline fun rnInlineCtorProxy(s: String) = rnInlineCtor(s + ".m2").f()
fun interface II {
fun f(): String
}
// MODULE: main(m2)
// FILE: main.kt
fun id(i: II) = i
fun box(): String {
if (rn2Inline { "inline" } != "inline") return "fail"
if (id { "1" }.f() != "1") return "fail 1"
if (II { "2" }.f() != "2") return "fail 2"
if (rnInlineCtorProxy("3") != "3.m2.m1") return "fail 3"
if (rn2Inline { "inline" } != "inline") return "fail 4"
return rn2 { "OK" }
}

View File

@@ -0,0 +1,16 @@
// !LANGUAGE: +InlineClasses -MangleClassMembersReturningInlineClasses
// WITH_RUNTIME
// TARGET_BACKEND: JVM
inline class S(val x: String)
class Test {
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("getO")
fun getOK() = S("OK")
}
fun box(): String {
val t = Test()
return t.getOK().x
}

View File

@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses -MangleClassMembersReturningInlineClasses
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// FILE: 1.kt
package test
inline class S(val string: String)
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("foo")
inline fun foo() = S("OK")
// FILE: 2.kt
import test.*
fun box() : String =
foo().string

View File

@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses +MangleClassMembersReturningInlineClasses
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// FILE: 1.kt
package test
inline class S(val string: String)
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("foo")
inline fun foo() = S("OK")
// FILE: 2.kt
import test.*
fun box() : String =
foo().string

View File

@@ -0,0 +1,18 @@
// !JVM_DEFAULT_MODE: all-compatibility
// JVM_TARGET: 1.8
// FULL_JDK
// FILE: J.java
public interface J {
default void foo() {}
}
// FILE: K.kt
interface K : J
interface MyList<T> : MutableList<T>
interface MySet<E> : MutableSet<E>
interface MyMap<K, V> : MutableMap<K, V>
interface MyMap2<X, Y> : MyMap<X, Y>

View File

@@ -0,0 +1,14 @@
@kotlin.Metadata
public interface K
@kotlin.Metadata
public interface MyList
@kotlin.Metadata
public interface MyMap
@kotlin.Metadata
public interface MyMap2
@kotlin.Metadata
public interface MySet

View File

@@ -0,0 +1,17 @@
// JVM_TARGET: 1.8
// FULL_JDK
// FILE: J.java
public interface J {
default void foo() {}
}
// FILE: K.kt
interface K : J
interface MyList<T> : MutableList<T>
interface MySet<E> : MutableSet<E>
interface MyMap<K, V> : MutableMap<K, V>
interface MyMap2<X, Y> : MyMap<X, Y>

View File

@@ -0,0 +1,14 @@
@kotlin.Metadata
public interface K
@kotlin.Metadata
public interface MyList
@kotlin.Metadata
public interface MyMap
@kotlin.Metadata
public interface MyMap2
@kotlin.Metadata
public interface MySet

View File

@@ -0,0 +1,21 @@
// WITH_RUNTIME
inline class IC(val x: Int)
class C {
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("test")
fun test() = IC(42)
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("differentName")
fun test2() = IC(42)
}
fun call1() = C().test()
fun call2() = C().test2()
// 1 public final test\(\)I
// 1 INVOKEVIRTUAL C.test \(\)I
// 1 public final differentName\(\)I
// 1 INVOKEVIRTUAL C.differentName \(\)I

View File

@@ -0,0 +1,37 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class A {
companion object {
fun foo(): Int = 0
}
}
class B {
fun foo(): String = ""
companion object {
fun foo(): Int = 0
}
}
fun <T> call(f: () -> T): T = f()
fun testA(a: A) {
val call1 = call(A::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call1<!>
val call2 = call(A.Companion::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call2<!>
}
fun testB(b: B) {
val call1 = call(B::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call1<!>
val call2 = call(B()::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>call2<!>
val call3 = call(B.Companion::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call3<!>
}

View File

@@ -0,0 +1,36 @@
package
public fun </*0*/ T> call(/*0*/ f: () -> T): T
public fun testA(/*0*/ a: A): kotlin.Unit
public fun testB(/*0*/ b: B): kotlin.Unit
public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}

View File

@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class A {
companion object {
fun foo(): Int = 0
}
}
fun A.foo(): Double = 0.0
fun Any.foo(): Float = 1f
class B {
fun foo(): String = ""
companion object {
fun foo(): Int = 0
}
}
fun B.foo(): Double = 0.0
fun call(a: Any) {}
fun testA(a: A) {
call(A::foo)
call(A.Companion::foo)
}
fun testB(b: B) {
call(B::foo)
call(B()::foo)
call(B.Companion::foo)
}

View File

@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class A {
companion object {
fun foo(): Int = 0
}
}
fun A.foo(): Double = 0.0
fun Any.foo(): Float = 1f
class B {
fun foo(): String = ""
companion object {
fun foo(): Int = 0
}
}
fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>foo<!>(): Double = 0.0
fun call(a: Any) {}
fun testA(a: A) {
call(<!COMPATIBILITY_WARNING!>A::foo<!>)
call(A.Companion::foo)
}
fun testB(b: B) {
call(B::foo)
call(B()::foo)
call(B.Companion::foo)
}

View File

@@ -0,0 +1,39 @@
package
public fun call(/*0*/ a: kotlin.Any): kotlin.Unit
public fun testA(/*0*/ a: A): kotlin.Unit
public fun testB(/*0*/ b: B): kotlin.Unit
public fun A.foo(): kotlin.Double
public fun B.foo(): kotlin.Double
public fun kotlin.Any.foo(): kotlin.Float
public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}

View File

@@ -18,7 +18,7 @@ object Test1 {
fun foo(r: Runnable) {}
fun test(f: () -> Unit) {
<!COMPATIBILITY_WARNING, DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!>foo(f)<!>
<!DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!><!COMPATIBILITY_WARNING!>foo<!>(f)<!>
}
}
}
@@ -65,7 +65,7 @@ object Test5 {
fun foo(r: Runnable) {}
fun test() {
<!COMPATIBILITY_WARNING, DEBUG_INFO_CALL("fqName: Test5.foo; typeCall: function")!>foo { }<!>
<!DEBUG_INFO_CALL("fqName: Test5.foo; typeCall: function")!><!COMPATIBILITY_WARNING!>foo<!> { }<!>
}
}
}

View File

@@ -12,7 +12,7 @@ object Test1 {
fun call(r: SuspendRunnable) {}
fun bar(f: () -> Unit) {
<!COMPATIBILITY_WARNING, DEBUG_INFO_CALL("fqName: Test1.call; typeCall: function")!>call(f)<!>
<!DEBUG_INFO_CALL("fqName: Test1.call; typeCall: function")!><!COMPATIBILITY_WARNING!>call<!>(f)<!>
}
}
}

View File

@@ -8,7 +8,7 @@ object Test1 {
fun foo(f: suspend () -> Unit) {}
fun test(g: () -> Unit) {
<!COMPATIBILITY_WARNING, DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!>foo(g)<!>
<!DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!><!COMPATIBILITY_WARNING!>foo<!>(g)<!>
}
}
}

View File

@@ -10,7 +10,7 @@ object Test1 {
fun bar(x: Int = 42): String = ""
fun test() {
val result = foo(<!UNSUPPORTED_FEATURE!>::bar<!>)
val result = foo(::bar)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>result<!>
}
}

View File

@@ -20,7 +20,7 @@ fun test(
foo2(<!UNSUPPORTED_FEATURE!>f2<!>)
foo3(<!UNSUPPORTED_FEATURE!>f3<!>)
foo1(<!UNSUPPORTED_FEATURE!>::bar<!>)
foo1(::bar)
foo1(<!TYPE_MISMATCH, UNSUPPORTED_FEATURE!>f2<!>)
foo1(<!TYPE_MISMATCH, UNSUPPORTED_FEATURE!>f3<!>)

View File

@@ -0,0 +1,18 @@
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface SuspendRunnable {
suspend fun run()
}
fun foo(r: SuspendRunnable) {}
fun bar(): String = ""
abstract class SubInt : () -> Int
fun test(f: () -> String, s: SubInt) {
<!INAPPLICABLE_CANDIDATE!>foo<!>(f)
<!INAPPLICABLE_CANDIDATE!>foo<!>(s)
<!INAPPLICABLE_CANDIDATE!>foo<!>(::bar)
}

View File

@@ -0,0 +1,18 @@
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface SuspendRunnable {
suspend fun run()
}
fun foo(r: SuspendRunnable) {}
fun bar(): String = ""
abstract class SubInt : () -> Int
fun test(f: () -> String, s: SubInt) {
foo(f)
foo(s)
foo(::bar)
}

View File

@@ -0,0 +1,20 @@
package
public fun bar(): kotlin.String
public fun foo(/*0*/ r: SuspendRunnable): kotlin.Unit
public fun test(/*0*/ f: () -> kotlin.String, /*1*/ s: SubInt): kotlin.Unit
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public fun interface SuspendRunnable {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract suspend fun run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,15 @@
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface KRunnable {
fun run()
}
fun foo(r: KRunnable) {}
abstract class SubInt : () -> Int
fun test(f: () -> Int, s: SubInt) {
<!INAPPLICABLE_CANDIDATE!>foo<!>(f)
<!INAPPLICABLE_CANDIDATE!>foo<!>(s)
}

View File

@@ -0,0 +1,15 @@
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun interface KRunnable {
fun run()
}
fun foo(r: KRunnable) {}
abstract class SubInt : () -> Int
fun test(f: () -> Int, s: SubInt) {
foo(f)
foo(s)
}

View File

@@ -0,0 +1,19 @@
package
public fun foo(/*0*/ r: KRunnable): kotlin.Unit
public fun test(/*0*/ f: () -> kotlin.Int, /*1*/ s: SubInt): kotlin.Unit
public fun interface KRunnable {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,14 @@
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun foo(f: suspend () -> Unit) {}
fun bar(): String = ""
abstract class SubInt : () -> Int
fun test(g: () -> Double, s: SubInt) {
<!INAPPLICABLE_CANDIDATE!>foo<!>(::bar)
<!INAPPLICABLE_CANDIDATE!>foo<!>(g)
<!INAPPLICABLE_CANDIDATE!>foo<!>(s)
}

View File

@@ -0,0 +1,14 @@
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun foo(f: suspend () -> Unit) {}
fun bar(): String = ""
abstract class SubInt : () -> Int
fun test(g: () -> Double, s: SubInt) {
foo(::bar)
foo(g)
foo(s)
}

View File

@@ -0,0 +1,13 @@
package
public fun bar(): kotlin.String
public fun foo(/*0*/ f: suspend () -> kotlin.Unit): kotlin.Unit
public fun test(/*0*/ g: () -> kotlin.Double, /*1*/ s: SubInt): kotlin.Unit
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,29 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
object Test1 {
fun foo(f: () -> Int) {}
object Scope {
fun foo(f: () -> Unit) {}
fun test(f: () -> Int) {
<!DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!>foo(f)<!>
}
}
}
object Test2 {
fun interface KRunnable {
fun run()
}
fun foo(f: () -> Unit) {}
object Scope1 {
fun foo(f: KRunnable) {}
fun test(f: () -> Int) {
<!DEBUG_INFO_CALL("fqName: fqName is unknown; typeCall: unresolved")!><!INAPPLICABLE_CANDIDATE!>foo<!>(f)<!>
}
}
}

View File

@@ -0,0 +1,29 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
object Test1 {
fun foo(f: () -> Int) {}
object Scope {
fun foo(f: () -> Unit) {}
fun test(f: () -> Int) {
<!DEBUG_INFO_CALL("fqName: Test1.foo; typeCall: function")!><!COMPATIBILITY_WARNING!>foo<!>(f)<!>
}
}
}
object Test2 {
fun interface KRunnable {
fun run()
}
fun foo(f: () -> Unit) {}
object Scope1 {
fun foo(f: KRunnable) {}
fun test(f: () -> Int) {
<!DEBUG_INFO_CALL("fqName: Test2.Scope1.foo; typeCall: function")!>foo(<!UNSUPPORTED_FEATURE!>f<!>)<!>
}
}
}

View File

@@ -0,0 +1,42 @@
package
public object Test1 {
private constructor Test1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ f: () -> kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public object Scope {
private constructor Scope()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(/*0*/ f: () -> kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public object Test2 {
private constructor Test2()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public fun interface KRunnable {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object Scope1 {
private constructor Scope1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ f: Test2.KRunnable): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(/*0*/ f: () -> kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}

View File

@@ -0,0 +1,22 @@
// !LANGUAGE: -UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun foo(f: () -> Unit) {}
fun bar(): Int = 0
abstract class SubInt : () -> Int
fun <T> T.freeze(): T = TODO()
fun test(f: () -> String, g: () -> Nothing, h: () -> Nothing?, s: SubInt) {
foo { "lambda" }
foo(::bar)
foo({ TODO() }.freeze())
foo(g)
<!INAPPLICABLE_CANDIDATE!>foo<!>(h)
<!INAPPLICABLE_CANDIDATE!>foo<!>(f)
<!INAPPLICABLE_CANDIDATE!>foo<!>(s)
}

View File

@@ -0,0 +1,22 @@
// !LANGUAGE: -UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun foo(f: () -> Unit) {}
fun bar(): Int = 0
abstract class SubInt : () -> Int
fun <T> T.freeze(): T = TODO()
fun test(f: () -> String, g: () -> Nothing, h: () -> Nothing?, s: SubInt) {
foo { "lambda" }
foo(::bar)
foo({ TODO() }.freeze())
foo(g)
foo(<!UNSUPPORTED_FEATURE!>h<!>)
foo(<!UNSUPPORTED_FEATURE!>f<!>)
foo(<!UNSUPPORTED_FEATURE!>s<!>)
}

View File

@@ -0,0 +1,14 @@
package
public fun bar(): kotlin.Int
public fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public fun test(/*0*/ f: () -> kotlin.String, /*1*/ g: () -> kotlin.Nothing, /*2*/ h: () -> kotlin.Nothing?, /*3*/ s: SubInt): kotlin.Unit
public fun </*0*/ T> T.freeze(): T
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,16 @@
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun foo(f: () -> Unit) {}
fun <T> fooGeneric(f: (T) -> Unit): T = TODO()
fun bar(): String = ""
fun createCall(): () -> Int = TODO()
fun test(g: () -> String, h: (Float) -> String) {
foo(::bar)
foo { "something" }
<!INAPPLICABLE_CANDIDATE!>foo<!>(g)
<!INAPPLICABLE_CANDIDATE!>fooGeneric<!>(h)
}

Some files were not shown because too many files have changed in this diff Show More