[NI] Use infered delegate expression type if there is no resolved call in trace
#KT-35707 Fixed
This commit is contained in:
@@ -632,16 +632,18 @@ class DelegatedPropertyResolver(
|
|||||||
result?.let { recordResolvedDelegateOrReportError(it.overloadResolutionResults, isGet) }
|
result?.let { recordResolvedDelegateOrReportError(it.overloadResolutionResults, isGet) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolvedDelegateType = extractResolvedDelegateType(delegateExpression, trace)
|
val resolvedDelegateType = extractResolvedDelegateType(delegateExpression, trace, delegateType)
|
||||||
trace.recordType(delegateExpression, resolvedDelegateType)
|
trace.recordType(delegateExpression, resolvedDelegateType)
|
||||||
trace.commit()
|
trace.commit()
|
||||||
return resolvedDelegateType.unwrap()
|
return resolvedDelegateType.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractResolvedDelegateType(delegateExpression: KtExpression, trace: BindingTrace): KotlinType {
|
private fun extractResolvedDelegateType(delegateExpression: KtExpression, trace: BindingTrace, delegateType: KotlinType): KotlinType {
|
||||||
val call = delegateExpression.getCall(trace.bindingContext)
|
val call = delegateExpression.getCall(trace.bindingContext)
|
||||||
val pretendReturnType = call.getResolvedCall(trace.bindingContext)?.resultingDescriptor?.returnType
|
val pretendReturnType = call.getResolvedCall(trace.bindingContext)?.resultingDescriptor?.returnType
|
||||||
return pretendReturnType?.takeUnless { !it.isProperType() } ?: ErrorUtils.createErrorType("Type for ${delegateExpression.text}")
|
return pretendReturnType?.takeIf { it.isProperType() }
|
||||||
|
?: delegateType.takeIf { it.isProperType() }
|
||||||
|
?: ErrorUtils.createErrorType("Type for ${delegateExpression.text}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinType.isProperType(): Boolean {
|
private fun KotlinType.isProperType(): Boolean {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// ISSUE: KT-35707
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
interface PropertyDelegate {
|
||||||
|
operator fun getValue(thisRef: A, property: KProperty<*>): Boolean = true
|
||||||
|
operator fun setValue(thisRef: A, property: KProperty<*>, value: Boolean) {}
|
||||||
|
}
|
||||||
|
class A {
|
||||||
|
val b by object : PropertyDelegate {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return if (A().b) {
|
||||||
|
"OK"
|
||||||
|
} else {
|
||||||
|
"FAIL"
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -9711,6 +9711,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
+5
@@ -9711,6 +9711,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
+5
@@ -8561,6 +8561,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
+5
@@ -8561,6 +8561,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
Generated
+5
@@ -7361,6 +7361,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
+5
@@ -8436,6 +8436,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/insideInlinedObjectMultiModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35707.kt")
|
||||||
|
public void testKt35707() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt35707.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4138.kt")
|
@TestMetadata("kt4138.kt")
|
||||||
public void testKt4138() throws Exception {
|
public void testKt4138() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user