Fix prematurely analyzing a lambda while fixing a type variable for another argument
^KT-35168 Fixed
This commit is contained in:
+5
@@ -8017,6 +8017,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt")
|
||||
public void testPrematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("returnNull.kt")
|
||||
public void testReturnNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt");
|
||||
|
||||
+1
-1
@@ -206,7 +206,7 @@ class CoroutineInferenceSession(
|
||||
val atomCompleter = createResolvedAtomCompleter(resultingSubstitutor, completedCall.context)
|
||||
val resultCallAtom = completedCall.callResolutionResult.resultCallAtom
|
||||
|
||||
for (subResolvedAtom in resultCallAtom.subResolvedAtoms) {
|
||||
resultCallAtom.subResolvedAtoms?.forEach { subResolvedAtom ->
|
||||
atomCompleter.completeAll(subResolvedAtom)
|
||||
}
|
||||
atomCompleter.completeResolvedCall(resultCallAtom, completedCall.callResolutionResult.diagnostics)
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ class KotlinToResolvedCallTransformer(
|
||||
)
|
||||
|
||||
if (!ErrorUtils.isError(candidate.candidateDescriptor)) {
|
||||
for (subKtPrimitive in candidate.subResolvedAtoms) {
|
||||
candidate.subResolvedAtoms?.forEach { subKtPrimitive ->
|
||||
ktPrimitiveCompleter.completeAll(subKtPrimitive)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class ResolvedAtomCompleter(
|
||||
}
|
||||
|
||||
fun completeAll(resolvedAtom: ResolvedAtom) {
|
||||
for (subKtPrimitive in resolvedAtom.subResolvedAtoms) {
|
||||
resolvedAtom.subResolvedAtoms?.forEach { subKtPrimitive ->
|
||||
completeAll(subKtPrimitive)
|
||||
}
|
||||
complete(resolvedAtom)
|
||||
|
||||
+3
-3
@@ -145,7 +145,7 @@ class KotlinConstraintSystemCompleter(
|
||||
to.addIfNotNull(this.safeAs<PostponedResolvedAtom>()?.takeUnless { it.analyzed })
|
||||
|
||||
if (analyzed) {
|
||||
subResolvedAtoms.forEach { it.process(to) }
|
||||
subResolvedAtoms?.forEach { it.process(to) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class KotlinConstraintSystemCompleter(
|
||||
}
|
||||
|
||||
if (analyzed) {
|
||||
subResolvedAtoms.forEach { it.process(to) }
|
||||
subResolvedAtoms?.forEach { it.process(to) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ class KotlinConstraintSystemCompleter(
|
||||
return this
|
||||
}
|
||||
|
||||
subResolvedAtoms.forEach { subResolvedAtom ->
|
||||
subResolvedAtoms?.forEach { subResolvedAtom ->
|
||||
subResolvedAtom.check()?.let { result -> return@check result }
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ sealed class ResolvedAtom {
|
||||
var analyzed: Boolean = false
|
||||
private set
|
||||
|
||||
lateinit var subResolvedAtoms: List<ResolvedAtom>
|
||||
var subResolvedAtoms: List<ResolvedAtom>? = null
|
||||
private set
|
||||
|
||||
protected open fun setAnalyzedResults(subResolvedAtoms: List<ResolvedAtom>) {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: +NewInference
|
||||
// SKIP_TXT
|
||||
// Issue: KT-35168
|
||||
|
||||
class Inv<T>
|
||||
|
||||
// Before the fix, here we had an exception while fixing a type variable for Inv due to prematurely analyzing a lambda
|
||||
// The exception was: "UninitializedPropertyAccessException: lateinit property subResolvedAtoms has not been initialized"
|
||||
class Foo<T>(x: (T) -> T, y: Inv<Any>)
|
||||
|
||||
fun bar() {
|
||||
Foo<Any>({}, Inv())
|
||||
}
|
||||
@@ -8024,6 +8024,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt")
|
||||
public void testPrematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("returnNull.kt")
|
||||
public void testReturnNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt");
|
||||
|
||||
Generated
+5
@@ -8019,6 +8019,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/LabeledFunctionLiterals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt")
|
||||
public void testPrematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/prematurelyAnalyzingLambdaWhileFixingTypeVariableForAnotherArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("returnNull.kt")
|
||||
public void testReturnNull() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt");
|
||||
|
||||
@@ -72,7 +72,7 @@ fun ResolvedCall<*>.hasLastFunctionalParameterWithResult(context: BindingContext
|
||||
val lastArgument = valueArguments[lastParameter]?.arguments?.singleOrNull() ?: return false
|
||||
if (this is NewResolvedCallImpl<*>) {
|
||||
// TODO: looks like hack
|
||||
resolvedCallAtom.subResolvedAtoms.firstOrNull { it is ResolvedLambdaAtom }.safeAs<ResolvedLambdaAtom>()?.let { lambdaAtom ->
|
||||
resolvedCallAtom.subResolvedAtoms?.firstOrNull { it is ResolvedLambdaAtom }.safeAs<ResolvedLambdaAtom>()?.let { lambdaAtom ->
|
||||
return lambdaAtom.resultArguments.filterIsInstance<ReceiverKotlinCallArgument>().all {
|
||||
val type = it.receiverValue?.type ?: return@all false
|
||||
predicate(type)
|
||||
|
||||
Reference in New Issue
Block a user