KT-5963 Call to super shouldn't require type specification if there is no conflict

Implemented unqualified 'super' type resolution (in BasicExpressionTypingVisitor).

No overload resolution of any kind is involved.
Corresponding supertype is determined by the expected member name only:
- 'super.foo(...)' - function or property (of possibly callable type) 'foo'
- 'super.x' - property 'x'
Supertype should provide a non-abstract implementation of such member.
As a fall-back solution for diagnostics purposes, consider supertypes with abstract implementation of such member.

Diagnostics:
- AMBIGUOUS_SUPER on 'super', if multiple possible supertypes are available;
- ABSTRACT_SUPER_CALL on selector expression, if the only available implementation is abstract.

#KT-5963 Fixed
This commit is contained in:
dnpetrov
2015-06-08 15:35:32 +03:00
parent 46baffc233
commit 046189087a
28 changed files with 1070 additions and 2 deletions
@@ -67,6 +67,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperPackage;
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
import org.jetbrains.kotlin.utils.ThrowingList;
@@ -398,7 +399,20 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
else {
if (supertypes.size() > 1) {
context.trace.report(AMBIGUOUS_SUPER.on(expression));
Collection<JetType> supertypesResolvedFromContext =
UnqualifiedSuperPackage.resolveUnqualifiedSuperFromExpressionContext(expression, supertypes);
if (supertypesResolvedFromContext.size() == 1) {
JetType singleResolvedType = supertypesResolvedFromContext.iterator().next();
result = substitutor.substitute(singleResolvedType, Variance.INVARIANT);
}
else if (supertypesResolvedFromContext.isEmpty()) {
// No supertype found, either with concrete or abstract members.
// Resolve to 'Any' (this will cause diagnostics for unresolved member reference).
result = components.builtIns.getAnyType();
}
else {
context.trace.report(AMBIGUOUS_SUPER.on(expression));
}
}
else {
// supertypes may be empty when all the supertypes are error types (are not resolved, for example)
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.types.expressions.unqualifiedSuper
import com.intellij.util.SmartList
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetCallExpression
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
import org.jetbrains.kotlin.psi.JetSuperExpression
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
import java.util.*
public fun resolveUnqualifiedSuperFromExpressionContext(superExpression: JetSuperExpression, supertypes: Collection<JetType>): Collection<JetType> {
val parentElement = superExpression.getParent()
if (parentElement is JetDotQualifiedExpression) {
val selectorExpression = parentElement.getSelectorExpression()
when (selectorExpression) {
is JetCallExpression -> {
// super.foo(...): foo can be a function or a property of a callable type
val calleeExpression = selectorExpression.getCalleeExpression()
if (calleeExpression is JetSimpleNameExpression) {
return resolveSupertypesByCalleeName(supertypes, calleeExpression.getReferencedNameAsName())
}
}
is JetSimpleNameExpression -> {
// super.x: x can be a property only
return resolveSupertypesByPropertyName(supertypes, selectorExpression.getReferencedNameAsName())
}
}
}
return emptyList()
}
private fun resolveSupertypesByCalleeName(supertypes: Collection<JetType>, calleeName: Name): Collection<JetType> =
resolveSupertypesByMembers(supertypes) { getFunctionMembers(it, calleeName) + getPropertyMembers(it, calleeName) }
private fun resolveSupertypesByPropertyName(supertypes: Collection<JetType>, propertyName: Name): Collection<JetType> =
resolveSupertypesByMembers(supertypes) { getPropertyMembers(it, propertyName) }
private inline fun resolveSupertypesByMembers(
supertypes: Collection<JetType>,
getMembers: (JetType) -> Collection<MemberDescriptor>
): Collection<JetType> {
val withConcreteMembers = SmartList<JetType>()
val withAnyMembers = SmartList<JetType>()
for (supertype in supertypes) {
val members = getMembers(supertype)
if (members.isNotEmpty()) {
withAnyMembers.add(supertype)
if (members any ::isConcreteMember) {
withConcreteMembers.add(supertype)
}
}
}
return if (withConcreteMembers.isNotEmpty()) withConcreteMembers else withAnyMembers
}
private fun getFunctionMembers(type: JetType, name: Name): Collection<MemberDescriptor> =
type.getMemberScope().getFunctions(name)
private fun getPropertyMembers(type: JetType, name: Name): Collection<MemberDescriptor> =
type.getMemberScope().getProperties(name).filterIsInstanceTo(SmartList<MemberDescriptor>())
private fun isConcreteMember(memberDescriptor: MemberDescriptor): Boolean =
memberDescriptor.getModality() != Modality.ABSTRACT
+66
View File
@@ -0,0 +1,66 @@
open class Base() {
open fun baseFun(): String = "Base.baseFun()"
open fun unambiguous(): String = "Base.unambiguous()"
open val baseProp: String
get() = "Base.baseProp"
}
interface Interface {
fun interfaceFun(): String = "Interface.interfaceFun()"
fun unambiguous(): String // NB abstract
}
interface AnotherInterface
interface DerivedInterface: Interface, AnotherInterface {
override fun interfaceFun(): String = "DerivedInterface.interfaceFun()"
override fun unambiguous(): String = "DerivedInterface.unambiguous()"
fun callsFunFromSuperInterface(): String = super.interfaceFun()
}
class Derived : Base(), Interface {
override fun baseFun(): String = "Derived.baseFun()"
override fun unambiguous(): String = "Derived.unambiguous()"
override fun interfaceFun(): String = "Derived.interfaceFun()"
override val baseProp: String
get() = "Derived.baseProp"
fun callsBaseFun(): String = super.baseFun()
fun callsUnambiguousFun(): String = super.unambiguous()
fun getsBaseProp(): String = super.baseProp
fun callsInterfaceFun(): String = super.interfaceFun()
}
fun box(): String {
val d = Derived()
val test1 = d.callsBaseFun()
if (test1 != "Base.baseFun()") return "Failed: d.callsBaseFun()==$test1"
val test2 = d.callsUnambiguousFun()
if (test2 != "Base.unambiguous()") return "Failed: d.callsUnambiguousFun()==$test2"
val test3 = d.getsBaseProp()
if (test3 != "Base.baseProp") return "Failed: d.getsBaseProp()==$test3"
val test4 = d.callsInterfaceFun()
if (test4 != "Interface.interfaceFun()") return "Failed: d.callsInterfaceFun()==$test4"
val di = object : DerivedInterface {}
val test5 = di.callsFunFromSuperInterface()
if (test5 != "Interface.interfaceFun()") return "Failed: di.callsFunFromSuperInterface()==$test5"
return "OK"
}
@@ -0,0 +1,63 @@
open class DeeperBase {
open fun deeperBaseFun(): String = "DeeperBase.deeperBaseFun()"
open val deeperBaseProp: String
get() = "DeeperBase.deeperBaseProp"
}
open class DeepBase : DeeperBase() {
}
interface DeeperInterface {
fun deeperInterfaceFun(): String = "DeeperInterface.deeperInterfaceFun()"
val deeperInterfaceProp: String
get() = "DeeperInterface.deeperInterfaceProp"
}
interface DeepInterface : DeeperInterface {
fun deepInterfaceFun(): String = "DeepInterface.deepInterfaceFun()"
}
class DeepDerived : DeepBase(), DeepInterface {
override fun deeperBaseFun(): String = "DeepDerived.deeperBaseFun()"
override val deeperBaseProp: String
get() = "DeepDerived.deeperBaseProp"
override fun deeperInterfaceFun(): String = "DeepDerived.deeperInterfaceFun()"
override val deeperInterfaceProp: String
get() = "DeepDerived.deeperInterfaceProp"
override fun deepInterfaceFun(): String = "DeepDerived.deepInterfaceFun()"
fun callsSuperDeeperBaseFun(): String = super.deeperBaseFun()
fun getsSuperDeeperBaseProp(): String = super.deeperBaseProp
fun callsSuperDeepInterfaceFun(): String = super.deepInterfaceFun()
fun callsSuperDeeperInterfaceFun(): String = super.deeperInterfaceFun()
fun getsSuperDeeperInterfaceProp(): String = super.deeperInterfaceProp
}
fun box(): String {
val dd = DeepDerived()
val test1 = dd.callsSuperDeeperBaseFun()
if (test1 != "DeeperBase.deeperBaseFun()") return "Failed: dd.callsSuperDeeperBaseFun()==$test1"
val test2 = dd.getsSuperDeeperBaseProp()
if (test2 != "DeeperBase.deeperBaseProp") return "Failed: dd.getsSuperDeeperBaseProp()==$test2"
val test3 = dd.callsSuperDeepInterfaceFun()
if (test3 != "DeepInterface.deepInterfaceFun()") return "Failed: dd.callsSuperDeepInterfaceFun()==$test3"
val test4 = dd.callsSuperDeeperInterfaceFun()
if (test4 != "DeeperInterface.deeperInterfaceFun()") return "Failed: dd.callsSuperDeeperInterfaceFun()==$test4"
val test5 = dd.getsSuperDeeperInterfaceProp()
if (test5 != "DeeperInterface.deeperInterfaceProp") return "Failed: dd.getsSuperDeeperInterfaceProp()==$test5"
return "OK"
}
@@ -0,0 +1,30 @@
interface Interface {
fun foo(x: Int): Int
}
fun withLocalClasses(param: Int): Interface {
open class LocalBase {
open val param: Int
get() = 100
}
interface LocalInterface : Interface {
override fun foo(x: Int): Int =
x + param
}
return object : LocalBase(), LocalInterface {
override fun foo(x: Int): Int =
x + super.param
}
}
fun box(): String {
val t = withLocalClasses(1)
val test1 = t.foo(10)
if (test1 != 110) return "Fail: t.foo(10)==$test1"
return "OK"
}
+1 -1
View File
@@ -12,7 +12,7 @@ class A<E>() : C(), T {
fun test() {
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>
<!SUPER_IS_NOT_AN_EXPRESSION!>super<T><!>
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo<!>()
super.foo()
super<T>.foo()
super<C>.bar()
super<T>@A.foo()
@@ -0,0 +1,37 @@
open class GenericBaseClass<T> {
open fun foo(x: T): T = x
open fun ambiguous(x: T): T = x
}
interface GenericBaseInterface<T> {
fun bar(x: T): T = x
fun ambiguous(x: T): T = x
}
class GenericDerivedClass<T> : GenericBaseClass<T>(), GenericBaseInterface<T> {
override fun foo(x: T): T = super.foo(x)
override fun bar(x: T): T = super.bar(x)
override fun ambiguous(x: T): T =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>(x)
}
class <!CONFLICTING_JVM_DECLARATIONS!>SpecializedDerivedClass<!> : GenericBaseClass<Int>(), GenericBaseInterface<String> {
override fun foo(x: Int): Int = super.foo(x)
override fun bar(x: String): String = super.bar(x)
override fun ambiguous(x: String): String =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>(x)
override fun ambiguous(x: Int): Int =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>(x)
}
class <!CONFLICTING_JVM_DECLARATIONS!>MixedDerivedClass<!><T> : GenericBaseClass<Int>(), GenericBaseInterface<T> {
override fun foo(x: Int): Int = super.foo(x)
override fun bar(x: T): T = super.bar(x)
override fun ambiguous(x: Int): Int =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>(x)
<!CONFLICTING_JVM_DECLARATIONS!>override fun ambiguous(x: T): T<!> =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>(x)
}
@@ -0,0 +1,50 @@
package
internal open class GenericBaseClass</*0*/ T> {
public constructor GenericBaseClass</*0*/ T>()
internal open fun ambiguous(/*0*/ x: T): T
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(/*0*/ x: T): T
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface GenericBaseInterface</*0*/ T> {
internal open fun ambiguous(/*0*/ x: T): T
internal open fun bar(/*0*/ x: T): T
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
}
internal final class GenericDerivedClass</*0*/ T> : GenericBaseClass<T>, GenericBaseInterface<T> {
public constructor GenericDerivedClass</*0*/ T>()
internal open override /*2*/ fun ambiguous(/*0*/ x: T): T
internal open override /*1*/ fun bar(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class MixedDerivedClass</*0*/ T> : GenericBaseClass<kotlin.Int>, GenericBaseInterface<T> {
public constructor MixedDerivedClass</*0*/ T>()
internal open override /*1*/ fun ambiguous(/*0*/ x: T): T
internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.Int): kotlin.Int
internal open override /*1*/ fun bar(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class SpecializedDerivedClass : GenericBaseClass<kotlin.Int>, GenericBaseInterface<kotlin.String> {
public constructor SpecializedDerivedClass()
internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.Int): kotlin.Int
internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.String): kotlin.String
internal open override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,57 @@
// Base Interface
// \ /
// \/
// Derived
//
open class Base() {
open fun foo() {}
open fun ambiguous() {}
open val prop: Int
get() = 1234
open val ambiguousProp: Int
get() = 111
}
interface Interface {
fun bar() {}
fun ambiguous() {}
val ambiguousProp: Int
get() = 222
}
class Derived : Base(), Interface {
override fun foo() {}
override fun bar() {}
override fun ambiguous() {}
override val ambiguousProp: Int
get() = 333
override val prop: Int
get() = 4321
fun callsFunFromSuperClass() {
super.foo()
}
fun getSuperProp(): Int =
super.prop
fun getAmbiguousSuperProp(): Int =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguousProp<!>
fun callsFunFromSuperInterface() {
super.bar()
}
fun callsAmbiguousSuperFun() {
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>()
}
}
@@ -0,0 +1,38 @@
package
internal open class Base {
public constructor Base()
internal open val ambiguousProp: kotlin.Int
internal open val prop: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class Derived : Base, Interface {
public constructor Derived()
internal open override /*2*/ val ambiguousProp: kotlin.Int
internal open override /*1*/ val prop: kotlin.Int
internal open override /*2*/ fun ambiguous(): kotlin.Unit
internal open override /*1*/ fun bar(): kotlin.Unit
internal final fun callsAmbiguousSuperFun(): kotlin.Unit
internal final fun callsFunFromSuperClass(): kotlin.Unit
internal final fun callsFunFromSuperInterface(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Unit
internal final fun getAmbiguousSuperProp(): kotlin.Int
internal final fun getSuperProp(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface Interface {
internal open val ambiguousProp: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
internal open fun bar(): kotlin.Unit
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
}
@@ -0,0 +1,39 @@
// fun foo: abstract in A, unresolved in I
// fun bar: implemented in A, abstract in I
// fun qux: abstract in A, abstract in I
// val x: unresolved in A, abstract in I
// val y: abstract in A, implemented in I
abstract class A {
abstract fun foo(): Int
open fun bar() {}
abstract fun qux()
abstract val y: Int
}
interface I {
fun bar()
fun qux()
val x: Int
val y: Int get() = 111
}
class B : A(), I {
override val x: Int = 12345
override val y: Int = super.y
override fun foo(): Int {
super.<!ABSTRACT_SUPER_CALL!>foo<!>()
return super.<!ABSTRACT_SUPER_CALL!>x<!>
}
override fun bar() {
super.bar()
}
override fun qux() {
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>qux<!>()
}
}
@@ -0,0 +1,34 @@
package
internal abstract class A {
public constructor A()
internal abstract val y: kotlin.Int
internal open fun bar(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal abstract fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal abstract fun qux(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class B : A, I {
public constructor B()
internal open override /*1*/ val x: kotlin.Int = 12345
internal open override /*2*/ val y: kotlin.Int
internal open override /*2*/ fun bar(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open override /*2*/ fun qux(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface I {
internal abstract val x: kotlin.Int
internal open val y: kotlin.Int
internal abstract fun bar(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal abstract fun qux(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,20 @@
// Ambiguity between fun and callable property
open class BaseWithCallableProp {
val fn = { "fn.invoke()" }
val bar = { "bar.invoke()"}
open fun bar(): String = "bar()"
}
interface InterfaceWithFun {
fun fn(): String = "fn()"
}
class DerivedUsingFun : BaseWithCallableProp(), InterfaceWithFun {
fun foo(): String =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>fn<!>()
override fun bar(): String =
super.bar()
}
@@ -0,0 +1,30 @@
package
internal open class BaseWithCallableProp {
public constructor BaseWithCallableProp()
internal final val bar: () -> kotlin.String
internal final val fn: () -> kotlin.String
internal open fun bar(): kotlin.String
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
}
internal final class DerivedUsingFun : BaseWithCallableProp, InterfaceWithFun {
public constructor DerivedUsingFun()
internal final override /*1*/ /*fake_override*/ val bar: () -> kotlin.String
internal final override /*1*/ /*fake_override*/ val fn: () -> kotlin.String
internal open override /*1*/ fun bar(): kotlin.String
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ /*fake_override*/ fun fn(): kotlin.String
internal final fun foo(): kotlin.String
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface InterfaceWithFun {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun fn(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,51 @@
// Check that it works with inherited members
//
// DeeperBase DeeperInterface
// | |
// DeepBase DeepInterface
// \ /
// \/
// DeepDerived
//
open class DeeperBase {
open fun deeperBaseFun() {}
open val deeperBaseProp: Int
get() = 333
}
open class DeepBase : DeeperBase() {
}
interface DeeperInterface {
fun deeperInterfaceFun() {}
}
interface DeepInterface : DeeperInterface {
fun deepInterfaceFun() {}
}
class DeepDerived : DeepBase(), DeepInterface {
override fun deeperBaseFun() {}
override val deeperBaseProp: Int
get() = 444
override fun deeperInterfaceFun() {}
override fun deepInterfaceFun() {}
fun callsSuperDeeperBaseFun() {
super.deeperBaseFun()
}
fun getsSuperDeeperBaseProp(): Int =
super.deeperBaseProp
fun callsSuperInterfaceFuns() {
super.deeperInterfaceFun()
super.deepInterfaceFun()
super<DeepInterface>.deeperInterfaceFun()
super<DeepInterface>.deepInterfaceFun()
}
}
@@ -0,0 +1,48 @@
package
internal open class DeepBase : DeeperBase {
public constructor DeepBase()
internal open override /*1*/ /*fake_override*/ val deeperBaseProp: kotlin.Int
internal open override /*1*/ /*fake_override*/ fun deeperBaseFun(): kotlin.Unit
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
}
internal final class DeepDerived : DeepBase, DeepInterface {
public constructor DeepDerived()
internal open override /*1*/ val deeperBaseProp: kotlin.Int
internal final fun callsSuperDeeperBaseFun(): kotlin.Unit
internal final fun callsSuperInterfaceFuns(): kotlin.Unit
internal open override /*1*/ fun deepInterfaceFun(): kotlin.Unit
internal open override /*1*/ fun deeperBaseFun(): kotlin.Unit
internal open override /*1*/ fun deeperInterfaceFun(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun getsSuperDeeperBaseProp(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface DeepInterface : DeeperInterface {
internal open fun deepInterfaceFun(): kotlin.Unit
internal open override /*1*/ /*fake_override*/ fun deeperInterfaceFun(): kotlin.Unit
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
}
internal open class DeeperBase {
public constructor DeeperBase()
internal open val deeperBaseProp: kotlin.Int
internal open fun deeperBaseFun(): kotlin.Unit
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
}
internal interface DeeperInterface {
internal open fun deeperInterfaceFun(): kotlin.Unit
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
}
@@ -0,0 +1,22 @@
open class GenericBaseClass<T> {
open fun foo(x: T): T = x
}
interface GenericBaseInterface<T> {
fun bar(x: T): T = x
}
class GenericDerivedClass<T> : GenericBaseClass<T>(), GenericBaseInterface<T> {
override fun foo(x: T): T = super.foo(x)
override fun bar(x: T): T = super.bar(x)
}
class SpecializedDerivedClass : GenericBaseClass<Int>(), GenericBaseInterface<String> {
override fun foo(x: Int): Int = super.foo(x)
override fun bar(x: String): String = super.bar(x)
}
class MixedDerivedClass<T> : GenericBaseClass<Int>(), GenericBaseInterface<T> {
override fun foo(x: Int): Int = super.foo(x)
override fun bar(x: T): T = super.bar(x)
}
@@ -0,0 +1,43 @@
package
internal open class GenericBaseClass</*0*/ T> {
public constructor GenericBaseClass</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(/*0*/ x: T): T
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface GenericBaseInterface</*0*/ T> {
internal open fun bar(/*0*/ x: T): T
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
}
internal final class GenericDerivedClass</*0*/ T> : GenericBaseClass<T>, GenericBaseInterface<T> {
public constructor GenericDerivedClass</*0*/ T>()
internal open override /*1*/ fun bar(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class MixedDerivedClass</*0*/ T> : GenericBaseClass<kotlin.Int>, GenericBaseInterface<T> {
public constructor MixedDerivedClass</*0*/ T>()
internal open override /*1*/ fun bar(/*0*/ x: T): T
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class SpecializedDerivedClass : GenericBaseClass<kotlin.Int>, GenericBaseInterface<kotlin.String> {
public constructor SpecializedDerivedClass()
internal open override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,33 @@
open class A {
open fun foo() {}
}
interface B {
fun bar() {}
}
interface Q {
fun qux() {}
}
class C : A(), B {
override fun foo() {
super@C.foo()
}
override fun bar() {
super@C.bar()
}
inner class D : A(), Q {
override fun foo() {
super@C.foo()
super@D.foo()
}
override fun qux() {
super@C.<!UNRESOLVED_REFERENCE!>qux<!>()
super@D.qux()
}
}
}
@@ -0,0 +1,41 @@
package
internal open class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface B {
internal open fun bar(): kotlin.Unit
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
}
internal final class C : A, B {
public constructor C()
internal open override /*1*/ fun bar(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
internal final inner class D : A, Q {
public constructor D()
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open override /*1*/ fun qux(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
}
internal interface Q {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open fun qux(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,28 @@
// Interface AnotherInterface
// \ /
// \/
// DerivedInterface
//
interface Interface {
fun foo() {}
fun ambiguous() {}
val ambiguousProp: Int
get() = 222
}
interface AnotherInterface {
fun ambiguous() {}
val ambiguousProp: Int
get() = 333
}
interface DerivedInterface: Interface, AnotherInterface {
override fun foo() { super.foo() }
override fun ambiguous() {
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>()
}
override val ambiguousProp: Int
get() = <!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguousProp<!>
}
@@ -0,0 +1,27 @@
package
internal interface AnotherInterface {
internal open val ambiguousProp: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
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
}
internal interface DerivedInterface : Interface, AnotherInterface {
internal open override /*2*/ val ambiguousProp: kotlin.Int
internal open override /*2*/ fun ambiguous(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface Interface {
internal open val ambiguousProp: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,21 @@
interface Interface {
fun foo(x: Int): Int
}
fun withLocalClasses(param: Int): Interface {
open class LocalBase {
open val param: Int
get() = 100
}
interface LocalInterface : Interface {
override fun foo(x: Int): Int =
x + param
}
return object : LocalBase(), LocalInterface {
override fun foo(x: Int): Int =
x + super.param
}
}
@@ -0,0 +1,10 @@
package
internal fun withLocalClasses(/*0*/ param: kotlin.Int): Interface
internal interface Interface {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal abstract fun foo(/*0*/ x: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,53 @@
// Check that unresolved super type doesn't interfere with unqualified super resolution.
open class Base() {
open fun foo() {}
open fun ambiguous() {}
open val prop: Int
get() = 1234
open val ambiguousProp: Int
get() = 111
}
interface Interface {
fun bar() {}
fun ambiguous() {}
val ambiguousProp: Int
get() = 222
}
class ClassDerivedFromUnresolved : Base(), Interface, <!UNRESOLVED_REFERENCE!>Unresolved<!> {
override fun foo() {}
override fun bar() {}
override fun ambiguous() {}
override val ambiguousProp: Int
get() = 333
override val prop: Int
get() = 4321
fun callsFunFromSuperClass() {
super.foo()
}
fun getSuperProp(): Int =
super.prop
fun getAmbiguousSuperProp(): Int =
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguousProp<!>
fun callsFunFromSuperInterface() {
super.bar()
}
fun callsAmbiguousSuperFun() {
<!AMBIGUOUS_SUPER!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>ambiguous<!>()
}
}
@@ -0,0 +1,38 @@
package
internal open class Base {
public constructor Base()
internal open val ambiguousProp: kotlin.Int
internal open val prop: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class ClassDerivedFromUnresolved : Base, Interface {
public constructor ClassDerivedFromUnresolved()
internal open override /*2*/ val ambiguousProp: kotlin.Int
internal open override /*1*/ val prop: kotlin.Int
internal open override /*2*/ fun ambiguous(): kotlin.Unit
internal open override /*1*/ fun bar(): kotlin.Unit
internal final fun callsAmbiguousSuperFun(): kotlin.Unit
internal final fun callsFunFromSuperClass(): kotlin.Unit
internal final fun callsFunFromSuperInterface(): kotlin.Unit
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open override /*1*/ fun foo(): kotlin.Unit
internal final fun getAmbiguousSuperProp(): kotlin.Int
internal final fun getSuperProp(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface Interface {
internal open val ambiguousProp: kotlin.Int
internal open fun ambiguous(): kotlin.Unit
internal open fun bar(): kotlin.Unit
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
}
@@ -13406,6 +13406,75 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnqualifiedSuper extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInUnqualifiedSuper() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ambiguousSuperWithGenerics.kt")
public void testAmbiguousSuperWithGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuper.kt")
public void testUnqualifiedSuper() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithAbstractMembers.kt")
public void testUnqualifiedSuperWithAbstractMembers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithCallableProperty.kt")
public void testUnqualifiedSuperWithCallableProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithDeeperHierarchies.kt")
public void testUnqualifiedSuperWithDeeperHierarchies() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithGenerics.kt")
public void testUnqualifiedSuperWithGenerics() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithInnerClass.kt")
public void testUnqualifiedSuperWithInnerClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithInterfaces.kt")
public void testUnqualifiedSuperWithInterfaces() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithLocalClass.kt")
public void testUnqualifiedSuperWithLocalClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithUnresolvedBase.kt")
public void testUnqualifiedSuperWithUnresolvedBase() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt");
doTest(fileName);
}
}
}
@TestMetadata("compiler/testData/diagnostics/tests/traitWithRequired")
@@ -6807,6 +6807,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/traitproperty.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuper.kt")
public void testUnqualifiedSuper() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuper.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithDeeperHierarchies.kt")
public void testUnqualifiedSuperWithDeeperHierarchies() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt");
doTest(fileName);
}
@TestMetadata("unqualifiedSuperWithLocalClass.kt")
public void testUnqualifiedSuperWithLocalClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/superConstructorCall")