FE: Fix null assertion error when left is CollectionLiteral

#KT-49961 fixed
This commit is contained in:
Xin Wang
2022-05-16 22:33:19 +08:00
committed by Victor Petukhov
parent bd299ed12c
commit eb1d7110ec
9 changed files with 59 additions and 1 deletions
@@ -13870,6 +13870,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
}
@Test
@TestMetadata("kt49961.kt")
public void testKt49961() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt49961.kt");
}
@Test
@TestMetadata("kt51844.kt")
public void testKt51844() throws Exception {
@@ -13870,6 +13870,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
}
@Test
@TestMetadata("kt49961.kt")
public void testKt49961() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt49961.kt");
}
@Test
@TestMetadata("kt51844.kt")
public void testKt51844() throws Exception {
@@ -13870,6 +13870,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
}
@Test
@TestMetadata("kt49961.kt")
public void testKt49961() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt49961.kt");
}
@Test
@TestMetadata("kt51844.kt")
public void testKt51844() throws Exception {
@@ -224,6 +224,10 @@ public class ArgumentTypeResolver {
return null;
}
public static boolean isCollectionLiteralArgument(@NotNull KtExpression expression) {
return expression instanceof KtCollectionLiteralExpression;
}
@NotNull
public KotlinTypeInfo getArgumentTypeInfo(
@Nullable KtExpression expression,
@@ -1303,7 +1303,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinTypeInfo leftTypeInfo = BindingContextUtils.getRecordedTypeInfo(left, context.trace.getBindingContext());
boolean isLeftFunctionLiteral = ArgumentTypeResolver.isFunctionLiteralArgument(left, context);
boolean isLeftCallableReference = ArgumentTypeResolver.isCallableReferenceArgument(left, context);
if (leftTypeInfo == null && (isLeftFunctionLiteral || isLeftCallableReference)) {
boolean isLeftCollectionLiteral = ArgumentTypeResolver.isCollectionLiteralArgument(left);
if (leftTypeInfo == null && (isLeftFunctionLiteral || isLeftCallableReference || isLeftCollectionLiteral)) {
return TypeInfoFactoryKt.noTypeInfo(context);
}
assert leftTypeInfo != null : "Left expression was not processed: " + expression;
@@ -0,0 +1,10 @@
class Xyz {
fun x(): String? {
return try {
<!UNSUPPORTED!>[<!UNRESOLVED_REFERENCE!>a<!>]<!> <!USELESS_ELVIS!>?: <!UNRESOLVED_REFERENCE!>XYZ<!><!>
}
catch (e: Exception) {
null
}
}
}
@@ -0,0 +1,10 @@
class Xyz {
fun x(): String? {
return try {
<!TYPE_MISMATCH, UNSUPPORTED!>[<!UNRESOLVED_REFERENCE!>a<!>]<!> <!USELESS_ELVIS!>?: <!UNRESOLVED_REFERENCE!>XYZ<!><!>
}
catch (e: Exception) {
null
}
}
}
@@ -0,0 +1,9 @@
package
public final class Xyz {
public constructor Xyz()
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 final fun x(): kotlin.String?
}
@@ -13876,6 +13876,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
}
@Test
@TestMetadata("kt49961.kt")
public void testKt49961() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt49961.kt");
}
@Test
@TestMetadata("kt51844.kt")
public void testKt51844() throws Exception {