[NI] Prototype for SAM-conversion.

Supported:
- conversion in resolution parts. Also sam-with-receiver is supported automatically
- separate flag for kotlin function with java SAM as parameters

TODO:
- fix overload conflict error when function type is the same byte origin types is ordered
- consider case when parameter type is T, T <:> Runnable
- support vararg of Runnable

[NI] Turn off synthetic scope with SAM adapter functions if NI enabled
This commit is contained in:
Stanislav Erokhin
2018-05-01 23:46:15 +03:00
parent 4b8e95c243
commit 8f0b073c08
48 changed files with 889 additions and 26 deletions
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.SmartList;
import com.intellij.util.containers.Stack;
import kotlin.Pair;
import kotlin.collections.CollectionsKt;
@@ -44,6 +45,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl;
import org.jetbrains.kotlin.resolve.calls.tower.NewVariableAsFunctionResolvedCallImpl;
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.EnumValue;
import org.jetbrains.kotlin.resolve.constants.NullValue;
@@ -694,18 +697,54 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
CallableDescriptor descriptor = call.getResultingDescriptor();
if (!(descriptor instanceof FunctionDescriptor)) return;
recordSamValueForNewInference(call);
recordSamConstructorIfNeeded(expression, call);
FunctionDescriptor original = SamCodegenUtil.getOriginalIfSamAdapter((FunctionDescriptor) descriptor);
if (original == null) return;
List<ResolvedValueArgument> valueArguments = call.getValueArgumentsByIndex();
if (valueArguments == null) return;
List<ValueParameterDescriptor> valueParametersWithSAMConversion = new SmartList<>();
for (ValueParameterDescriptor valueParameter : original.getValueParameters()) {
ValueParameterDescriptor adaptedParameter = descriptor.getValueParameters().get(valueParameter.getIndex());
if (KotlinTypeChecker.DEFAULT.equalTypes(adaptedParameter.getType(), valueParameter.getType())) continue;
valueParametersWithSAMConversion.add(valueParameter);
}
writeSamValueForValueParameters(valueParametersWithSAMConversion, call.getValueArgumentsByIndex());
}
private void recordSamValueForNewInference(@NotNull ResolvedCall<?> call) {
NewResolvedCallImpl<?> newResolvedCall = null;
if (call instanceof NewVariableAsFunctionResolvedCallImpl) {
newResolvedCall = ((NewVariableAsFunctionResolvedCallImpl) call).getFunctionCall();
}
else if(call instanceof NewResolvedCallImpl) {
newResolvedCall = (NewResolvedCallImpl<?>) call;
}
if (newResolvedCall == null) return;
List<ValueParameterDescriptor> valueParametersWithSAMConversion = new SmartList<>();
Map<ValueParameterDescriptor, ResolvedValueArgument> arguments = newResolvedCall.getValueArguments();
for (ValueParameterDescriptor valueParameter : arguments.keySet()) {
ResolvedValueArgument argument = arguments.get(valueParameter);
if (!(argument instanceof ExpressionValueArgument)) continue;
ValueArgument valueArgument = ((ExpressionValueArgument) argument).getValueArgument();
if (valueArgument == null || newResolvedCall.getExpectedTypeForSamConvertedArgument(valueArgument) == null) continue;
valueParametersWithSAMConversion.add(valueParameter.getOriginal());
}
writeSamValueForValueParameters(valueParametersWithSAMConversion, newResolvedCall.getValueArgumentsByIndex());
}
private void writeSamValueForValueParameters(
@NotNull Collection<ValueParameterDescriptor> valueParametersWithSAMConversion,
@Nullable List<ResolvedValueArgument> valueArguments
) {
if (valueArguments == null) return;
for (ValueParameterDescriptor valueParameter : valueParametersWithSAMConversion) {
SamType samType = SamType.createByValueParameter(valueParameter);
if (samType == null) continue;
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. 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.load.java.sam
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.load.java.components.SamConversionResolver
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
import org.jetbrains.kotlin.synthetic.hasJavaOriginInHierarchy
import org.jetbrains.kotlin.types.UnwrappedType
class JvmSamConversionTransformer(
private val samResolver: SamConversionResolver,
private val languageVersionSettings: LanguageVersionSettings
) : SamConversionTransformer {
override fun getFunctionTypeForPossibleSamType(possibleSamType: UnwrappedType): UnwrappedType? =
SingleAbstractMethodUtils.getFunctionTypeForSamType(possibleSamType, samResolver)?.unwrap()
override fun shouldRunSamConversionForFunction(candidate: CallableDescriptor): Boolean {
if (languageVersionSettings.supportsFeature(LanguageFeature.SamConversionForKotlinFunctions)) return true
val functionDescriptor = candidate.original as? FunctionDescriptor ?: return false
if (functionDescriptor is TypeAliasConstructorDescriptor &&
functionDescriptor.underlyingConstructorDescriptor is JavaClassConstructorDescriptor) return true
return functionDescriptor.hasJavaOriginInHierarchy()
}
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.platform
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useImpl
import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.load.java.sam.JvmSamConversionTransformer
import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.resolve.PlatformConfigurator
@@ -97,5 +98,6 @@ object JvmPlatformConfigurator : PlatformConfigurator(
container.useImpl<JvmModuleAccessibilityChecker.ClassifierUsage>()
container.useInstance(JvmTypeSpecificityComparator)
container.useImpl<JvmDefaultSuperCallChecker>()
container.useImpl<JvmSamConversionTransformer>()
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.synthetic
import com.intellij.util.SmartList
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -59,6 +60,8 @@ class SamAdapterFunctionsScope(
private val deprecationResolver: DeprecationResolver,
private val lookupTracker: LookupTracker
) : SyntheticScope {
private val samViaSyntheticScopeDisabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
private val extensionForFunction =
storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
extensionForFunctionNotCached(function)
@@ -95,6 +98,8 @@ class SamAdapterFunctionsScope(
}
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
if (samViaSyntheticScopeDisabled) return emptyList()
var result: SmartList<FunctionDescriptor>? = null
for (type in receiverTypes) {
for (function in type.memberScope.getContributedFunctions(name, location)) {
@@ -134,6 +139,8 @@ class SamAdapterFunctionsScope(
}
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
if (samViaSyntheticScopeDisabled) return emptyList()
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
type.memberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
.filterIsInstance<FunctionDescriptor>()
@@ -148,12 +155,17 @@ class SamAdapterFunctionsScope(
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
if (samViaSyntheticScopeDisabled) return emptyList()
return getSamFunctions(scope.getContributedFunctions(name, location), location)
}
override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
val classifier = scope.getContributedClassifier(name, location) ?: return emptyList()
recordSamLookupsToClassifier(classifier, location)
if (samViaSyntheticScopeDisabled) return listOfNotNull(getSamConstructor(classifier))
return getAllSamConstructors(classifier)
}
@@ -166,16 +178,22 @@ class SamAdapterFunctionsScope(
}
override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor> {
if (samViaSyntheticScopeDisabled) return emptyList()
return getSamFunctions(scope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS), location = null)
}
override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor> {
return scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS)
.filterIsInstance<ClassifierDescriptor>()
.flatMap { getAllSamConstructors(it) }
val classifiers = scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance<ClassifierDescriptor>()
if (samViaSyntheticScopeDisabled) return classifiers.mapNotNull { getSamConstructor(it) }
return classifiers.flatMap { getAllSamConstructors(it) }
}
override fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor? {
if (samViaSyntheticScopeDisabled) return null
return when (constructor) {
is JavaClassConstructorDescriptor -> createJavaSamAdapterConstructor(constructor)
is TypeAliasConstructorDescriptor -> {
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.UserDataProperty
import org.jetbrains.kotlin.resolve.calls.checkers.*
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
import org.jetbrains.kotlin.resolve.checkers.*
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
@@ -62,6 +63,7 @@ abstract class TargetPlatform(val platformName: String) {
) {
override fun configureModuleComponents(container: StorageComponentContainer) {
container.useInstance(SyntheticScopes.Empty)
container.useInstance(SamConversionTransformer.Empty)
container.useInstance(TypeSpecificityComparator.NONE)
}
}
@@ -209,10 +209,14 @@ class KotlinToResolvedCallTransformer(
for (valueArgument in resolvedCall.call.valueArguments) {
val argumentMapping = resolvedCall.getArgumentMapping(valueArgument!!)
val (expectedType, callPosition) = when (argumentMapping) {
is ArgumentMatch -> Pair(
getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument, context),
CallPosition.ValueArgumentPosition(resolvedCall, argumentMapping.valueParameter, valueArgument)
)
is ArgumentMatch -> {
val expectedType = resolvedCall.getExpectedTypeForSamConvertedArgument(valueArgument)
?: getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument, context)
Pair(
expectedType,
CallPosition.ValueArgumentPosition(resolvedCall, argumentMapping.valueParameter, valueArgument)
)
}
else -> Pair(TypeUtils.NO_EXPECTED_TYPE, CallPosition.Unknown)
}
val newContext =
@@ -522,6 +526,8 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
private var extensionReceiver = resolvedCallAtom.extensionReceiverArgument?.receiver?.receiverValue
private var dispatchReceiver = resolvedCallAtom.dispatchReceiverArgument?.receiver?.receiverValue
private var smartCastDispatchReceiverType: KotlinType? = null
private var expedtedTypeForSamConvertedArgumentMap: MutableMap<ValueArgument, UnwrappedType>? = null
override val kotlinCall: KotlinCall get() = resolvedCallAtom.atom
@@ -610,6 +616,22 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
val substituted = (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType)
TypeApproximator().approximateToSuperType(substituted, TypeApproximatorConfiguration.CapturedTypesApproximation) ?: substituted
}
calculateExpedtedTypeForSamConvertedArgumentMap(substitutor)
}
fun getExpectedTypeForSamConvertedArgument(valueArgument: ValueArgument): UnwrappedType? =
expedtedTypeForSamConvertedArgumentMap?.get(valueArgument)
private fun calculateExpedtedTypeForSamConvertedArgumentMap(substitutor: NewTypeSubstitutor?) {
if (resolvedCallAtom.argumentsWithConversion.isEmpty()) return
expedtedTypeForSamConvertedArgumentMap = hashMapOf()
for ((argument, description) in resolvedCallAtom.argumentsWithConversion) {
val typeWithFreshVariables = resolvedCallAtom.substitutor.safeSubstitute(description.convertedTypeByCandidateParameter)
val expectedType = substitutor?.safeSubstitute(typeWithFreshVariables) ?: typeWithFreshVariables
expedtedTypeForSamConvertedArgumentMap!![argument.psiCallArgument.valueArgument] = expectedType
}
}
init {
@@ -49,4 +49,15 @@ interface KotlinResolutionCallbacks {
fun isCompileTimeConstant(resolvedAtom: ResolvedCallAtom, expectedType: UnwrappedType): Boolean
val inferenceSession: InferenceSession
}
interface SamConversionTransformer {
fun getFunctionTypeForPossibleSamType(possibleSamType: UnwrappedType): UnwrappedType?
fun shouldRunSamConversionForFunction(candidate: CallableDescriptor): Boolean
object Empty : SamConversionTransformer {
override fun getFunctionTypeForPossibleSamType(possibleSamType: UnwrappedType): UnwrappedType? = null
override fun shouldRunSamConversionForFunction(candidate: CallableDescriptor): Boolean = false
}
}
@@ -61,7 +61,7 @@ class NewOverloadingConflictResolver(
} else {
val originalValueParameter = originalValueParameters[valueParameter.index]
for (valueArgument in resolvedValueArgument.arguments) {
valueArgumentToParameterType[valueArgument] =
valueArgumentToParameterType[valueArgument] = candidate.resolvedCall.argumentsWithConversion[valueArgument]?.convertedTypeByOriginParameter ?:
valueArgument.getExpectedType(originalValueParameter, candidate.callComponents.languageVersionSettings)
}
}
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.builtins.getFunctionalClassKind
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
@@ -21,6 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.anySuperTypeConstructor
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
internal object CheckInstantiationOfAbstractClass : ResolutionPart() {
@@ -28,7 +31,8 @@ internal object CheckInstantiationOfAbstractClass : ResolutionPart() {
val candidateDescriptor = resolvedCall.candidateDescriptor
if (candidateDescriptor is ConstructorDescriptor &&
!callComponents.statelessCallbacks.isSuperOrDelegatingConstructorCall(resolvedCall.atom)) {
!callComponents.statelessCallbacks.isSuperOrDelegatingConstructorCall(resolvedCall.atom)
) {
if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) {
addDiagnostic(InstantiationOfAbstractClass)
}
@@ -244,11 +248,48 @@ private fun KotlinResolutionCandidate.prepareExpectedType(
argument: KotlinCallArgument,
candidateParameter: ParameterDescriptor
): UnwrappedType {
val argumentType = argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings)
val argumentType = getExpectedTypeWithSAMConversion(argument, candidateParameter) ?: argument.getExpectedType(
candidateParameter,
callComponents.languageVersionSettings
)
val resultType = knownTypeParametersResultingSubstitutor?.substitute(argumentType) ?: argumentType
return resolvedCall.substitutor.substituteKeepAnnotations(resultType)
}
private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion(
argument: KotlinCallArgument,
candidateParameter: ParameterDescriptor
): UnwrappedType? {
if (!callComponents.samConversionTransformer.shouldRunSamConversionForFunction(resolvedCall.candidateDescriptor)) return null
val argumentIsFunctional = when (argument) {
is SimpleKotlinCallArgument -> argument.receiver.stableType.isSubtypeOfFunctionType()
is LambdaKotlinCallArgument, is CallableReferenceKotlinCallArgument -> true
else -> false
}
if (!argumentIsFunctional) return null
val originalExpectedType = argument.getExpectedType(candidateParameter.original, callComponents.languageVersionSettings)
val convertedTypeByOriginal = callComponents.samConversionTransformer.getFunctionTypeForPossibleSamType(originalExpectedType) ?: return null
val candidateExpectedType = argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings)
val convertedTypeByCandidate = callComponents.samConversionTransformer.getFunctionTypeForPossibleSamType(candidateExpectedType)
assert(candidateExpectedType.constructor == originalExpectedType.constructor && convertedTypeByCandidate != null) {
"If original type is SAM type, then candidate should have same type constructor and corresponding function type\n" +
"originalExpectType: $originalExpectedType, candidateExpectType: $candidateExpectedType\n" +
"functionTypeByOriginal: $convertedTypeByOriginal, functionTypeByCandidate: $convertedTypeByCandidate"
}
resolvedCall.registerArgumentWithSamConversion(argument, SamConversionDescription(convertedTypeByOriginal, convertedTypeByCandidate!!))
return convertedTypeByCandidate
}
private fun UnwrappedType.isSubtypeOfFunctionType() = anySuperTypeConstructor {
it.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.Function
}
internal object CheckReceivers : ResolutionPart() {
private fun KotlinResolutionCandidate.checkReceiver(
receiverArgument: SimpleKotlinCallArgument?,
@@ -42,7 +42,8 @@ class KotlinCallComponents(
val constraintInjector: ConstraintInjector,
val reflectionTypes: ReflectionTypes,
val builtIns: KotlinBuiltIns,
val languageVersionSettings: LanguageVersionSettings
val languageVersionSettings: LanguageVersionSettings,
val samConversionTransformer: SamConversionTransformer
)
class SimpleCandidateFactory(
@@ -61,8 +61,15 @@ abstract class ResolvedCallAtom : ResolvedAtom() {
abstract val typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping
abstract val argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
abstract val substitutor: FreshVariableNewTypeSubstitutor
abstract val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
}
class SamConversionDescription(
val convertedTypeByOriginParameter: UnwrappedType,
val convertedTypeByCandidateParameter: UnwrappedType // expected type for corresponding argument
)
class ResolvedExpressionAtom(override val atom: ExpressionKotlinCallArgument) : ResolvedAtom() {
init {
setAnalyzedResults(listOf())
@@ -24,10 +24,10 @@ import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.UnwrappedType
abstract class ResolutionPart {
@@ -176,6 +176,17 @@ class MutableResolvedCallAtom(
override lateinit var argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
override lateinit var substitutor: FreshVariableNewTypeSubstitutor
lateinit var argumentToCandidateParameter: Map<KotlinCallArgument, ValueParameterDescriptor>
private var samAdapterMap: HashMap<KotlinCallArgument, SamConversionDescription>? = null
override val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
get() = samAdapterMap ?: emptyMap()
fun registerArgumentWithSamConversion(argument: KotlinCallArgument, samConversionDescription: SamConversionDescription) {
if (samAdapterMap == null)
samAdapterMap = hashMapOf()
samAdapterMap!![argument] = samConversionDescription
}
override public fun setAnalyzedResults(subResolvedAtoms: List<ResolvedAtom>) {
super.setAnalyzedResults(subResolvedAtoms)
+44
View File
@@ -0,0 +1,44 @@
// !LANGUAGE: +NewInference
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: Fn.java
public interface Fn<T, R> {
R run(String s, int i, T t);
}
// FILE: J.java
public class J {
public int runConversion(Fn<String, Integer> f1, Fn<Integer, String> f2) {
return f1.run("Bar", 1, f2.run("Foo", 42, 239));
}
}
// FILE: 1.kt
fun box(): String {
val j = J()
var x = ""
val fsi = object : Fn<String, Int> {
override fun run(s: String, i: Int, t: String): Int {
x += "$s$i$t "
return i
}
}
val fis = object : Fn<Int, String> {
override fun run(s: String, i: Int, t: Int): String {
x += "$s$i$t "
return s
}
}
val r1 = j.runConversion(fsi) { s, i, ti -> x += "L$s$i$ti "; "L$s"}
val r2 = j.runConversion({ s, i, ts -> x += "L$s$i$ts"; i }, fis)
if (r1 != 1) return "fail r1: $r1"
if (r2 != 1) return "fail r2: $r2"
if (x != "LFoo42239 Bar1LFoo Foo42239 LBar1Foo") return x
return "OK"
}
+41
View File
@@ -0,0 +1,41 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: Fn.java
public interface Fn<T, R> {
R run(String s, int i, T t);
}
// FILE: 1.kt
class K {
fun runConversion(f1: Fn<String, Int>, f2: Fn<Int, String>) = f1.run("Bar", 1, f2.run("Foo", 42, 239))
}
fun box(): String {
val k = K()
var x = ""
val fsi = object : Fn<String, Int> {
override fun run(s: String, i: Int, t: String): Int {
x += "$s$i$t "
return i
}
}
val fis = object : Fn<Int, String> {
override fun run(s: String, i: Int, t: Int): String {
x += "$s$i$t "
return s
}
}
val r1 = k.runConversion(fsi) { s, i, ti -> x += "L$s$i$ti "; "L$s"}
val r2 = k.runConversion({ s, i, ts -> x += "L$s$i$ts"; i }, fis)
if (r1 != 1) return "fail r1: $r1"
if (r2 != 1) return "fail r2: $r2"
if (x != "LFoo42239 Bar1LFoo Foo42239 LBar1Foo") return x
return "OK"
}
@@ -1,3 +1,4 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: A.java
@@ -15,14 +16,14 @@ fun <T> bar(s: T) {}
fun <T> complex(t: T, f: (T) -> Unit) {}
fun test1() {
foo(1, A::invokeLater)
foo(1, <!NI;TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(1, ::bar)
complex(1, ::bar)
}
fun <R> test2(x: R) {
foo(x, A::invokeLater)
foo(x, <!NI;TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(x, ::bar)
complex(x, ::bar)
@@ -13,5 +13,5 @@ public class J {
package test
fun test() {
J("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = <!NI;TYPE_MISMATCH!>{ }<!>, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
J("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = { }, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
}
@@ -13,5 +13,5 @@ public class J {
package test
fun test() {
J.foo("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = <!NI;TYPE_MISMATCH!>{ }<!>, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
J.foo("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = { }, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
}
@@ -1,3 +1,4 @@
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_VARIABLE
// FILE: A.java
@@ -20,7 +21,7 @@ class B {
fun main() {
fun println() {}
// All parameters in SAM adapter of `foo` have functional types
B().foo(<!TYPE_MISMATCH!>{ println() }<!>, B.bar())
B().foo(<!OI;TYPE_MISMATCH!>{ println() }<!>, B.bar())
// So you should use SAM constructors when you want to use mix lambdas and Java objects
B().foo(Runnable { println() }, B.bar())
B().foo({ println() }, { it: Any? -> it == null } )
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// FILE: Runnable.java
public interface Runnable {
void run();
}
// FILE: 1.kt
interface K {
fun foo1(r: Runnable)
fun foo2(r1: Runnable, r2: Runnable)
}
fun test(k: K, r: Runnable) {
k.foo1(r)
k.foo1(<!TYPE_MISMATCH!>{}<!>)
k.foo2(r, r)
k.foo2(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
k.foo2(r, <!TYPE_MISMATCH!>{}<!>)
k.foo2(<!TYPE_MISMATCH!>{}<!>, r)
}
@@ -0,0 +1,18 @@
package
public fun test(/*0*/ k: K, /*1*/ r: Runnable): kotlin.Unit
public interface K {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo1(/*0*/ r: Runnable): kotlin.Unit
public abstract fun foo2(/*0*/ r1: Runnable, /*1*/ r2: Runnable): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Runnable {
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
}
@@ -0,0 +1,29 @@
// !LANGUAGE: +NewInference
// !CHECK_TYPE
// FILE: J.java
public interface J<T> {
void f_t(F<T> f1, F<T> f2);
<R> void f_r(F<R> f1, F<R> f2);
<R> void f_pr(F<PR<T, R>> f1, F<PR<T, R>> f2);
}
// FILE: F.java
public interface F<S> {
void apply(S s);
}
// FILE: PR.java
public interface PR<X, Y> {}
// FILE: 1.kt
fun test(
j: J<String>,
f_string: F<String>,
f_int: F<Int>,
f_pr: F<PR<String, Int>>
) {
j.f_t(f_string) { it checkType { _<String>() } }
j.f_r(f_int) { it checkType { _<Int>() } }
j.f_pr(f_pr) { it checkType { _<PR<String, Int>>() } }
}
@@ -0,0 +1,25 @@
package
public fun test(/*0*/ j: J<kotlin.String>, /*1*/ f_string: F<kotlin.String>, /*2*/ f_int: F<kotlin.Int>, /*3*/ f_pr: F<PR<kotlin.String, kotlin.Int>>): kotlin.Unit
public interface F</*0*/ S : kotlin.Any!> {
public abstract fun apply(/*0*/ s: S!): kotlin.Unit
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 interface J</*0*/ T : kotlin.Any!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun </*0*/ R : kotlin.Any!> f_pr(/*0*/ f1: F<PR<T!, R!>!>!, /*1*/ f2: F<PR<T!, R!>!>!): kotlin.Unit
public abstract fun </*0*/ R : kotlin.Any!> f_r(/*0*/ f1: F<R!>!, /*1*/ f2: F<R!>!): kotlin.Unit
public abstract fun f_t(/*0*/ f1: F<T!>!, /*1*/ f2: F<T!>!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface PR</*0*/ X : kotlin.Any!, /*1*/ Y : kotlin.Any!> {
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
}
@@ -0,0 +1,27 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !CHECK_TYPE
// FILE: F.java
public interface F<S> {
void apply(S s);
}
// FILE: PR.java
public interface PR<X, Y> {}
// FILE: 1.kt
interface K<T> {
fun f_t(f1: F<T>, f2: F<T>)
fun <R> f_r(f1: F<R>, f2: F<R>)
fun <R> f_pr(f1: F<PR<T, R>>, f2: F<PR<T, R>>)
}
fun test(
k: K<String>,
f_string: F<String>,
f_int: F<Int>,
f_pr: F<PR<String, Int>>
) {
k.f_t(f_string) { it checkType { _<String>() } }
k.f_r(f_int) { it checkType { _<Int>() } }
k.f_pr(f_pr) { it checkType { _<PR<String, Int>>() } }
}
@@ -0,0 +1,25 @@
package
public fun test(/*0*/ k: K<kotlin.String>, /*1*/ f_string: F<kotlin.String>, /*2*/ f_int: F<kotlin.Int>, /*3*/ f_pr: F<PR<kotlin.String, kotlin.Int>>): kotlin.Unit
public interface F</*0*/ S : kotlin.Any!> {
public abstract fun apply(/*0*/ s: S!): kotlin.Unit
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 interface K</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun </*0*/ R> f_pr(/*0*/ f1: F<PR<T, R>>, /*1*/ f2: F<PR<T, R>>): kotlin.Unit
public abstract fun </*0*/ R> f_r(/*0*/ f1: F<R>, /*1*/ f2: F<R>): kotlin.Unit
public abstract fun f_t(/*0*/ f1: F<T>, /*1*/ f2: F<T>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface PR</*0*/ X : kotlin.Any!, /*1*/ Y : kotlin.Any!> {
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
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +NewInference
// !CHECK_TYPE
// FILE: Fn.java
public interface Fn<T, R> {
R apply(T t);
}
// FILE: Fn2.java
public interface Fn2<T, R> extends Fn<T, R> {}
// FILE: J.java
public interface J {
String foo(Fn<String, Object> f, Object o);
int foo(Fn<Object, Object> f, String s); // (Any) -> Any <: (String) -> Any <=> String <: Any
String bas(Fn<Object, Object> f, Object o);
int bas(Fn<Object, String> f, String s); // (Any) -> String <: (Any) -> Any <=> String <: Any
String bar(Fn<String, Object> f);
int bar(Fn2<String, Object> f); // Fn2 seems more specific one even function type same
}
// FILE: 1.kt
fun test(j: J) {
j.foo({ it checkType { _<Any>() }; "" }, "") checkType { _<Int>() }
j.bas({ it checkType { _<Any>() }; "" }, "") checkType { _<Int>() }
// NI: TODO
j.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!> { <!UNRESOLVED_REFERENCE!>it<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Any>() }; "" } <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
@@ -0,0 +1,29 @@
package
public fun test(/*0*/ j: J): kotlin.Unit
public interface Fn</*0*/ T : kotlin.Any!, /*1*/ R : kotlin.Any!> {
public abstract fun apply(/*0*/ t: T!): R!
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 interface Fn2</*0*/ T : kotlin.Any!, /*1*/ R : kotlin.Any!> : Fn<T!, R!> {
public abstract override /*1*/ /*fake_override*/ fun apply(/*0*/ t: T!): R!
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 interface J {
public abstract fun bar(/*0*/ f: Fn2<kotlin.String!, kotlin.Any!>!): kotlin.Int
public abstract fun bar(/*0*/ f: Fn<kotlin.String!, kotlin.Any!>!): kotlin.String!
public abstract fun bas(/*0*/ f: Fn<kotlin.Any!, kotlin.Any!>!, /*1*/ o: kotlin.Any!): kotlin.String!
public abstract fun bas(/*0*/ f: Fn<kotlin.Any!, kotlin.String!>!, /*1*/ s: kotlin.String!): kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ f: Fn<kotlin.Any!, kotlin.Any!>!, /*1*/ s: kotlin.String!): kotlin.Int
public abstract fun foo(/*0*/ f: Fn<kotlin.String!, kotlin.Any!>!, /*1*/ o: kotlin.Any!): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,30 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !CHECK_TYPE
// FILE: Fn.java
public interface Fn<T, R> {
R apply(T t);
}
// FILE: Fn2.java
public interface Fn2<T, R> extends Fn<T, R> {}
// FILE: 1.kt
interface K {
fun foo(f: Fn<String, Any>): String
fun foo(f: Fn<Any, Any>): Int
fun bas(f: Fn<Any, Any>): String
fun bas(f: Fn<Any, String>): Int
fun bar(f: Fn<String, Any>): String
fun bar(f: Fn2<String, Any>): Int
}
fun test(k: K) {
k.foo { it checkType { _<Any>() }; "" } checkType { _<Int>() }
k.bas { it checkType { _<Any?>() }; "" } checkType { _<Int>() }
// NI: TODO
k.<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!> { <!UNRESOLVED_REFERENCE!>it<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Any>() }; "" } <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Int>() }
}
@@ -0,0 +1,29 @@
package
public fun test(/*0*/ k: K): kotlin.Unit
public interface Fn</*0*/ T : kotlin.Any!, /*1*/ R : kotlin.Any!> {
public abstract fun apply(/*0*/ t: T!): R!
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 interface Fn2</*0*/ T : kotlin.Any!, /*1*/ R : kotlin.Any!> : Fn<T!, R!> {
public abstract override /*1*/ /*fake_override*/ fun apply(/*0*/ t: T!): R!
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 interface K {
public abstract fun bar(/*0*/ f: Fn2<kotlin.String, kotlin.Any>): kotlin.Int
public abstract fun bar(/*0*/ f: Fn<kotlin.String, kotlin.Any>): kotlin.String
public abstract fun bas(/*0*/ f: Fn<kotlin.Any, kotlin.Any>): kotlin.String
public abstract fun bas(/*0*/ f: Fn<kotlin.Any, kotlin.String>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ f: Fn<kotlin.Any, kotlin.Any>): kotlin.Int
public abstract fun foo(/*0*/ f: Fn<kotlin.String, kotlin.Any>): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,18 @@
// !LANGUAGE: +NewInference
// FILE: J.java
public interface J<T> {
public void foo(T r1, T r2);
}
// FILE: Runnable.java
public interface Runnable {
void run();
}
// FILE: 1.kt
fun test(j: J<Runnable>, r: Runnable) {
j.foo(r, r)
j.foo(r, <!TYPE_MISMATCH!>{}<!>)
j.foo(<!TYPE_MISMATCH!>{}<!>, r)
j.foo(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
}
@@ -0,0 +1,17 @@
package
public fun test(/*0*/ j: J<Runnable>, /*1*/ r: Runnable): kotlin.Unit
public interface J</*0*/ T : kotlin.Any!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ r1: T!, /*1*/ r2: T!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Runnable {
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
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// FILE: Runnable.java
public interface Runnable {
void run();
}
// FILE: 1.kt
interface K<T> {
fun foo(t1: T, t2: T)
}
fun test(k: K<Runnable>, r: Runnable) {
k.foo(r, r)
k.foo(r, <!TYPE_MISMATCH!>{}<!>)
k.foo(<!TYPE_MISMATCH!>{}<!>, r)
k.foo(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
}
@@ -0,0 +1,17 @@
package
public fun test(/*0*/ k: K<Runnable>, /*1*/ r: Runnable): kotlin.Unit
public interface K</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ t1: T, /*1*/ t2: T): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Runnable {
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
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// FILE: J.java
public interface J {
public void foo1(Runnable r);
public void foo2(Runnable r1, Runnable r2);
public void foo3(Runnable r1, Runnable r2, Runnable r3);
}
// FILE: Runnable.java
public interface Runnable {
void run();
}
// FILE: 1.kt
fun test(j: J, r: Runnable) {
j.foo1(r)
j.foo1({})
j.foo2(r, r)
j.foo2({}, {})
j.foo2(r, {})
j.foo2({}, r)
j.foo3(r, r, r)
j.foo3(r, r, {})
j.foo3(r, {}, r)
j.foo3(r, {}, {})
j.foo3({}, r, r)
j.foo3({}, r, {})
j.foo3({}, {}, r)
j.foo3({}, {}, {})
}
@@ -0,0 +1,19 @@
package
public fun test(/*0*/ j: J, /*1*/ r: Runnable): kotlin.Unit
public interface J {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo1(/*0*/ r: Runnable!): kotlin.Unit
public abstract fun foo2(/*0*/ r1: Runnable!, /*1*/ r2: Runnable!): kotlin.Unit
public abstract fun foo3(/*0*/ r1: Runnable!, /*1*/ r2: Runnable!, /*2*/ r3: Runnable!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Runnable {
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
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// FILE: Runnable.java
public interface Runnable {
void run();
}
// FILE: 1.kt
interface K {
fun foo1(r: Runnable)
fun foo2(r1: Runnable, r2: Runnable)
fun foo3(r1: Runnable, r2: Runnable, r3: Runnable)
}
fun test(k: K, r: Runnable) {
k.foo1(r)
k.foo1({})
k.foo2(r, r)
k.foo2({}, {})
k.foo2(r, {})
k.foo2({}, r)
k.foo3(r, r, r)
k.foo3(r, r, {})
k.foo3(r, {}, r)
k.foo3(r, {}, {})
k.foo3({}, r, r)
k.foo3({}, r, {})
k.foo3({}, {}, r)
k.foo3({}, {}, {})
}
@@ -0,0 +1,19 @@
package
public fun test(/*0*/ k: K, /*1*/ r: Runnable): kotlin.Unit
public interface K {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo1(/*0*/ r: Runnable): kotlin.Unit
public abstract fun foo2(/*0*/ r1: Runnable, /*1*/ r2: Runnable): kotlin.Unit
public abstract fun foo3(/*0*/ r1: Runnable, /*1*/ r2: Runnable, /*2*/ r3: Runnable): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Runnable {
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
}
@@ -21,7 +21,7 @@ class B : A() {
}
if (d.x is B) {
<!SMARTCAST_IMPOSSIBLE!>d.x<!>.<!NI;INVISIBLE_MEMBER!>foo<!> {}
<!OI;SMARTCAST_IMPOSSIBLE!>d.x<!>.<!NI;INVISIBLE_MEMBER!>foo<!> {}
}
}
}
@@ -2,7 +2,7 @@
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass<Int>): Int {
val inner = javaClass.createInner<String>()
return <!TYPE_MISMATCH!>inner.<!NI;TYPE_MISMATCH!>doSomething(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, "") <!TYPE_MISMATCH!>{ }<!><!><!>
return <!TYPE_MISMATCH!>inner.<!NI;TYPE_MISMATCH!>doSomething(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, "") <!OI;TYPE_MISMATCH!>{ }<!><!><!>
}
// FILE: JavaClass.java
@@ -1,9 +1,9 @@
// !WITH_NEW_INFERENCE
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass) {
javaClass.doSomething(<!NAMED_ARGUMENTS_NOT_ALLOWED!>p<!> = 1) <!NI;TYPE_MISMATCH!>{
javaClass.doSomething(<!NAMED_ARGUMENTS_NOT_ALLOWED!>p<!> = 1) {
bar()
}<!>
}
}
fun bar(){}
@@ -1,7 +1,7 @@
// !WITH_NEW_INFERENCE
// FILE: KotlinFile.kt
fun foo(javaInterface: JavaInterface) {
javaInterface.doIt(<!NULL_FOR_NONNULL_TYPE!>null<!>) <!NI;TYPE_MISMATCH!>{ }<!>
javaInterface.doIt(<!NULL_FOR_NONNULL_TYPE!>null<!>) { }
javaInterface.doIt("", <!NULL_FOR_NONNULL_TYPE!>null<!>)
}
@@ -1,6 +1,7 @@
// !WITH_NEW_INFERENCE
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass) {
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!TYPE_MISMATCH!>{ }<!>
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!OI;TYPE_MISMATCH!>{ }<!>
}
// FILE: JavaClass.java
@@ -19425,6 +19425,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
}
@TestMetadata("partialSam.kt")
public void testPartialSam() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
}
@TestMetadata("partialSamKT.kt")
public void testPartialSamKT() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSamKT.kt");
}
@TestMetadata("compiler/testData/codegen/box/sam/constructors")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17166,6 +17166,64 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
}
}
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SamConversions extends AbstractDiagnosticsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInSamConversions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/samConversions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("DisabledForKTSimple.kt")
public void testDisabledForKTSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.kt");
}
@TestMetadata("GenericSubstitution.kt")
public void testGenericSubstitution() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.kt");
}
@TestMetadata("GenericSubstitutionKT.kt")
public void testGenericSubstitutionKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
}
@TestMetadata("OverloadPriority.kt")
public void testOverloadPriority() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
}
@TestMetadata("OverloadPriorityKT.kt")
public void testOverloadPriorityKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.kt");
}
@TestMetadata("SAMAfterSubstitution.kt")
public void testSAMAfterSubstitution() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.kt");
}
@TestMetadata("SAMAfterSubstitutionKT.kt")
public void testSAMAfterSubstitutionKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.kt");
}
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.kt");
}
@TestMetadata("SimpleCorrectKT.kt")
public void testSimpleCorrectKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/scopes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17166,6 +17166,64 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
}
}
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SamConversions extends AbstractDiagnosticsUsingJavacTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInSamConversions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/samConversions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("DisabledForKTSimple.kt")
public void testDisabledForKTSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.kt");
}
@TestMetadata("GenericSubstitution.kt")
public void testGenericSubstitution() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitution.kt");
}
@TestMetadata("GenericSubstitutionKT.kt")
public void testGenericSubstitutionKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
}
@TestMetadata("OverloadPriority.kt")
public void testOverloadPriority() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
}
@TestMetadata("OverloadPriorityKT.kt")
public void testOverloadPriorityKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriorityKT.kt");
}
@TestMetadata("SAMAfterSubstitution.kt")
public void testSAMAfterSubstitution() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.kt");
}
@TestMetadata("SAMAfterSubstitutionKT.kt")
public void testSAMAfterSubstitutionKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.kt");
}
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SimpleCorrect.kt");
}
@TestMetadata("SimpleCorrectKT.kt")
public void testSimpleCorrectKT() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/SimpleCorrectKT.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/scopes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -19425,6 +19425,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
}
@TestMetadata("partialSam.kt")
public void testPartialSam() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
}
@TestMetadata("partialSamKT.kt")
public void testPartialSamKT() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSamKT.kt");
}
@TestMetadata("compiler/testData/codegen/box/sam/constructors")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -19425,6 +19425,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
}
@TestMetadata("partialSam.kt")
public void testPartialSam() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
}
@TestMetadata("partialSamKT.kt")
public void testPartialSamKT() throws Exception {
runTest("compiler/testData/codegen/box/sam/partialSamKT.kt");
}
@TestMetadata("compiler/testData/codegen/box/sam/constructors")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -91,6 +91,8 @@ enum class LanguageFeature(
NewInference(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED),
SamConversionForKotlinFunctions(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED),
InlineClasses(sinceVersion = null, defaultState = State.DISABLED, kind = UNSTABLE_FEATURE),
;
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.OverloadFilter
import org.jetbrains.kotlin.resolve.OverridesBackwardCompatibilityHelper
import org.jetbrains.kotlin.resolve.PlatformConfigurator
import org.jetbrains.kotlin.resolve.calls.checkers.ReifiedTypeParameterSubstitutionChecker
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
@@ -63,6 +64,7 @@ object JsPlatformConfigurator : PlatformConfigurator(
container.useInstance(NameSuggestion())
container.useImpl<JsCallChecker>()
container.useInstance(SyntheticScopes.Empty)
container.useInstance(SamConversionTransformer.Empty)
container.useInstance(JsTypeSpecificityComparator)
container.useImpl<JsNameClashChecker>()
container.useImpl<JsNameCharsChecker>()