[NI] Avoid forcing resolve for array access expression
#KT-31606 Fixed #EA-126523 Fixed
This commit is contained in:
+5
@@ -1704,6 +1704,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sam.kt")
|
||||
public void testSam() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/sam.kt");
|
||||
|
||||
+38
-8
@@ -1717,15 +1717,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
context, call, arrayAccessExpression, isGet ? OperatorNameConventions.GET : OperatorNameConventions.SET);
|
||||
|
||||
List<KtExpression> indices = arrayAccessExpression.getIndexExpressions();
|
||||
// The accumulated data flow info of all index expressions is saved on the last index
|
||||
KotlinTypeInfo resultTypeInfo = arrayTypeInfo;
|
||||
if (!indices.isEmpty()) {
|
||||
resultTypeInfo = facade.getTypeInfo(indices.get(indices.size() - 1), context);
|
||||
}
|
||||
|
||||
if (!isGet) {
|
||||
resultTypeInfo = facade.getTypeInfo(rightHandSide, context);
|
||||
}
|
||||
KotlinTypeInfo resultTypeInfo =
|
||||
computeAccumulatedInfoForArrayAccessExpression(arrayTypeInfo, indices, rightHandSide, isGet, context, facade);
|
||||
|
||||
if ((isImplicit && !functionResults.isSuccess()) || !functionResults.isSingleResult()) {
|
||||
traceForResolveResult.report(isGet ? NO_GET_METHOD.on(arrayAccessExpression) : NO_SET_METHOD.on(arrayAccessExpression));
|
||||
@@ -1735,4 +1729,40 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
functionResults.getResultingCall());
|
||||
return resultTypeInfo.replaceType(functionResults.getResultingDescriptor().getReturnType());
|
||||
}
|
||||
|
||||
private static KotlinTypeInfo computeAccumulatedInfoForArrayAccessExpression(
|
||||
@NotNull KotlinTypeInfo arrayTypeInfo,
|
||||
@NotNull List<KtExpression> indices,
|
||||
@Nullable KtExpression rightHandSide,
|
||||
boolean isGet,
|
||||
@NotNull ExpressionTypingContext context,
|
||||
@NotNull ExpressionTypingInternals facade
|
||||
) {
|
||||
KotlinTypeInfo accumulatedTypeInfo = null;
|
||||
boolean forceResolve = !context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference);
|
||||
|
||||
// The accumulated data flow info of all index expressions is saved on the last index
|
||||
if (!indices.isEmpty()) {
|
||||
accumulatedTypeInfo = getTypeInfo(indices.get(indices.size() - 1), facade, context, forceResolve);
|
||||
}
|
||||
|
||||
if (!isGet && rightHandSide != null) {
|
||||
accumulatedTypeInfo = getTypeInfo(rightHandSide, facade, context, forceResolve);
|
||||
}
|
||||
|
||||
return accumulatedTypeInfo != null ? accumulatedTypeInfo : arrayTypeInfo;
|
||||
}
|
||||
|
||||
private static KotlinTypeInfo getTypeInfo(
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull ExpressionTypingInternals facade,
|
||||
@NotNull ExpressionTypingContext context,
|
||||
boolean forceExpressionResolve
|
||||
) {
|
||||
if (forceExpressionResolve) {
|
||||
return facade.getTypeInfo(expression, context);
|
||||
} else {
|
||||
return BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class Sample(val str: String)
|
||||
|
||||
class Inv<T>
|
||||
|
||||
class Form {
|
||||
operator fun <F> get(field: KProperty1<*, F>): Inv<F> = TODO()
|
||||
}
|
||||
|
||||
fun <K> foo(i: Inv<K>) {}
|
||||
|
||||
fun test(f: Form) {
|
||||
foo(f[Sample::str])
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ K> foo(/*0*/ i: Inv<K>): kotlin.Unit
|
||||
public fun test(/*0*/ f: Form): kotlin.Unit
|
||||
|
||||
public final class Form {
|
||||
public constructor Form()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final operator fun </*0*/ F> get(/*0*/ field: kotlin.reflect.KProperty1<*, F>): Inv<F>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Inv</*0*/ T> {
|
||||
public constructor Inv</*0*/ 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
|
||||
}
|
||||
|
||||
public final class Sample {
|
||||
public constructor Sample(/*0*/ str: kotlin.String)
|
||||
public final val str: kotlin.String
|
||||
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
|
||||
}
|
||||
@@ -1711,6 +1711,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sam.kt")
|
||||
public void testSam() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/sam.kt");
|
||||
|
||||
Generated
+5
@@ -1706,6 +1706,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/parsingPriorityOfGenericArgumentsVsLess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sam.kt")
|
||||
public void testSam() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/sam.kt");
|
||||
|
||||
Reference in New Issue
Block a user