Support parenthesized left expression for ExpectedTypeFromCast
This commit is contained in:
+18
-5
@@ -180,12 +180,25 @@ class GenericCandidateResolver(
|
|||||||
|
|
||||||
private fun getBinaryWithTypeParent(calleeExpression: KtExpression?): KtBinaryExpressionWithTypeRHS? {
|
private fun getBinaryWithTypeParent(calleeExpression: KtExpression?): KtBinaryExpressionWithTypeRHS? {
|
||||||
val callExpression = calleeExpression?.parent.safeAs<KtCallExpression>() ?: return null
|
val callExpression = calleeExpression?.parent.safeAs<KtCallExpression>() ?: return null
|
||||||
val parent = callExpression.parent
|
val possibleQualifiedExpression = callExpression.parent
|
||||||
return when (parent) {
|
|
||||||
is KtBinaryExpressionWithTypeRHS -> parent
|
val targetExpression = if (possibleQualifiedExpression is KtQualifiedExpression) {
|
||||||
is KtQualifiedExpression -> parent.parent.safeAs<KtBinaryExpressionWithTypeRHS>().takeIf { parent.selectorExpression == callExpression }
|
if (possibleQualifiedExpression.selectorExpression != callExpression) return null
|
||||||
else -> null
|
possibleQualifiedExpression
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
callExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetExpression.topParenthesizedParentOrMe().parent.safeAs<KtBinaryExpressionWithTypeRHS>()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtExpression.topParenthesizedParentOrMe(): KtExpression {
|
||||||
|
var result: KtExpression = this
|
||||||
|
while (KtPsiUtil.deparenthesizeOnce(result.parent.safeAs()) == result) {
|
||||||
|
result = result.parent.safeAs() ?: break
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addValidityConstraintsForConstituentTypes(builder: ConstraintSystem.Builder, type: KotlinType) {
|
private fun addValidityConstraintsForConstituentTypes(builder: ConstraintSystem.Builder, type: KotlinType) {
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
// !LANGUAGE: +ExpectedTypeFromCast
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.EXPRESSION)
|
||||||
|
annotation class bar
|
||||||
|
|
||||||
|
fun <T> foo(): T = TODO()
|
||||||
|
|
||||||
|
fun <V> id(value: V) = value
|
||||||
|
|
||||||
|
val par1 = (foo()) as String
|
||||||
|
val par2 = ((foo())) as String
|
||||||
|
|
||||||
|
val par3 = (dd@ (foo())) as String
|
||||||
|
|
||||||
|
val par4 = ( @bar() (foo())) as String
|
||||||
|
|
||||||
|
object X {
|
||||||
|
fun <T> foo(): T = TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
val par5 = ( @bar() X.foo()) as String
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val par1: kotlin.String
|
||||||
|
public val par2: kotlin.String
|
||||||
|
public val par3: kotlin.String
|
||||||
|
public val par4: kotlin.String
|
||||||
|
public val par5: kotlin.String
|
||||||
|
public fun </*0*/ T> foo(): T
|
||||||
|
public fun </*0*/ V> id(/*0*/ value: V): V
|
||||||
|
|
||||||
|
public object X {
|
||||||
|
private constructor X()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun </*0*/ T> foo(): T
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.EXPRESSION}) public final annotation class bar : kotlin.Annotation {
|
||||||
|
public constructor bar()
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -10240,6 +10240,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expectedTypeFromCastParenthesized.kt")
|
||||||
|
public void testExpectedTypeFromCastParenthesized() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("expectedTypeWithGenerics.kt")
|
@TestMetadata("expectedTypeWithGenerics.kt")
|
||||||
public void testExpectedTypeWithGenerics() throws Exception {
|
public void testExpectedTypeWithGenerics() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
||||||
|
|||||||
+6
@@ -10240,6 +10240,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expectedTypeFromCastParenthesized.kt")
|
||||||
|
public void testExpectedTypeFromCastParenthesized() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("expectedTypeWithGenerics.kt")
|
@TestMetadata("expectedTypeWithGenerics.kt")
|
||||||
public void testExpectedTypeWithGenerics() throws Exception {
|
public void testExpectedTypeWithGenerics() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user