Properly calculate this for super call
This commit is contained in:
+15
-5
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getSuperCallExpression
|
||||
@@ -46,7 +46,7 @@ class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker
|
||||
context.trace.report(diagnostic.on(reportOn))
|
||||
}
|
||||
|
||||
if (getSuperCallExpression(resolvedCall.call) == null) return
|
||||
val superCallExpression = getSuperCallExpression(resolvedCall.call) ?: return
|
||||
|
||||
if (!isInterface(descriptor.original.containingDeclaration)) return
|
||||
|
||||
@@ -54,7 +54,7 @@ class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker
|
||||
val realDescriptorOwner = realDescriptor.containingDeclaration as? ClassDescriptor ?: return
|
||||
|
||||
if (isInterface(realDescriptorOwner) && realDescriptor is JavaCallableMemberDescriptor) {
|
||||
val classifier = DescriptorUtils.getParentOfType(context.scope.ownerDescriptor, ClassifierDescriptor::class.java)
|
||||
val classifier = getSuperCallLabelTarget(context.trace.bindingContext, superCallExpression)
|
||||
//is java interface default method called from trait
|
||||
if (classifier != null && DescriptorUtils.isInterface(classifier)) {
|
||||
context.trace.report(INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER.on(reportOn))
|
||||
@@ -68,4 +68,14 @@ class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker
|
||||
|
||||
private fun isDefaultCallsProhibited(context: CallCheckerContext) =
|
||||
context.languageVersionSettings.supportsFeature(LanguageFeature.DefaultMethodsCallFromJava6TargetError)
|
||||
|
||||
private fun getSuperCallLabelTarget(
|
||||
bindingContext: BindingContext,
|
||||
expression: KtSuperExpression
|
||||
): ClassDescriptor? {
|
||||
val thisTypeForSuperCall = bindingContext.get(BindingContext.THIS_TYPE_FOR_SUPER_EXPRESSION, expression) ?: return null
|
||||
val descriptor = thisTypeForSuperCall.constructor.declarationDescriptor
|
||||
return descriptor as? ClassDescriptor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+98
-2
@@ -21,8 +21,26 @@ interface KotlinInterface : JavaInterface {
|
||||
fun fooo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterface.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val propertyy: String
|
||||
get() {
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterface.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun testOverride(): String {
|
||||
return "OK";
|
||||
}
|
||||
@@ -32,15 +50,52 @@ interface KotlinInterfaceInderectInheritance : KotlinInterface {
|
||||
fun foooo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterfaceInderectInheritance.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val propertyyy: String
|
||||
get() {
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterfaceInderectInheritance.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinClass : JavaInterface {
|
||||
fun foo(){
|
||||
fun foo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testOverride<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClass.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property: String
|
||||
get() {
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testOverride<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClass.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinClassInderectInheritance : KotlinClass() {
|
||||
@@ -48,23 +103,64 @@ class KotlinClassInderectInheritance : KotlinClass() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
super.test()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance.test()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property2: String
|
||||
get() {
|
||||
super.test()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance.test()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInheritance {
|
||||
fun foo(){
|
||||
fun foo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance2.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property: String
|
||||
get() {
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance2.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
JavaInterface.<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>testStatic<!>()
|
||||
KotlinClass().foo()
|
||||
KotlinClass().property
|
||||
KotlinClassInderectInheritance2().foo()
|
||||
KotlinClassInderectInheritance2().property
|
||||
|
||||
KotlinClass().test()
|
||||
KotlinClass().property
|
||||
KotlinClass().testOverride()
|
||||
KotlinClassInderectInheritance().testOverride()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface JavaInterface {
|
||||
|
||||
public open class KotlinClass : JavaInterface {
|
||||
public constructor KotlinClass()
|
||||
public final val property: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@@ -25,6 +26,8 @@ public open class KotlinClass : JavaInterface {
|
||||
|
||||
public final class KotlinClassInderectInheritance : KotlinClass {
|
||||
public constructor KotlinClassInderectInheritance()
|
||||
public final override /*1*/ /*fake_override*/ val property: kotlin.String
|
||||
public final val property2: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public final fun foo2(): kotlin.Unit
|
||||
@@ -36,6 +39,9 @@ public final class KotlinClassInderectInheritance : KotlinClass {
|
||||
|
||||
public final class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInheritance {
|
||||
public constructor KotlinClassInderectInheritance2()
|
||||
public final val property: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ val propertyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ val propertyyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun fooo(): kotlin.Unit
|
||||
@@ -47,6 +53,7 @@ public final class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInhe
|
||||
}
|
||||
|
||||
public interface KotlinInterface : JavaInterface {
|
||||
public open val propertyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun fooo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@@ -56,6 +63,8 @@ public interface KotlinInterface : JavaInterface {
|
||||
}
|
||||
|
||||
public interface KotlinInterfaceInderectInheritance : KotlinInterface {
|
||||
public open override /*1*/ /*fake_override*/ val propertyy: kotlin.String
|
||||
public open val propertyyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun fooo(): kotlin.Unit
|
||||
public open fun foooo(): kotlin.Unit
|
||||
|
||||
@@ -23,8 +23,26 @@ interface KotlinInterface : JavaInterface {
|
||||
fun fooo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterface.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val propertyy: String
|
||||
get() {
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterface.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun testOverride(): String {
|
||||
return "OK";
|
||||
}
|
||||
@@ -34,7 +52,25 @@ interface KotlinInterfaceInderectInheritance : KotlinInterface {
|
||||
fun foooo() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterfaceInderectInheritance.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val propertyyy: String
|
||||
get() {
|
||||
super.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinInterfaceInderectInheritance.<!INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinClass : JavaInterface {
|
||||
@@ -42,7 +78,26 @@ open class KotlinClass : JavaInterface {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>testOverride<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClass.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property: String
|
||||
get() {
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>testOverride<!>()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClass.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinClassInderectInheritance : KotlinClass() {
|
||||
@@ -50,7 +105,26 @@ class KotlinClassInderectInheritance : KotlinClass() {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
super.test()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance.test()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property2: String
|
||||
get() {
|
||||
super.test()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance.test()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInheritance {
|
||||
@@ -58,15 +132,37 @@ class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInheritance {
|
||||
<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance2.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val property: String
|
||||
get() {
|
||||
super.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
super.testOverride()
|
||||
|
||||
object {
|
||||
fun run () {
|
||||
super@KotlinClassInderectInheritance2.<!DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET!>test<!>()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
JavaInterface.<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET!>testStatic<!>()
|
||||
KotlinClass().foo()
|
||||
KotlinClass().property
|
||||
KotlinClassInderectInheritance2().foo()
|
||||
KotlinClassInderectInheritance2().property
|
||||
|
||||
KotlinClass().test()
|
||||
KotlinClass().property
|
||||
KotlinClass().testOverride()
|
||||
KotlinClassInderectInheritance().testOverride()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface JavaInterface {
|
||||
|
||||
public open class KotlinClass : JavaInterface {
|
||||
public constructor KotlinClass()
|
||||
public final val property: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@@ -25,6 +26,8 @@ public open class KotlinClass : JavaInterface {
|
||||
|
||||
public final class KotlinClassInderectInheritance : KotlinClass {
|
||||
public constructor KotlinClassInderectInheritance()
|
||||
public final override /*1*/ /*fake_override*/ val property: kotlin.String
|
||||
public final val property2: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public final fun foo2(): kotlin.Unit
|
||||
@@ -36,6 +39,9 @@ public final class KotlinClassInderectInheritance : KotlinClass {
|
||||
|
||||
public final class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInheritance {
|
||||
public constructor KotlinClassInderectInheritance2()
|
||||
public final val property: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ val propertyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ val propertyyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun fooo(): kotlin.Unit
|
||||
@@ -47,6 +53,7 @@ public final class KotlinClassInderectInheritance2 : KotlinInterfaceInderectInhe
|
||||
}
|
||||
|
||||
public interface KotlinInterface : JavaInterface {
|
||||
public open val propertyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun fooo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@@ -56,6 +63,8 @@ public interface KotlinInterface : JavaInterface {
|
||||
}
|
||||
|
||||
public interface KotlinInterfaceInderectInheritance : KotlinInterface {
|
||||
public open override /*1*/ /*fake_override*/ val propertyy: kotlin.String
|
||||
public open val propertyyy: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun fooo(): kotlin.Unit
|
||||
public open fun foooo(): kotlin.Unit
|
||||
|
||||
Reference in New Issue
Block a user