Fix prematurely analyzing a lambda while fixing a type variable for another argument

^KT-35168 Fixed
This commit is contained in:
victor.petukhov
2019-11-28 15:56:59 +03:00
parent c4a115720e
commit e246c23a46
10 changed files with 37 additions and 8 deletions
@@ -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");
@@ -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)
@@ -139,7 +139,7 @@ class KotlinToResolvedCallTransformer(
)
if (!ErrorUtils.isError(candidate.candidateDescriptor)) {
for (subKtPrimitive in candidate.subResolvedAtoms) {
candidate.subResolvedAtoms?.forEach { subKtPrimitive ->
ktPrimitiveCompleter.completeAll(subKtPrimitive)
}
}
@@ -73,7 +73,7 @@ class ResolvedAtomCompleter(
}
fun completeAll(resolvedAtom: ResolvedAtom) {
for (subKtPrimitive in resolvedAtom.subResolvedAtoms) {
resolvedAtom.subResolvedAtoms?.forEach { subKtPrimitive ->
completeAll(subKtPrimitive)
}
complete(resolvedAtom)
@@ -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>) {
@@ -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");
@@ -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)