Fix SAM adapters substitution
Approximate sourceFunction types if it's needed #KT-11696 Fixed
This commit is contained in:
+4
-1
@@ -169,7 +169,10 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
|
||||
|
||||
}
|
||||
|
||||
val sourceFunctionSubstitutor = TypeSubstitutor.create(substitutionMap)
|
||||
val sourceFunctionSubstitutor =
|
||||
TypeConstructorSubstitution.createByConstructorsMap(
|
||||
substitutionMap, configuration.originalSubstitutor.substitution.approximateCapturedTypes()).buildSubstitutor()
|
||||
|
||||
descriptor.sourceFunction = original.sourceFunction.substitute(sourceFunctionSubstitutor)
|
||||
|
||||
return descriptor
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// FILE: Promise.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
interface Consumer<T> {
|
||||
void consume(T t);
|
||||
}
|
||||
|
||||
public abstract class Promise<T> {
|
||||
@NotNull
|
||||
public abstract Promise<T> done(@NotNull Consumer<? super T> done);
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
class User {
|
||||
fun use(promise: Promise<*>): Promise<*> {
|
||||
promise.done { }
|
||||
return promise
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
User().use(
|
||||
object : Promise<CharSequence>() {
|
||||
override fun done(x: Consumer<in CharSequence?>): Promise<CharSequence> {
|
||||
result = x.javaClass.genericInterfaces[0].toString()
|
||||
return this
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (result != "Consumer<java.lang.Object>") return "fail: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -493,6 +493,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11696.kt")
|
||||
public void testKt11696() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/sam/kt11696.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt4753.kt")
|
||||
public void testKt4753() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/sam/kt4753.kt");
|
||||
|
||||
@@ -47,10 +47,16 @@ abstract class TypeConstructorSubstitution : TypeSubstitution() {
|
||||
abstract fun get(key: TypeConstructor): TypeProjection?
|
||||
|
||||
companion object {
|
||||
@JvmStatic fun createByConstructorsMap(map: Map<TypeConstructor, TypeProjection>): TypeConstructorSubstitution =
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun createByConstructorsMap(
|
||||
map: Map<TypeConstructor, TypeProjection>,
|
||||
approximateCapturedTypes: Boolean = false
|
||||
): TypeConstructorSubstitution =
|
||||
object : TypeConstructorSubstitution() {
|
||||
override fun get(key: TypeConstructor) = map[key]
|
||||
override fun isEmpty() = map.isEmpty()
|
||||
override fun approximateCapturedTypes() = approximateCapturedTypes
|
||||
}
|
||||
|
||||
@JvmStatic fun createByParametersMap(map: Map<TypeParameterDescriptor, TypeProjection>): TypeConstructorSubstitution =
|
||||
|
||||
Reference in New Issue
Block a user