[NI] Transform anonymous types of expected type for delegation
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.common.collect.Lists
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
||||
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.OperatorCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.FROM_COMPLETER
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.toHandle
|
||||
@@ -566,7 +568,21 @@ class DelegatedPropertyResolver(
|
||||
|
||||
val call = delegateExpression.getCall(traceToResolveConventionMethods.bindingContext)
|
||||
val pretendReturnType = call.getResolvedCall(traceToResolveConventionMethods.bindingContext)?.resultingDescriptor?.returnType
|
||||
return pretendReturnType?.takeUnless { it.contains { it.constructor is TypeVariableTypeConstructor } }
|
||||
val expectedType = pretendReturnType?.takeUnless { it.contains { it.constructor is TypeVariableTypeConstructor } }
|
||||
return expectedType?.let { AnonymousTypeSubstitutor.safeSubstitute(it.unwrap()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object AnonymousTypeSubstitutor : NewTypeSubstitutor {
|
||||
override val isEmpty get() = true
|
||||
|
||||
override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? {
|
||||
val declarationDescriptor = constructor.declarationDescriptor
|
||||
if (declarationDescriptor is ClassifierDescriptor && DescriptorUtils.isAnonymousObject(declarationDescriptor)) {
|
||||
return constructor.supertypes.firstOrNull()?.unwrap()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val b: First by lazy {
|
||||
object : First { }
|
||||
}
|
||||
|
||||
private val withoutType by lazy {
|
||||
object : First { }
|
||||
}
|
||||
|
||||
private val withTwoSupertypes by lazy {
|
||||
object : First, Second { }
|
||||
}
|
||||
|
||||
interface First
|
||||
interface Second
|
||||
|
||||
fun box(): String {
|
||||
b
|
||||
withoutType
|
||||
withTwoSupertypes
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val b: First by lazy {
|
||||
object : First { }
|
||||
}
|
||||
|
||||
private val withoutType by lazy {
|
||||
object : First { }
|
||||
}
|
||||
|
||||
private val withTwoSupertypes by lazy {
|
||||
object : First, Second { }
|
||||
}
|
||||
|
||||
interface First
|
||||
interface Second
|
||||
|
||||
fun <T> lazy(initializer: () -> T): Lazy<T> = TODO()
|
||||
interface Lazy<out T> {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO()
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public val b: First
|
||||
private val withTwoSupertypes: withTwoSupertypes.<anonymous>.<no name provided>
|
||||
private val withoutType: withoutType.<anonymous>.<no name provided>
|
||||
public fun </*0*/ T> lazy(/*0*/ initializer: () -> T): Lazy<T>
|
||||
|
||||
public interface First {
|
||||
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 Lazy</*0*/ out T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Second {
|
||||
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
|
||||
}
|
||||
+6
@@ -17036,6 +17036,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectInsideDelegation.kt")
|
||||
public void testObjectInsideDelegation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToSelfInLocal.kt")
|
||||
public void testReferenceToSelfInLocal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/referenceToSelfInLocal.kt");
|
||||
|
||||
@@ -6099,6 +6099,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/typeOfLazyDelegatedPropertyWithObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useCompleterWithoutExpectedType.kt")
|
||||
public void testUseCompleterWithoutExpectedType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/inference/useCompleterWithoutExpectedType.kt");
|
||||
|
||||
@@ -17036,6 +17036,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectInsideDelegation.kt")
|
||||
public void testObjectInsideDelegation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToSelfInLocal.kt")
|
||||
public void testReferenceToSelfInLocal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/referenceToSelfInLocal.kt");
|
||||
|
||||
@@ -17036,6 +17036,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectInsideDelegation.kt")
|
||||
public void testObjectInsideDelegation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToSelfInLocal.kt")
|
||||
public void testReferenceToSelfInLocal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/referenceToSelfInLocal.kt");
|
||||
|
||||
+6
-6
@@ -2939,18 +2939,18 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-19634.java")
|
||||
public void testKt_19634() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-19634.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-17379.java")
|
||||
public void testKt_17379() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-17379.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-19634.java")
|
||||
public void testKt_19634() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-19634.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-5294.java")
|
||||
public void testKt_5294() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-5294.java");
|
||||
|
||||
+6
-6
@@ -2939,18 +2939,18 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-19634.java")
|
||||
public void testKt_19634() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-19634.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-17379.java")
|
||||
public void testKt_17379() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-17379.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-19634.java")
|
||||
public void testKt_19634() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-19634.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt-5294.java")
|
||||
public void testKt_5294() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/issues/kt-5294.java");
|
||||
|
||||
@@ -20810,6 +20810,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectInsideDelegation.kt")
|
||||
public void testObjectInsideDelegation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToSelfInLocal.kt")
|
||||
public void testReferenceToSelfInLocal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/referenceToSelfInLocal.kt");
|
||||
|
||||
Reference in New Issue
Block a user