psi2ir: fix unsubstituted type parameters around SAM conversions

Preserve type substitution:
- when obtaining function type for SAM type;
- when generating SAM conversions for SAM adapter arguments;
- for "original" method corresponding to a SAM adapter.
This commit is contained in:
Dmitry Petrov
2019-08-13 12:23:15 +03:00
parent 6b208f7c9c
commit 986654b709
20 changed files with 658 additions and 47 deletions
@@ -1367,11 +1367,31 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/expressions/sam"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("samByProjectedType.kt")
public void testSamByProjectedType() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt");
}
@TestMetadata("samConstructors.kt")
public void testSamConstructors() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConstructors.kt");
}
@TestMetadata("samConversionInGenericConstructorCall.kt")
public void testSamConversionInGenericConstructorCall() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt");
}
@TestMetadata("samConversionInGenericConstructorCall_NI.kt")
public void testSamConversionInGenericConstructorCall_NI() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.kt");
}
@TestMetadata("samConversionToGeneric.kt")
public void testSamConversionToGeneric() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.kt");
}
@TestMetadata("samConversions.kt")
public void testSamConversions() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversions.kt");
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.backend.jvm
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
@@ -16,7 +15,7 @@ import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.*
object JvmGeneratorExtensions : GeneratorExtensions() {
override val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = { descriptor ->
@@ -43,15 +42,14 @@ object JvmGeneratorExtensions : GeneratorExtensions() {
override fun isSamType(type: KotlinType): Boolean =
SingleAbstractMethodUtils.isSamType(type)
override fun getFunctionTypeForSAMClass(descriptor: ClassDescriptor): KotlinType {
if (descriptor !is JavaClassDescriptor) {
throw AssertionError("SAM should be represented by a Java class: $descriptor")
}
override fun getSubstitutedFunctionTypeForSamType(samType: KotlinType): KotlinType {
val descriptor = samType.constructor.declarationDescriptor as? JavaClassDescriptor
?: throw AssertionError("SAM should be represented by a Java class: $samType")
val singleAbstractMethod = SingleAbstractMethodUtils.getSingleAbstractMethodOrNull(descriptor)
?: throw AssertionError("$descriptor should have a single abstract method")
return SingleAbstractMethodUtils.getFunctionTypeForAbstractMethod(singleAbstractMethod, false)
val unsubstitutedFunctionType = SingleAbstractMethodUtils.getFunctionTypeForAbstractMethod(singleAbstractMethod, false)
return TypeSubstitutor.create(samType).substitute(unsubstitutedFunctionType, Variance.INVARIANT)
?: throw AssertionError("Failed to substitute function type $unsubstitutedFunctionType corresponding to $samType")
}
companion object Instance : JvmSamConversion()
@@ -41,7 +41,9 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.scopes.receivers.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeProjectionImpl
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.Variance
import kotlin.math.max
import kotlin.math.min
@@ -292,17 +294,9 @@ fun StatementGenerator.generateValueArgumentUsing(
TODO("Unexpected valueArgument: ${valueArgument::class.java.simpleName}")
}
fun StatementGenerator.castArgumentToFunctionalInterfaceForSamType(
irExpression: IrExpression,
samType: KotlinType
): IrExpression {
val samConversion = context.extensions.samConversion
val samTypeDescriptor = samType.constructor.declarationDescriptor
val samClassDescriptor = samTypeDescriptor as? ClassDescriptor
?: throw AssertionError("SAM class expected: $samType")
val kotlinFunctionType = samConversion.getFunctionTypeForSAMClass(samClassDescriptor)
fun StatementGenerator.castArgumentToFunctionalInterfaceForSamType(irExpression: IrExpression, samType: KotlinType): IrExpression {
val kotlinFunctionType = context.extensions.samConversion.getSubstitutedFunctionTypeForSamType(samType)
val irFunctionType = context.typeTranslator.translateType(kotlinFunctionType)
return irExpression.implicitCastTo(irFunctionType)
}
@@ -422,6 +416,16 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
"Mismatching value parameters, $originalDescriptor vs call: " +
"${originalValueParameters.size} != ${call.argumentsCount}"
}
assert(underlyingDescriptor.typeParameters.size == originalDescriptor.typeParameters.size) {
"Mismatching type parameters:\n" +
"$underlyingDescriptor has ${underlyingDescriptor.typeParameters}\n" +
"$originalDescriptor has ${originalDescriptor.typeParameters}"
}
val substitutionContext = call.original.typeArguments.entries.associate { (typeParameterDescriptor, typeArgument) ->
underlyingDescriptor.typeParameters[typeParameterDescriptor.index].typeConstructor to TypeProjectionImpl(typeArgument)
}
val typeSubstitutor = TypeSubstitutor.create(substitutionContext)
for (i in underlyingValueParameters.indices) {
val originalParameterType = originalValueParameters[i].type
@@ -432,7 +436,13 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
val originalArgument = call.irValueArgumentsByIndex[i] ?: continue
val targetType = underlyingParameterType.toIrType()
val expectedArgumentType = typeSubstitutor.substitute(underlyingParameterType, Variance.INVARIANT)
?: throw AssertionError(
"Failed to substitute value argument type in SAM conversion: " +
"underlyingParameterType=$underlyingParameterType, " +
"substitutionContext=$substitutionContext"
)
val targetType = expectedArgumentType.toIrType()
call.irValueArgumentsByIndex[i] =
IrTypeOperatorCallImpl(
@@ -440,7 +450,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca
targetType,
IrTypeOperator.SAM_CONVERSION,
targetType,
castArgumentToFunctionalInterfaceForSamType(originalArgument, underlyingParameterType)
castArgumentToFunctionalInterfaceForSamType(originalArgument, expectedArgumentType)
)
}
}
@@ -477,9 +487,12 @@ private fun unwrapSpecialDescriptor(
samConversion: GeneratorExtensions.SamConversion
): CallableDescriptor =
when (descriptor) {
is ImportedFromObjectCallableDescriptor<*> -> unwrapSpecialDescriptor(descriptor.callableFromObject, samConversion)
is TypeAliasConstructorDescriptor -> descriptor.underlyingConstructorDescriptor
else -> samConversion.getOriginalForSamAdapter(descriptor)?.let { unwrapSpecialDescriptor(it, samConversion) } ?: descriptor
is ImportedFromObjectCallableDescriptor<*> ->
unwrapSpecialDescriptor(descriptor.callableFromObject, samConversion)
is TypeAliasConstructorDescriptor ->
descriptor.underlyingConstructorDescriptor
else ->
samConversion.getOriginalForSamAdapter(descriptor)?.let { unwrapSpecialDescriptor(it, samConversion) } ?: descriptor
}
fun unwrapCallableDescriptorAndTypeArguments(resolvedCall: ResolvedCall<*>, samConversion: GeneratorExtensions.SamConversion): CallBuilder {
@@ -503,11 +516,11 @@ fun unwrapCallableDescriptorAndTypeArguments(resolvedCall: ResolvedCall<*>, samC
if (unsubstitutedUnwrappedTypeParameters.isEmpty())
null
else
unsubstitutedUnwrappedTypeParameters.associate {
unsubstitutedUnwrappedTypeParameters.associateWith {
val originalTypeParameter = candidateDescriptor.typeParameters[it.index]
val originalTypeArgument = originalTypeArguments[originalTypeParameter]
?: throw AssertionError("No type argument for $originalTypeParameter")
it to originalTypeArgument
originalTypeArgument
}
}
@@ -516,8 +529,8 @@ fun unwrapCallableDescriptorAndTypeArguments(resolvedCall: ResolvedCall<*>, samC
if (substitutedType.arguments.isEmpty())
null
else
unsubstitutedUnwrappedTypeParameters.associate {
it to substitutedType.arguments[it.index].type
unsubstitutedUnwrappedTypeParameters.associateWith {
substitutedType.arguments[it.index].type
}
}
@@ -547,5 +560,17 @@ fun unwrapCallableDescriptorAndTypeArguments(resolvedCall: ResolvedCall<*>, samC
}
}
return CallBuilder(resolvedCall, unwrappedDescriptor, unwrappedTypeArguments)
val substitutedUnwrappedDescriptor =
if (unwrappedTypeArguments == null)
unwrappedDescriptor
else {
val substitutionContext = unsubstitutedUnwrappedDescriptor.typeParameters.associate {
val typeArgument = unwrappedTypeArguments[it]
?: throw AssertionError("No type argument for $it in $unwrappedTypeArguments")
it.typeConstructor to TypeProjectionImpl(typeArgument)
}
unwrappedDescriptor.substitute(TypeSubstitutor.create(substitutionContext))
}
return CallBuilder(resolvedCall, substitutedUnwrappedDescriptor, unwrappedTypeArguments)
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.SimpleType
open class GeneratorExtensions {
open val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)?
@@ -26,8 +27,8 @@ open class GeneratorExtensions {
open fun isSamType(type: KotlinType): Boolean = false
open fun getFunctionTypeForSAMClass(descriptor: ClassDescriptor): KotlinType =
throw UnsupportedOperationException("SAM conversion is not supported in this configuration (class=$descriptor)")
open fun getSubstitutedFunctionTypeForSamType(samType: KotlinType): KotlinType =
throw UnsupportedOperationException("SAM conversion is not supported in this configuration (samType=$samType)")
companion object Instance : SamConversion()
}
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.psi2ir.transformations
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrClass
@@ -32,7 +31,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
import org.jetbrains.kotlin.ir.util.TypeTranslator
import org.jetbrains.kotlin.ir.util.coerceToUnitIfNeeded
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.psi2ir.containsNull
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
@@ -181,9 +179,7 @@ open class InsertImplicitCasts(
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrExpression =
when (expression.operator) {
IrTypeOperator.SAM_CONVERSION -> expression.transformPostfix {
val targetClassDescriptor = typeOperandClassifier.descriptor as? ClassDescriptor
?: throw AssertionError("Target type of $operator should be a class: ${render()}")
argument = argument.cast(samConversion.getFunctionTypeForSAMClass(targetClassDescriptor))
argument = argument.cast(samConversion.getSubstitutedFunctionTypeForSamType(typeOperand.originalKotlinType!!))
}
IrTypeOperator.IMPLICIT_CAST -> {
@@ -1,5 +1,4 @@
// SKIP_JDK6
// IGNORE_BACKEND: JVM_IR
// FILE: Custom.java
class Custom<K, V> {
@@ -0,0 +1,9 @@
FILE fqName:<root> fileName:/samByProjectedType.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public open fun bar (j: <root>.J<*>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
j: FUN_EXPR type=kotlin.Function1<kotlin.Any, kotlin.Any> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Any
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
GET_VAR 'x: kotlin.Any declared in <root>.test1.<anonymous>' type=kotlin.Any origin=null
@@ -0,0 +1,14 @@
// FILE: samByProjectedType.kt
fun test1() {
H.bar { x: Any -> x }
}
// FILE: J.java
public interface J<T> {
T foo(T x);
}
// FILE: H.java
public class H {
public static void bar(J<?> j) {}
}
@@ -0,0 +1,11 @@
FILE fqName:<root> fileName:/samByProjectedType.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public open fun bar (j: <root>.J<*>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
j: TYPE_OP type=<root>.J<*>? origin=SAM_CONVERSION typeOperand=<root>.J<*>?
FUN_EXPR type=kotlin.Function1<kotlin.Any, kotlin.Any> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Any
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (x: kotlin.Any): kotlin.Any declared in <root>.test1'
GET_VAR 'x: kotlin.Any declared in <root>.test1.<anonymous>' type=kotlin.Any origin=null
@@ -25,13 +25,12 @@ FILE fqName:<root> fileName:/samConstructors.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (): java.util.Comparator<kotlin.Int> declared in <root>'
TYPE_OP type=java.util.Comparator<kotlin.Int> origin=SAM_CONVERSION typeOperand=java.util.Comparator<kotlin.Int>
TYPE_OP type=kotlin.Function2<T of java.util.Comparator?, T of java.util.Comparator?, kotlin.Int> origin=IMPLICIT_CAST typeOperand=kotlin.Function2<T of java.util.Comparator?, T of java.util.Comparator?, kotlin.Int>
FUN_EXPR type=kotlin.Function2<kotlin.Int?, kotlin.Int?, kotlin.Int> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (a:kotlin.Int?, b:kotlin.Int?) returnType:kotlin.Int
VALUE_PARAMETER name:a index:0 type:kotlin.Int?
VALUE_PARAMETER name:b index:1 type:kotlin.Int?
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (a: kotlin.Int?, b: kotlin.Int?): kotlin.Int declared in <root>.test4'
CALL 'public final fun minus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=MINUS
$this: GET_VAR 'a: kotlin.Int? declared in <root>.test4.<anonymous>' type=kotlin.Int? origin=null
other: GET_VAR 'b: kotlin.Int? declared in <root>.test4.<anonymous>' type=kotlin.Int? origin=null
FUN_EXPR type=kotlin.Function2<kotlin.Int?, kotlin.Int?, kotlin.Int> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (a:kotlin.Int?, b:kotlin.Int?) returnType:kotlin.Int
VALUE_PARAMETER name:a index:0 type:kotlin.Int?
VALUE_PARAMETER name:b index:1 type:kotlin.Int?
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (a: kotlin.Int?, b: kotlin.Int?): kotlin.Int declared in <root>.test4'
CALL 'public final fun minus (other: kotlin.Int): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=MINUS
$this: GET_VAR 'a: kotlin.Int? declared in <root>.test4.<anonymous>' type=kotlin.Int? origin=null
other: GET_VAR 'b: kotlin.Int? declared in <root>.test4.<anonymous>' type=kotlin.Int? origin=null
@@ -0,0 +1,14 @@
FILE fqName:<root> fileName:/samConversionInGenericConstructorCall.kt
FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>) returnType:IrErrorType
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1<kotlin.String, kotlin.String>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/C.C]>#' type=IrErrorType
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/C.C]>#' type=IrErrorType
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference +SamConversionPerArgument
// FILE: samConversionInGenericConstructorCall.kt
fun test1(f: (String) -> String) = C(f)
fun test2(x: Any) {
x as (String) -> String
C(x)
}
// FILE: J.java
public interface J<T1, T2> {
T1 foo(T2 x);
}
// FILE: C.java
public class C<X> {
public C(J<X, X> jxx) {}
}
@@ -0,0 +1,20 @@
FILE fqName:<root> fileName:/samConversionInGenericConstructorCall.kt
FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>) returnType:<root>.C<kotlin.String>
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1<kotlin.String, kotlin.String>): <root>.C<kotlin.String> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> (jxx: <root>.J<X of <root>.C?, X of <root>.C?>?) declared in <root>.C' type=<root>.C<kotlin.String> origin=null
<class: X>: kotlin.String
jxx: TYPE_OP type=<root>.J<kotlin.String?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String?, kotlin.String?>
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CONSTRUCTOR_CALL 'public constructor <init> (jxx: <root>.J<X of <root>.C?, X of <root>.C?>?) declared in <root>.C' type=<root>.C<kotlin.String> origin=null
<class: X>: kotlin.String
jxx: TYPE_OP type=<root>.J<kotlin.String?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String?, kotlin.String?>
GET_VAR 'x: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
@@ -0,0 +1,92 @@
FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
FUN name:test3 visibility:public modality:FINAL <> (f1:kotlin.Function1<kotlin.String, kotlin.String>, f2:kotlin.Function1<kotlin.Int, kotlin.String>) returnType:IrErrorType
VALUE_PARAMETER name:f1 index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
VALUE_PARAMETER name:f2 index:1 type:kotlin.Function1<kotlin.Int, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (f1: kotlin.Function1<kotlin.String, kotlin.String>, f2: kotlin.Function1<kotlin.Int, kotlin.String>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: D>#' type=IrErrorType
GET_VAR 'f2: kotlin.Function1<kotlin.Int, kotlin.String> declared in <root>.test3' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=null
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer
TYPE_PARAMETER name:T1 index:0 variance: superTypes:[]
CONSTRUCTOR visibility:public <> (j11:<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>>) returnType:<root>.Outer<T1 of <uninitialized parent>> [primary]
VALUE_PARAMETER name:j11 index:0 type:<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:j11 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j11 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> visibility:public [final]
EXPRESSION_BODY
GET_VAR 'j11: <root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>> declared in <root>.Outer.<init>' type=<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j11> visibility:public modality:FINAL <> ($this:<root>.Outer) returnType:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>
correspondingProperty: PROPERTY name:j11 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-j11> (): <root>.J<T1 of <root>.Outer, T1 of <root>.Outer> declared in <root>.Outer'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j11 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> visibility:public [final]' type=<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> origin=null
receiver: GET_VAR '<this>: <root>.Outer declared in <root>.Outer.<get-j11>' type=<root>.Outer origin=null
CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer.Inner
TYPE_PARAMETER name:T2 index:0 variance: superTypes:[]
CONSTRUCTOR visibility:public <> (j12:<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>>) returnType:<root>.Outer.Inner<T2 of <uninitialized parent>> [primary]
VALUE_PARAMETER name:j12 index:0 type:<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
PROPERTY name:j12 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j12 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> visibility:public [final]
EXPRESSION_BODY
GET_VAR 'j12: <root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>> declared in <root>.Outer.Inner.<init>' type=<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j12> visibility:public modality:FINAL <> ($this:<root>.Outer.Inner) returnType:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>
correspondingProperty: PROPERTY name:j12 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer.Inner
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-j12> (): <root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> declared in <root>.Outer.Inner'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j12 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> visibility:public [final]' type=<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> origin=null
receiver: GET_VAR '<this>: <root>.Outer.Inner declared in <root>.Outer.Inner.<get-j12>' type=<root>.Outer.Inner origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:test4 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>, g:kotlin.Function1<kotlin.Any, kotlin.String>) returnType:IrErrorType
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
VALUE_PARAMETER name:g index:1 type:kotlin.Function1<kotlin.Any, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (f: kotlin.Function1<kotlin.String, kotlin.String>, g: kotlin.Function1<kotlin.Any, kotlin.String>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: Inner>#' type=IrErrorType
GET_VAR 'g: kotlin.Function1<kotlin.Any, kotlin.String> declared in <root>.test4' type=kotlin.Function1<kotlin.Any, kotlin.String> origin=null
FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.Int>) returnType:IrErrorType
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.Int>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1<kotlin.String, kotlin.Int>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/G.G]>#' type=IrErrorType
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.Int> declared in <root>.testGenericJavaCtor1' type=kotlin.Function1<kotlin.String, kotlin.Int> origin=null
FUN name:testGenericJavaCtor2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.Int> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.Int>
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/G.G]>#' type=IrErrorType
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Any origin=null
@@ -0,0 +1,39 @@
// !LANGUAGE: +NewInference +SamConversionPerArgument +SamConversionForKotlinFunctions
// FILE: samConversionInGenericConstructorCall_NI.kt
fun test3(
f1: (String) -> String,
f2: (Int) -> String
) =
C(f1).D(f2)
class Outer<T1>(val j11: J<T1, T1>) {
inner class Inner<T2>(val j12: J<T1, T2>)
}
fun test4(f: (String) -> String, g: (Any) -> String) = Outer(f).Inner(g)
fun testGenericJavaCtor1(f: (String) -> Int) = G(f)
fun testGenericJavaCtor2(x: Any) {
x as (String) -> Int
G(x)
}
// FILE: J.java
public interface J<T1, T2> {
T1 foo(T2 x);
}
// FILE: C.java
public class C<X> {
public C(J<X, X> jxx) {}
public class D<Y> {
public D(J<X, Y> jxy) {}
}
}
// FILE: G.java
public class G<TClass> {
public <TCtor> G(J<TCtor, TClass> x) {}
}
@@ -0,0 +1,113 @@
FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
FUN name:test3 visibility:public modality:FINAL <> (f1:kotlin.Function1<kotlin.String, kotlin.String>, f2:kotlin.Function1<kotlin.Int, kotlin.String>) returnType:<root>.C.D<kotlin.Int, kotlin.String>
VALUE_PARAMETER name:f1 index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
VALUE_PARAMETER name:f2 index:1 type:kotlin.Function1<kotlin.Int, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (f1: kotlin.Function1<kotlin.String, kotlin.String>, f2: kotlin.Function1<kotlin.Int, kotlin.String>): <root>.C.D<kotlin.Int, kotlin.String> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> (jxy: <root>.J<X of <root>.C?, Y of <root>.C.D?>?) declared in <root>.C.D' type=<root>.C.D<kotlin.Int, kotlin.String> origin=null
<class: Y>: kotlin.Int
$outer: CONSTRUCTOR_CALL 'public constructor <init> (jxx: <root>.J<X of <root>.C?, X of <root>.C?>?) declared in <root>.C' type=<root>.C<kotlin.String> origin=null
<class: X>: kotlin.String
jxx: TYPE_OP type=<root>.J<kotlin.String?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String?, kotlin.String?>
GET_VAR 'f1: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test3' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
jxy: TYPE_OP type=<root>.J<kotlin.String?, kotlin.Int?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String?, kotlin.Int?>
GET_VAR 'f2: kotlin.Function1<kotlin.Int, kotlin.String> declared in <root>.test3' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=null
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer<T1 of <root>.Outer>
TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (j11:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>) returnType:<root>.Outer<T1 of <root>.Outer> [primary]
VALUE_PARAMETER name:j11 index:0 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:j11 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j11 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> visibility:public [final]
EXPRESSION_BODY
GET_VAR 'j11: <root>.J<T1 of <root>.Outer, T1 of <root>.Outer> declared in <root>.Outer.<init>' type=<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j11> visibility:public modality:FINAL <> ($this:<root>.Outer<T1 of <root>.Outer>) returnType:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>
correspondingProperty: PROPERTY name:j11 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer<T1 of <root>.Outer>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-j11> (): <root>.J<T1 of <root>.Outer, T1 of <root>.Outer> declared in <root>.Outer'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j11 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> visibility:public [final]' type=<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> origin=null
receiver: GET_VAR '<this>: <root>.Outer<T1 of <root>.Outer> declared in <root>.Outer.<get-j11>' type=<root>.Outer<T1 of <root>.Outer> origin=null
CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer>
TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> ($this:<root>.Outer<T1 of <root>.Outer>, j12:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>) returnType:<root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer> [primary]
$outer: VALUE_PARAMETER name:<this> type:<root>.Outer<T1 of <root>.Outer>
VALUE_PARAMETER name:j12 index:0 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
PROPERTY name:j12 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j12 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> visibility:public [final]
EXPRESSION_BODY
GET_VAR 'j12: <root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> declared in <root>.Outer.Inner.<init>' type=<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j12> visibility:public modality:FINAL <> ($this:<root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer>) returnType:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>
correspondingProperty: PROPERTY name:j12 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-j12> (): <root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> declared in <root>.Outer.Inner'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j12 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> visibility:public [final]' type=<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> origin=null
receiver: GET_VAR '<this>: <root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer> declared in <root>.Outer.Inner.<get-j12>' type=<root>.Outer.Inner<T2 of <root>.Outer.Inner, T1 of <root>.Outer> origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:test4 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.String>, g:kotlin.Function1<kotlin.Any, kotlin.String>) returnType:<root>.Outer.Inner<kotlin.Any, kotlin.String>
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
VALUE_PARAMETER name:g index:1 type:kotlin.Function1<kotlin.Any, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (f: kotlin.Function1<kotlin.String, kotlin.String>, g: kotlin.Function1<kotlin.Any, kotlin.String>): <root>.Outer.Inner<kotlin.Any, kotlin.String> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> (j12: <root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>) [primary] declared in <root>.Outer.Inner' type=<root>.Outer.Inner<kotlin.Any, kotlin.String> origin=null
<class: T2>: kotlin.Any
$outer: CONSTRUCTOR_CALL 'public constructor <init> (j11: <root>.J<T1 of <root>.Outer, T1 of <root>.Outer>) [primary] declared in <root>.Outer' type=<root>.Outer<kotlin.String> origin=null
<class: T1>: kotlin.String
j11: TYPE_OP type=<root>.J<kotlin.String, kotlin.String> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String, kotlin.String>
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test4' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
j12: TYPE_OP type=<root>.J<kotlin.String, kotlin.Any> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String, kotlin.Any>
GET_VAR 'g: kotlin.Function1<kotlin.Any, kotlin.String> declared in <root>.test4' type=kotlin.Function1<kotlin.Any, kotlin.String> origin=null
FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1<kotlin.String, kotlin.Int>) returnType:<root>.G<kotlin.String>
VALUE_PARAMETER name:f index:0 type:kotlin.Function1<kotlin.String, kotlin.Int>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1<kotlin.String, kotlin.Int>): <root>.G<kotlin.String> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> <TCtor> (x: <root>.J<TCtor of <root>.G.<init>?, TClass of <root>.G?>?) declared in <root>.G' type=<root>.G<kotlin.String> origin=null
<class: TClass>: kotlin.String
<TCtor>: kotlin.Int
x: TYPE_OP type=<root>.J<kotlin.Int?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.Int?, kotlin.String?>
GET_VAR 'f: kotlin.Function1<kotlin.String, kotlin.Int> declared in <root>.testGenericJavaCtor1' type=kotlin.Function1<kotlin.String, kotlin.Int> origin=null
FUN name:testGenericJavaCtor2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:x index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.Int> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.Int>
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Any origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CONSTRUCTOR_CALL 'public constructor <init> <TCtor> (x: <root>.J<TCtor of <root>.G.<init>?, TClass of <root>.G?>?) declared in <root>.G' type=<root>.G<kotlin.String> origin=null
<class: TClass>: kotlin.String
<TCtor>: kotlin.Int
x: TYPE_OP type=<root>.J<kotlin.Int?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.Int?, kotlin.String?>
GET_VAR 'x: kotlin.Any declared in <root>.testGenericJavaCtor2' type=kotlin.Any origin=null
@@ -0,0 +1,72 @@
FILE fqName:<root> fileName:/samConversionToGeneric.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:IrErrorType
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: J>#' type=IrErrorType
FUN_EXPR type=IrErrorType origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:IrErrorType) returnType:IrErrorType
VALUE_PARAMETER name:x index:0 type:IrErrorType
BLOCK_BODY
ERROR_CALL 'Unresolved reference: x#' type=IrErrorType
FUN name:test2 visibility:public modality:FINAL <> () returnType:IrErrorType
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: J>#' type=IrErrorType
FUN_EXPR type=IrErrorType origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.String) returnType:IrErrorType
VALUE_PARAMETER name:x index:0 type:kotlin.String
BLOCK_BODY
ERROR_CALL 'Unresolved reference: x#' type=IrErrorType
FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.Unit declared in <root>'
CALL 'public open fun bar (j: <root>.J<X of <uninitialized parent>?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
j: FUN_EXPR type=kotlin.Function1<kotlin.String, kotlin.String> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.String
VALUE_PARAMETER name:x index:0 type:kotlin.String
BLOCK_BODY
GET_VAR 'x: kotlin.String declared in <root>.test3.<anonymous>' type=kotlin.String origin=null
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=<root>.J<kotlin.String> origin=CAST typeOperand=<root>.J<kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
FUN name:test6 visibility:public modality:FINAL <T> (a:kotlin.Function1<T of <root>.test6, T of <root>.test6>) returnType:kotlin.Unit
TYPE_PARAMETER name:T index:0 variance: superTypes:[]
VALUE_PARAMETER name:a index:0 type:kotlin.Function1<T of <root>.test6, T of <root>.test6>
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar]>#' type=IrErrorType
GET_VAR 'a: kotlin.Function1<T of <root>.test6, T of <root>.test6> declared in <root>.test6' type=kotlin.Function1<T of <root>.test6, T of <root>.test6> origin=null
FUN name:test7 visibility:public modality:FINAL <T> (a:kotlin.Any) returnType:kotlin.Unit
TYPE_PARAMETER name:T index:0 variance: superTypes:[]
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Function1<T of <root>.test7, T of <root>.test7> origin=CAST typeOperand=kotlin.Function1<T of <root>.test7, T of <root>.test7>
GET_VAR 'a: kotlin.Any declared in <root>.test7' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.test7' type=kotlin.Any origin=null
FUN name:test8 visibility:public modality:FINAL <> (efn:kotlin.Function1<kotlin.String, kotlin.String>) returnType:IrErrorType
VALUE_PARAMETER name:efn index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test8 (efn: kotlin.Function1<kotlin.String, kotlin.String>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: J>#' type=IrErrorType
GET_VAR 'efn: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test8' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test9 visibility:public modality:FINAL <> (efn:kotlin.Function1<kotlin.String, kotlin.String>) returnType:kotlin.Unit
VALUE_PARAMETER name:efn index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar]>#' type=IrErrorType
GET_VAR 'efn: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test9' type=kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test10 visibility:public modality:FINAL <> (fn:kotlin.Function1<kotlin.Int, kotlin.String>) returnType:kotlin.Unit
VALUE_PARAMETER name:fn index:0 type:kotlin.Function1<kotlin.Int, kotlin.String>
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/H.bar2x]>#' type=IrErrorType
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.String> declared in <root>.test10' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=null
@@ -0,0 +1,56 @@
// FILE: samConversionToGeneric.kt
fun test1() = J<String> { x -> x }
fun test2() = J { x: String -> x }
fun test3() = H.bar { x: String -> x }
fun test4(a: Any) {
a as J<String>
H.bar(a)
}
fun test5(a: Any) {
a as (String) -> String
H.bar(a)
}
fun <T> test6(a: (T) -> T) {
H.bar(a)
}
fun <T> test7(a: Any) {
a as (T) -> T
H.bar(a)
}
fun test8(efn: String.() -> String) = J(efn)
fun test9(efn: String.() -> String) {
H.bar(efn)
}
fun test10(fn: (Int) -> String) {
H.bar2x(fn)
}
// FILE: J.java
public interface J<T> {
T foo(T x);
}
// FILE: J2.java
public interface J2<T1, T2> {
T1 foo(T2 x);
}
// FILE: J2X.java
public interface J2X<T3> extends J2<String, T3> {
}
// FILE: H.java
public class H {
public static <X> void bar(J<X> j) {}
public static <Y> void bar2x(J2X<Y> j2x) {}
}
@@ -0,0 +1,94 @@
FILE fqName:<root> fileName:/samConversionToGeneric.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:<root>.J<kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): <root>.J<kotlin.String> declared in <root>'
TYPE_OP type=<root>.J<kotlin.String> origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String>
FUN_EXPR type=kotlin.Function1<kotlin.String?, kotlin.String?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.String?) returnType:kotlin.String?
VALUE_PARAMETER name:x index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (x: kotlin.String?): kotlin.String? declared in <root>.test1'
GET_VAR 'x: kotlin.String? declared in <root>.test1.<anonymous>' type=kotlin.String? origin=null
FUN name:test2 visibility:public modality:FINAL <> () returnType:<root>.J<kotlin.String?>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): <root>.J<kotlin.String?> declared in <root>'
TYPE_OP type=<root>.J<kotlin.String?> origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String?>
FUN_EXPR type=kotlin.Function1<kotlin.String, kotlin.String> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.String
VALUE_PARAMETER name:x index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (x: kotlin.String): kotlin.String declared in <root>.test2'
GET_VAR 'x: kotlin.String declared in <root>.test2.<anonymous>' type=kotlin.String origin=null
FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.Unit declared in <root>'
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: kotlin.String?
j: TYPE_OP type=<root>.J<kotlin.String?>? origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String?>?
FUN_EXPR type=kotlin.Function1<kotlin.String, kotlin.String> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.String
VALUE_PARAMETER name:x index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (x: kotlin.String): kotlin.String declared in <root>.test3'
GET_VAR 'x: kotlin.String declared in <root>.test3.<anonymous>' type=kotlin.String origin=null
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=<root>.J<kotlin.String> origin=CAST typeOperand=<root>.J<kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: kotlin.String?
j: TYPE_OP type=<root>.J<kotlin.String?> origin=IMPLICIT_CAST typeOperand=<root>.J<kotlin.String?>
GET_VAR 'a: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=kotlin.Function1<kotlin.String, kotlin.String> origin=CAST typeOperand=kotlin.Function1<kotlin.String, kotlin.String>
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: kotlin.String?
j: TYPE_OP type=<root>.J<kotlin.String?>? origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String?>?
TYPE_OP type=kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String?, kotlin.String?> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String?, kotlin.String?>
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
FUN name:test6 visibility:public modality:FINAL <T> (a:kotlin.Function1<T of <root>.test6, T of <root>.test6>) returnType:kotlin.Unit
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
VALUE_PARAMETER name:a index:0 type:kotlin.Function1<T of <root>.test6, T of <root>.test6>
BLOCK_BODY
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: T of <root>.test6?
j: TYPE_OP type=<root>.J<T of <root>.test6?>? origin=SAM_CONVERSION typeOperand=<root>.J<T of <root>.test6?>?
GET_VAR 'a: kotlin.Function1<T of <root>.test6, T of <root>.test6> declared in <root>.test6' type=kotlin.Function1<T of <root>.test6, T of <root>.test6> origin=null
FUN name:test7 visibility:public modality:FINAL <T> (a:kotlin.Any) returnType:kotlin.Unit
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
VALUE_PARAMETER name:a index:0 type:kotlin.Any
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=kotlin.Function1<T of <root>.test7, T of <root>.test7> origin=CAST typeOperand=kotlin.Function1<T of <root>.test7, T of <root>.test7>
GET_VAR 'a: kotlin.Any declared in <root>.test7' type=kotlin.Any origin=null
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: T of <root>.test7?
j: TYPE_OP type=<root>.J<T of <root>.test7?>? origin=SAM_CONVERSION typeOperand=<root>.J<T of <root>.test7?>?
TYPE_OP type=kotlin.Function1<@[ParameterName(name = 'x')] T of <root>.test7?, T of <root>.test7?> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 'x')] T of <root>.test7?, T of <root>.test7?>
GET_VAR 'a: kotlin.Any declared in <root>.test7' type=kotlin.Any origin=null
FUN name:test8 visibility:public modality:FINAL <> (efn:@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String>) returnType:<root>.J<kotlin.String?>
VALUE_PARAMETER name:efn index:0 type:@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test8 (efn: @[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String>): <root>.J<kotlin.String?> declared in <root>'
TYPE_OP type=<root>.J<kotlin.String?> origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String?>
GET_VAR 'efn: @[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test8' type=@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test9 visibility:public modality:FINAL <> (efn:@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String>) returnType:kotlin.Unit
VALUE_PARAMETER name:efn index:0 type:@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
CALL 'public open fun bar <X> (j: <root>.J<X of <root>.H.bar?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<X>: kotlin.String?
j: TYPE_OP type=<root>.J<kotlin.String?>? origin=SAM_CONVERSION typeOperand=<root>.J<kotlin.String?>?
GET_VAR 'efn: @[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.test9' type=@[ExtensionFunctionType] kotlin.Function1<kotlin.String, kotlin.String> origin=null
FUN name:test10 visibility:public modality:FINAL <> (fn:kotlin.Function1<kotlin.Int, kotlin.String>) returnType:kotlin.Unit
VALUE_PARAMETER name:fn index:0 type:kotlin.Function1<kotlin.Int, kotlin.String>
BLOCK_BODY
CALL 'public open fun bar2x <Y> (j2x: <root>.J2X<Y of <root>.H.bar2x?>?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
<Y>: kotlin.Int?
j2x: TYPE_OP type=<root>.J2X<kotlin.Int?>? origin=SAM_CONVERSION typeOperand=<root>.J2X<kotlin.Int?>?
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.String> declared in <root>.test10' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=null
@@ -1367,11 +1367,31 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/expressions/sam"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("samByProjectedType.kt")
public void testSamByProjectedType() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt");
}
@TestMetadata("samConstructors.kt")
public void testSamConstructors() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConstructors.kt");
}
@TestMetadata("samConversionInGenericConstructorCall.kt")
public void testSamConversionInGenericConstructorCall() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt");
}
@TestMetadata("samConversionInGenericConstructorCall_NI.kt")
public void testSamConversionInGenericConstructorCall_NI() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.kt");
}
@TestMetadata("samConversionToGeneric.kt")
public void testSamConversionToGeneric() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.kt");
}
@TestMetadata("samConversions.kt")
public void testSamConversions() throws Exception {
runTest("compiler/testData/ir/irText/expressions/sam/samConversions.kt");