Fix case of inner object usage in missing supertypes checker

FakeCallableDescriptorForObject instance, which is not ConstructorDescriptor,
is checked with call checkers when object's contents are being used.
Checker of missing supertypes should not be run against this fake descriptor.
Object's members belong to separate member scope, so their resolution doesn't
force containing class' supertypes evaluation. I.e. object's methods
may work fine even if some supertypes of containing class are missing.
This commit is contained in:
Pavel Kirpichenkov
2019-11-22 20:11:45 +03:00
parent 5afab1ac2b
commit 55b3637f03
3 changed files with 17 additions and 2 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.resolve.MissingSupertypesResolver
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
@@ -47,7 +48,7 @@ object MissingDependencySupertypeChecker {
descriptor.dispatchReceiverParameter?.declaration, reportOn, descriptor.dispatchReceiverParameter?.declaration, reportOn,
context.trace, context.missingSupertypesResolver context.trace, context.missingSupertypesResolver
) )
if (descriptor !is ConstructorDescriptor && !errorReported) { if (descriptor !is ConstructorDescriptor && descriptor !is FakeCallableDescriptorForObject && !errorReported) {
// The constructed class' own supertypes are not resolved after constructor call, // The constructed class' own supertypes are not resolved after constructor call,
// so its containing declaration should not be checked. // so its containing declaration should not be checked.
// Dispatch receiver is checked before for case of inner class constructor call. // Dispatch receiver is checked before for case of inner class constructor call.
@@ -0,0 +1,11 @@
package test
class SubKt : Super() {
companion object {
fun companionMethod() = "OK"
}
object InnerObject {
fun objectMethod() = "OK"
}
}
@@ -1,4 +1,5 @@
import test.Sub as MySub; import test.Sub as MySub
import test.SubKt
typealias Sub = MySub typealias Sub = MySub
@@ -21,4 +22,6 @@ fun test() {
useCallRef(::Sub) useCallRef(::Sub)
simpleFun(Sub()) simpleFun(Sub())
inlineFun<Sub>(Sub()) inlineFun<Sub>(Sub())
SubKt.companionMethod()
SubKt.InnerObject.objectMethod()
} }