Fix for KT-11519: Version 1.0.1 fails with NPE in com.sun.beans.TypeResolver.resolve() where v1.0.0 works fine
#KT-11519 Fixed
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor;
|
||||
@@ -26,13 +25,12 @@ import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor;
|
||||
public class SamCodegenUtil {
|
||||
@Nullable
|
||||
public static FunctionDescriptor getOriginalIfSamAdapter(@NotNull FunctionDescriptor fun) {
|
||||
FunctionDescriptor original = fun.getOriginal();
|
||||
if (original instanceof SamAdapterDescriptor<?>) {
|
||||
return ((SamAdapterDescriptor<?>) original).getOriginForSam();
|
||||
if (fun instanceof SamAdapterDescriptor<?>) {
|
||||
return ((SamAdapterDescriptor<?>) fun).getOriginForSam();
|
||||
}
|
||||
|
||||
if (original instanceof SamAdapterExtensionFunctionDescriptor) {
|
||||
return ((SamAdapterExtensionFunctionDescriptor) original).getSourceFunction();
|
||||
if (fun instanceof SamAdapterExtensionFunctionDescriptor) {
|
||||
return ((SamAdapterExtensionFunctionDescriptor) fun).getSourceFunction();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+3
-4
@@ -26,10 +26,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cfg.WhenChecker;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.TypeMapperUtilsKt;
|
||||
import org.jetbrains.kotlin.codegen.when.SwitchCodegenUtil;
|
||||
import org.jetbrains.kotlin.codegen.when.WhenByEnumsMapping;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl;
|
||||
import org.jetbrains.kotlin.fileClasses.FileClasses;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor;
|
||||
@@ -46,8 +46,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.EnumValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
@@ -411,7 +410,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
if (valueArguments == null) return;
|
||||
|
||||
for (ValueParameterDescriptor valueParameter : original.getValueParameters()) {
|
||||
SamType samType = SamType.create(valueParameter.getType());
|
||||
SamType samType = SamType.create(TypeMapperUtilsKt.removeExternalProjections(valueParameter.getType()));
|
||||
if (samType == null) continue;
|
||||
|
||||
ResolvedValueArgument resolvedValueArgument = valueArguments.get(valueParameter.getIndex());
|
||||
|
||||
@@ -78,4 +78,9 @@ fun CallableMemberDescriptor.createTypeParameterWithNewName(descriptor: TypePara
|
||||
}
|
||||
newDescriptor.setInitialized()
|
||||
return newDescriptor
|
||||
}
|
||||
|
||||
fun KotlinType.removeExternalProjections(): KotlinType {
|
||||
val newArguments = arguments.map { TypeProjectionImpl(Variance.INVARIANT, it.type) }
|
||||
return replace(newArguments)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// FILE: Custom.java
|
||||
|
||||
class Custom<K, V> {
|
||||
private K k;
|
||||
|
||||
private V v;
|
||||
|
||||
public Custom(K k, V v) {
|
||||
this.k = k;
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
public interface MBiConsumer<T, U> {
|
||||
void accept(T t, U u);
|
||||
}
|
||||
|
||||
public void forEach(MBiConsumer<? super K, ? super V> action) {
|
||||
action.accept(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
import java.util.Arrays
|
||||
|
||||
fun box(): String {
|
||||
val instance = Custom<String, String>("O", "K")
|
||||
var result = "fail"
|
||||
instance.forEach { a, b ->
|
||||
result = a + b
|
||||
}
|
||||
|
||||
val superInterfaces = Arrays.toString((Class.forName("_1Kt\$box$1")).genericInterfaces)
|
||||
if (superInterfaces != "[Custom.Custom\$MBiConsumer<java.lang.String, java.lang.String>]") {
|
||||
return "fail: $superInterfaces"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// FILE: Custom.java
|
||||
|
||||
class Custom<K, V> {
|
||||
public interface MBiConsumer<T, U> {
|
||||
void accept(T t, U u);
|
||||
}
|
||||
|
||||
private K k;
|
||||
|
||||
private V v;
|
||||
|
||||
public Custom(K k, V v) {
|
||||
this.k = k;
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
public void forEach(MBiConsumer<? super K, ? super V> action) {
|
||||
action.accept(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
import java.util.Arrays
|
||||
|
||||
fun box(): String {
|
||||
val instance = Custom<String, String>("O", "K")
|
||||
var result = "fail"
|
||||
instance.forEach (Custom.MBiConsumer<String, String> { a, b ->
|
||||
result = a + b
|
||||
})
|
||||
|
||||
val superInterfaces = Arrays.toString((Class.forName("_1Kt\$box$1")).genericInterfaces)
|
||||
if (superInterfaces != "[Custom.Custom\$MBiConsumer<java.lang.String, java.lang.String>]") {
|
||||
return "fail: $superInterfaces"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+12
@@ -481,6 +481,18 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11519.kt")
|
||||
public void testKt11519() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/sam/kt11519.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt11519Constructor.kt")
|
||||
public void testKt11519Constructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/sam/kt11519Constructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt4753.kt")
|
||||
public void testKt4753() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/sam/kt4753.kt");
|
||||
|
||||
Reference in New Issue
Block a user