Changes on code review
This commit is contained in:
+7
-7
@@ -86,7 +86,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetType getFunctionTypeForSamType(@NotNull JetType samType, boolean isSamConstructor) {
|
||||
private static JetType getFunctionTypeForSamType(@NotNull JetType samType) {
|
||||
// e.g. samType == Comparator<String>?
|
||||
|
||||
ClassifierDescriptor classifier = samType.getConstructor().getDeclarationDescriptor();
|
||||
@@ -103,11 +103,11 @@ public class SingleAbstractMethodUtils {
|
||||
JetType type = fixProjections(substitute);
|
||||
if (type == null) return null;
|
||||
|
||||
if (JvmPackage.getPLATFORM_TYPES() && !isSamConstructor && TypesPackage.isNullabilityFlexible(samType)) {
|
||||
if (JvmPackage.getPLATFORM_TYPES() && TypesPackage.isNullabilityFlexible(samType)) {
|
||||
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(type, TypeUtils.makeNullable(type));
|
||||
}
|
||||
|
||||
return TypeUtils.makeNullableAsSpecified(type, !isSamConstructor && samType.isMarkedNullable());
|
||||
return TypeUtils.makeNullableAsSpecified(type, samType.isMarkedNullable());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -151,7 +151,7 @@ public class SingleAbstractMethodUtils {
|
||||
|
||||
TypeParameters typeParameters = recreateAndInitializeTypeParameters(samInterface.getTypeConstructor().getParameters(), result);
|
||||
|
||||
JetType parameterTypeUnsubstituted = getFunctionTypeForSamType(samInterface.getDefaultType(), true);
|
||||
JetType parameterTypeUnsubstituted = getFunctionTypeForSamType(samInterface.getDefaultType());
|
||||
assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + samInterface.getDefaultType();
|
||||
JetType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
assert parameterType != null : "couldn't substitute type: " + parameterTypeUnsubstituted +
|
||||
@@ -177,7 +177,7 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
public static boolean isSamType(@NotNull JetType type) {
|
||||
return getFunctionTypeForSamType(type, /* irrelevant */ false) != null;
|
||||
return getFunctionTypeForSamType(type) != null;
|
||||
}
|
||||
|
||||
public static boolean isSamAdapterNecessary(@NotNull FunctionDescriptor fun) {
|
||||
@@ -240,7 +240,7 @@ public class SingleAbstractMethodUtils {
|
||||
assert returnTypeUnsubstituted != null : "Creating SAM adapter for not initialized original: " + original;
|
||||
|
||||
TypeSubstitutor substitutor = typeParameters.substitutor;
|
||||
JetType returnType = substitutor.substitute(returnTypeUnsubstituted, Variance.OUT_VARIANCE);
|
||||
JetType returnType = substitutor.substitute(returnTypeUnsubstituted, Variance.INVARIANT);
|
||||
assert returnType != null : "couldn't substitute type: " + returnTypeUnsubstituted +
|
||||
", substitutor = " + substitutor;
|
||||
|
||||
@@ -261,7 +261,7 @@ public class SingleAbstractMethodUtils {
|
||||
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(originalValueParameters.size());
|
||||
for (ValueParameterDescriptor originalParam : originalValueParameters) {
|
||||
JetType originalType = originalParam.getType();
|
||||
JetType functionType = getFunctionTypeForSamType(originalType, false);
|
||||
JetType functionType = getFunctionTypeForSamType(originalType);
|
||||
JetType newTypeUnsubstituted = functionType != null ? functionType : originalType;
|
||||
JetType newType = substitutor.substitute(newTypeUnsubstituted, Variance.IN_VARIANCE);
|
||||
assert newType != null : "couldn't substitute type: " + newTypeUnsubstituted + ", substitutor = " + substitutor;
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : JetScope by Jet
|
||||
val typeParameters = ArrayList<TypeParameterDescriptor>(typeParamsSum.size())
|
||||
val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(typeParamsSum, TypeSubstitution.EMPTY, this, typeParameters)
|
||||
|
||||
val returnType = typeSubstitutor.safeSubstitute(originalFunction.returnType!!, Variance.OUT_VARIANCE)
|
||||
val returnType = typeSubstitutor.safeSubstitute(originalFunction.returnType!!, Variance.INVARIANT)
|
||||
val receiverType = typeSubstitutor.safeSubstitute(ownerClass.defaultType, Variance.INVARIANT)
|
||||
val valueParameters = SingleAbstractMethodUtils.createValueParametersForSamAdapter(originalFunction, this, typeSubstitutor)
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// FILE: Super.java
|
||||
class Super {
|
||||
void foo(Runnable r) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Sub.kt
|
||||
class Sub() : Super() {
|
||||
fun foo(<!UNUSED_PARAMETER!>r<!> : (() -> Unit)?) {
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
internal final class Sub : Super {
|
||||
public constructor Sub()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(/*0*/ r: (() -> kotlin.Unit)?): kotlin.Unit
|
||||
public/*package*/ open override /*1*/ /*fake_override*/ fun foo(/*0*/ r: java.lang.Runnable!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public/*package*/ open class Super {
|
||||
public/*package*/ constructor Super()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public/*package*/ open fun foo(/*0*/ r: java.lang.Runnable!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-2
@@ -3,8 +3,6 @@ fun foo(javaClass: JavaClass<String>): String {
|
||||
return javaClass.doSomething("", 1) { s: String -> "" }
|
||||
}
|
||||
|
||||
fun useString(<!UNUSED_PARAMETER!>s<!>: String) {}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass<T> {
|
||||
public T doSomething(T t, int anInt, I<T> i) { return t; }
|
||||
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ javaClass: JavaClass<kotlin.String>): kotlin.String
|
||||
internal fun useString(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
|
||||
public open class JavaClass</*0*/ T : kotlin.Any!> {
|
||||
public constructor JavaClass</*0*/ T : kotlin.Any!>()
|
||||
|
||||
Vendored
+5
-3
@@ -1,11 +1,13 @@
|
||||
// FILE: KotlinFile.kt
|
||||
fun foo(javaClass: JavaClass<Int>): String {
|
||||
return javaClass.doSomething("", 1) { it }
|
||||
fun foo(javaClass: JavaClass<Int>) {
|
||||
val <!UNUSED_VARIABLE!>a<!>: String = javaClass.doSomething1("", 1) { p: String -> p }
|
||||
val <!UNUSED_VARIABLE!>b<!>: String = javaClass.doSomething2("", 1, true) { p: Int -> p }
|
||||
}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass<X> {
|
||||
public <T> T doSomething(T t, X x, I<T> i) { return i.run(t); }
|
||||
public <T> T doSomething1(T t, X x, I<T> i) { return i.run(t); }
|
||||
public <T> T doSomething2(T t, X x, boolean p, I<X> i) { return i.run(t); }
|
||||
}
|
||||
|
||||
interface I<T> {
|
||||
|
||||
Vendored
+3
-2
@@ -1,10 +1,11 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ javaClass: JavaClass<kotlin.Int>): kotlin.String
|
||||
internal fun foo(/*0*/ javaClass: JavaClass<kotlin.Int>): kotlin.Unit
|
||||
|
||||
public open class JavaClass</*0*/ X : kotlin.Any!> {
|
||||
public constructor JavaClass</*0*/ X : kotlin.Any!>()
|
||||
public open fun </*0*/ T : kotlin.Any!> doSomething(/*0*/ t: T!, /*1*/ x: X!, /*2*/ i: I<T!>!): T!
|
||||
public open fun </*0*/ T : kotlin.Any!> doSomething1(/*0*/ t: T!, /*1*/ x: X!, /*2*/ i: I<T!>!): T!
|
||||
public open fun </*0*/ T : kotlin.Any!> doSomething2(/*0*/ t: T!, /*1*/ x: X!, /*2*/ p: kotlin.Boolean, /*3*/ i: I<X!>!): T!
|
||||
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
|
||||
|
||||
+4
-8
@@ -1,20 +1,16 @@
|
||||
// FILE: KotlinFile.kt
|
||||
fun foo(javaClass: JavaClass<Int>) {
|
||||
fun foo(javaClass: JavaClass<Int>): Int {
|
||||
val inner = javaClass.createInner<String>()
|
||||
inner.doSomething(1, "") {
|
||||
bar()
|
||||
}
|
||||
return inner.doSomething(1, "") { }
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass<T> {
|
||||
public <X> Inner<X> createInner() {
|
||||
return new Inner<X>();
|
||||
}
|
||||
|
||||
public class Inner<X>{
|
||||
public void doSomething(T t, X x, Runnable runnable) { runnable.run(); }
|
||||
public interface Inner<X>{
|
||||
public T doSomething(T t, X x, Runnable runnable);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+6
-5
@@ -1,7 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun bar(): kotlin.Unit
|
||||
internal fun foo(/*0*/ javaClass: JavaClass<kotlin.Int>): kotlin.Unit
|
||||
internal fun foo(/*0*/ javaClass: JavaClass<kotlin.Int>): kotlin.Int
|
||||
|
||||
public open class JavaClass</*0*/ T : kotlin.Any!> {
|
||||
public constructor JavaClass</*0*/ T : kotlin.Any!>()
|
||||
@@ -10,11 +9,13 @@ public open class JavaClass</*0*/ T : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public open inner class Inner</*0*/ X : kotlin.Any!> {
|
||||
public constructor Inner</*0*/ X : kotlin.Any!>()
|
||||
public open fun doSomething(/*0*/ t: T!, /*1*/ x: X!, /*2*/ runnable: java.lang.Runnable!): kotlin.Unit
|
||||
public interface Inner</*0*/ X : kotlin.Any!> {
|
||||
public abstract fun doSomething(/*0*/ t: T!, /*1*/ x: X!, /*2*/ runnable: java.lang.Runnable!): T!
|
||||
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
|
||||
}
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun </*0*/ X : kotlin.Any!> Inner(/*0*/ function: (T!, X!, java.lang.Runnable!) -> T!): JavaClass.Inner<X>
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,4 +1,4 @@
|
||||
// FILE: KotlinFile.kt
|
||||
// FILE: KotlinFile1.kt
|
||||
package k
|
||||
|
||||
import JavaClass
|
||||
@@ -7,6 +7,11 @@ fun foo(javaClass: JavaClass) {
|
||||
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!TYPE_MISMATCH!>{ }<!>
|
||||
}
|
||||
|
||||
// FILE: KotlinFile2.kt
|
||||
fun foo(javaClass: JavaClass) {
|
||||
javaClass.doSomething { }
|
||||
}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass {
|
||||
void doSomething(Runnable runnable) { runnable.run(); }
|
||||
|
||||
+2
@@ -1,5 +1,7 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ javaClass: JavaClass): kotlin.Unit
|
||||
|
||||
public open class JavaClass {
|
||||
public constructor JavaClass()
|
||||
public/*package*/ open fun doSomething(/*0*/ runnable: java.lang.Runnable!): kotlin.Unit
|
||||
|
||||
-4
@@ -1,8 +1,4 @@
|
||||
// FILE: KotlinFile.kt
|
||||
package k
|
||||
|
||||
import JavaClass
|
||||
|
||||
fun foo(javaClass: JavaClass) {
|
||||
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!TYPE_MISMATCH!>{ }<!>
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,5 +1,7 @@
|
||||
package
|
||||
|
||||
internal fun foo(/*0*/ javaClass: JavaClass): kotlin.Unit
|
||||
|
||||
public open class JavaClass {
|
||||
public constructor JavaClass()
|
||||
private open fun doSomething(/*0*/ runnable: java.lang.Runnable!): kotlin.Unit
|
||||
@@ -7,7 +9,3 @@ public open class JavaClass {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
package k {
|
||||
internal fun foo(/*0*/ javaClass: JavaClass): kotlin.Unit
|
||||
}
|
||||
|
||||
Vendored
+1
-2
@@ -1,7 +1,6 @@
|
||||
// FILE: KotlinFile.kt
|
||||
fun foo(javaInterface: JavaInterface) {
|
||||
val value: String?
|
||||
value = javaInterface.compute { "" }
|
||||
val value = javaInterface.compute { "" }
|
||||
value<!UNSAFE_CALL!>.<!>length()
|
||||
}
|
||||
|
||||
|
||||
@@ -8382,6 +8382,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("canDeclareIfSamAdapterIsInherited.kt")
|
||||
public void testCanDeclareIfSamAdapterIsInherited() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("computeIfAbsentConcurrent.kt")
|
||||
public void testComputeIfAbsentConcurrent() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/computeIfAbsentConcurrent.kt");
|
||||
|
||||
Reference in New Issue
Block a user