[NI] Run completion on subatoms of error calls

Call transformer previously ran completion of argument atoms
only for non-error candidates. This led to missing diagnostics,
i.e. from collection literal resolver.

Now arguments of calls resolved to error descriptor are completed,
with exception to not found provideDelegate calls.
provideDelegate's subatoms are not completed after failure, because
it is a part of delegate competion, which does not end with
unresolved provideDelegate.
Completing after provideDelegate failure removes constraint system
from resolved arguments, which breaks resolve for get/setValue.

^KT-33592 Fixed
This commit is contained in:
Pavel Kirpichenkov
2019-12-02 20:07:17 +03:00
parent 29fbb8e22f
commit 3de6289c6c
16 changed files with 73 additions and 10 deletions
@@ -3430,6 +3430,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.kt");
}
@TestMetadata("collectionLiteralsOutsideOfAnnotations.kt")
public void testCollectionLiteralsOutsideOfAnnotations() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.kt");
}
@TestMetadata("collectionLiteralsWithVarargs.kt")
public void testCollectionLiteralsWithVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt");
@@ -49,8 +49,8 @@ class DelegatedPropertyInferenceSession(
private fun ResolvedCallAtom.addConstraintForThis(descriptor: CallableDescriptor, commonSystem: ConstraintSystemBuilder) {
val typeOfThis = variableDescriptor.extensionReceiverParameter?.type
?: variableDescriptor.dispatchReceiverParameter?.type
?: builtIns.nullableNothingType
?: variableDescriptor.dispatchReceiverParameter?.type
?: builtIns.nullableNothingType
val valueParameterForThis = descriptor.valueParameters.getOrNull(0) ?: return
val substitutedType = freshVariablesSubstitutor.safeSubstitute(valueParameterForThis.type.unwrap())
@@ -85,6 +85,8 @@ class DelegatedPropertyInferenceSession(
): Map<TypeConstructor, UnwrappedType> = emptyMap()
override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
}
object InferenceSessionForExistingCandidates : InferenceSession {
@@ -104,4 +106,7 @@ object InferenceSessionForExistingCandidates : InferenceSession {
override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false
override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom): Boolean {
return !ErrorUtils.isError(resolvedCallAtom.candidateDescriptor)
}
}
@@ -107,6 +107,8 @@ class CoroutineInferenceSession(
return commonSystem.fixedTypeVariables.cast() // TODO: SUB
}
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
private fun createNonFixedTypeToVariableSubstitutor(): NewTypeSubstitutorByConstructorMap {
val bindings = hashMapOf<TypeConstructor, UnwrappedType>()
for ((variable, nonFixedType) in stubsForPostponedVariables) {
@@ -138,7 +138,7 @@ class KotlinToResolvedCallTransformer(
typeApproximator, missingSupertypesResolver
)
if (!ErrorUtils.isError(candidate.candidateDescriptor)) {
if (context.inferenceSession.shouldCompleteResolvedSubAtomsOf(candidate)) {
candidate.subResolvedAtoms?.forEach { subKtPrimitive ->
ktPrimitiveCompleter.completeAll(subKtPrimitive)
}
@@ -61,6 +61,8 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean =
!completedCalls.add(resolvedAtom)
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
fun resolveCandidates(resolutionCallbacks: KotlinResolutionCallbacks): List<ResolutionResultCallInfo<D>> {
val resolvedCallsInfo = partiallyResolvedCallsInfo.toList()
@@ -73,6 +73,8 @@ class ResolvedAtomCompleter(
}
fun completeAll(resolvedAtom: ResolvedAtom) {
if (!resolvedAtom.analyzed)
return
resolvedAtom.subResolvedAtoms?.forEach { subKtPrimitive ->
completeAll(subKtPrimitive)
}
@@ -26,6 +26,7 @@ interface InferenceSession {
override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false
override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
}
}
@@ -37,6 +38,7 @@ interface InferenceSession {
fun inferPostponedVariables(lambda: ResolvedLambdaAtom, initialStorage: ConstraintStorage): Map<TypeConstructor, UnwrappedType>
fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean
fun callCompleted(resolvedAtom: ResolvedAtom): Boolean
fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom): Boolean
}
interface PartialCallInfo {
@@ -15,5 +15,5 @@ fun take(f: () -> Unit) {}
fun test() {
B::foo checkType { _<KFunction1<B, Unit>>() }
<!NONE_APPLICABLE!>take<!>(B::<!NI;DEBUG_INFO_MISSING_UNRESOLVED!>foo<!>)
<!NONE_APPLICABLE!>take<!>(B::foo)
}
@@ -11,7 +11,7 @@ class Foo {
}
fun foo() {
<!NI;NONE_APPLICABLE, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>installRoute<!><Any>(::<!NI;DEBUG_INFO_MISSING_UNRESOLVED!>route<!>)
<!NI;NONE_APPLICABLE, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>installRoute<!><Any>(::route)
}
}
@@ -22,7 +22,7 @@ val x1 = fn1(1, ::foo, ::foo)
val x2 = fn1(1, ::foo, ::bar)
val x3 = fn2(::bar, ::foo)
val x4 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!NI;DEBUG_INFO_MISSING_UNRESOLVED, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::<!NI;DEBUG_INFO_MISSING_UNRESOLVED!>bar<!>)
val x4 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!NI;DEBUG_INFO_MISSING_UNRESOLVED, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::bar)
val x5 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!NI;DEBUG_INFO_MISSING_UNRESOLVED, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::<!NI;DEBUG_INFO_MISSING_UNRESOLVED, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
val x6 = fn3(1, ::qux)
@@ -0,0 +1,22 @@
// !LANGUAGE: +NewInference
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun takeArray(array: Array<String>) {}
fun test() {
"foo bar".<!UNRESOLVED_REFERENCE!>split<!>(<!UNSUPPORTED!>[""]<!>)
<!UNRESOLVED_REFERENCE!>unresolved<!>(<!UNSUPPORTED!>[""]<!>)
takeArray(<!UNSUPPORTED!>[""]<!>)
val v = <!UNSUPPORTED!>[""]<!>
<!UNSUPPORTED!>[""]<!>
<!UNSUPPORTED!>[1, 2, 3]<!>.size
}
fun baz(arg: Array<Int> = <!UNSUPPORTED!>[]<!>) {
if (true) <!UNSUPPORTED!>["yes"]<!> else {<!UNSUPPORTED!>["no"]<!>}
}
class Foo(
val v: Array<Int> = <!UNSUPPORTED!>[]<!>
)
@@ -0,0 +1,13 @@
package
public fun baz(/*0*/ arg: kotlin.Array<kotlin.Int> = ...): kotlin.Unit
public fun takeArray(/*0*/ array: kotlin.Array<kotlin.String>): kotlin.Unit
public fun test(): kotlin.Unit
public final class Foo {
public constructor Foo(/*0*/ v: kotlin.Array<kotlin.Int> = ...)
public final val v: kotlin.Array<kotlin.Int>
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
}
@@ -3437,6 +3437,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.kt");
}
@TestMetadata("collectionLiteralsOutsideOfAnnotations.kt")
public void testCollectionLiteralsOutsideOfAnnotations() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.kt");
}
@TestMetadata("collectionLiteralsWithVarargs.kt")
public void testCollectionLiteralsWithVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt");
@@ -3432,6 +3432,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsAsPrimitiveArrays.kt");
}
@TestMetadata("collectionLiteralsOutsideOfAnnotations.kt")
public void testCollectionLiteralsOutsideOfAnnotations() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsOutsideOfAnnotations.kt");
}
@TestMetadata("collectionLiteralsWithVarargs.kt")
public void testCollectionLiteralsWithVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt");
@@ -6,9 +6,9 @@ UFile (package = ) [public final class InferenceInsideUnresolvedConstructorKt {.
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [<anonymous class>(id(42))]
UIdentifier (Identifier (Unresolved)) [UIdentifier (Identifier (Unresolved))]
USimpleNameReferenceExpression (identifier = <anonymous class>, resolvesTo = null) [<anonymous class>]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [id(42)] : PsiType:<ErrorType>
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [id(42)] : PsiType:int
UIdentifier (Identifier (id)) [UIdentifier (Identifier (id))]
USimpleNameReferenceExpression (identifier = id, resolvesTo = null) [id] : PsiType:<ErrorType>
USimpleNameReferenceExpression (identifier = id, resolvesTo = null) [id] : PsiType:int
ULiteralExpression (value = 42) [42] : PsiType:int
UMethod (name = id) [public static final fun id(@org.jetbrains.annotations.Nullable x: T) : T {...}]
UParameter (name = x) [@org.jetbrains.annotations.Nullable var x: T]
@@ -13,9 +13,9 @@ UFile (package = ) [public final class InnerNonFixedTypeVariableKt {...]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) [<ERROR FUNCTION>(mutableSetOf(), { ...})] : PsiType:<ErrorType>
UIdentifier (Identifier (mapTo)) [UIdentifier (Identifier (mapTo))]
USimpleNameReferenceExpression (identifier = <ERROR FUNCTION>, resolvesTo = null) [<ERROR FUNCTION>] : PsiType:<ErrorType>
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [mutableSetOf()] : PsiType:<ErrorType>
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [mutableSetOf()] : PsiType:Set<NonExistentClass>
UIdentifier (Identifier (mutableSetOf)) [UIdentifier (Identifier (mutableSetOf))]
USimpleNameReferenceExpression (identifier = mutableSetOf, resolvesTo = null) [mutableSetOf] : PsiType:<ErrorType>
USimpleNameReferenceExpression (identifier = mutableSetOf, resolvesTo = null) [mutableSetOf] : PsiType:Set<NonExistentClass>
ULambdaExpression [{ ...}] : PsiType:Function0<? extends Unit>
UBlockExpression [{...}]
UClass (name = Some) [public final class Some {...}]