[FIR] Implement RETURN_TYPE_MISMATCH_ON_INHERITANCE diagnostic
This commit is contained in:
committed by
teamcityserver
parent
8012eb3214
commit
94da1e37aa
Vendored
-37
@@ -1,37 +0,0 @@
|
||||
interface IBase {
|
||||
fun copy(): IBase
|
||||
}
|
||||
|
||||
interface ILeft : IBase {
|
||||
override fun copy(): ILeft
|
||||
}
|
||||
|
||||
open class CLeft : ILeft {
|
||||
override fun copy(): ILeft = CLeft()
|
||||
}
|
||||
|
||||
interface IRight : IBase {
|
||||
override fun copy(): IRight
|
||||
}
|
||||
|
||||
interface IDerived : ILeft, IRight {
|
||||
override fun copy(): IDerived
|
||||
}
|
||||
|
||||
// Error: ILeft::copy and IRight::copy have unrelated return types
|
||||
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class CDerivedInvalid1<!> : ILeft, IRight
|
||||
|
||||
// Error: CLeft::copy and IRight::copy have unrelated return types
|
||||
class CDerivedInvalid2 : CLeft(), IRight
|
||||
|
||||
// OK: CDerived1::copy overrides both ILeft::copy and IRight::copy
|
||||
class CDerived1 : ILeft, IRight {
|
||||
override fun copy(): CDerived1 = CDerived1()
|
||||
}
|
||||
|
||||
// Although ILeft::copy and IRight::copy return types are unrelated, IDerived::copy return type is the most specific of three.
|
||||
abstract class CDerived2 : ILeft, IRight, IDerived
|
||||
|
||||
class CDerived2a : ILeft, IRight, IDerived {
|
||||
override fun copy(): IDerived = CDerived2a()
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
interface IBase {
|
||||
fun copy(): IBase
|
||||
}
|
||||
|
||||
Vendored
-43
@@ -1,43 +0,0 @@
|
||||
// FILE: J.java
|
||||
public interface J {
|
||||
java.util.List<String> foo();
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
interface ILNS {
|
||||
fun foo(): List<String?>
|
||||
}
|
||||
|
||||
interface IMLS {
|
||||
fun foo(): MutableList<String>
|
||||
}
|
||||
|
||||
interface IMLNS {
|
||||
fun foo(): MutableList<String?>
|
||||
}
|
||||
|
||||
interface ILS {
|
||||
fun foo(): List<String>
|
||||
}
|
||||
|
||||
interface Test1 : ILNS, J
|
||||
interface Test2 : J, ILNS
|
||||
|
||||
interface Test3 : IMLS, J
|
||||
interface Test4 : J, IMLS
|
||||
|
||||
interface Test5 : ILNS, IMLS, J
|
||||
interface Test6 : ILNS, J, IMLS
|
||||
interface Test7 : J, ILNS, IMLS
|
||||
|
||||
// Return types of ILS::foo and IMLNS::foo are incompatible themselves.
|
||||
// However, return type of J::foo is (Mutable)List<String!>!,
|
||||
// which is subtype of both List<String> and MutalbeList<String?>.
|
||||
// Thus, inheriting from J, IMLNS, and ILS is Ok,
|
||||
// but inheriting from IMLNS and ILS is not.
|
||||
|
||||
interface Test8 : J, IMLNS, ILS
|
||||
interface Test9 : IMLNS, J, ILS
|
||||
interface Test10 : IMLNS, ILS, J
|
||||
|
||||
interface Test11 : IMLNS, ILS
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: J.java
|
||||
public interface J {
|
||||
java.util.List<String> foo();
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
// FILE: K.kt
|
||||
abstract class ATest1 : TestNN.JNullVsNotNull()
|
||||
|
||||
abstract class ATest2 : TestNN.JUnknownImpl(), TestNN.JNotNull
|
||||
|
||||
abstract class ATest3 : TestNN.JUnknownVsNotNull()
|
||||
|
||||
class CTest1 : TestNN.JNullVsNotNull()
|
||||
|
||||
class CTest2 : TestNN.JUnknownImpl(), TestNN.JNotNull
|
||||
|
||||
class CTest3 : TestNN.JUnknownVsNotNull()
|
||||
|
||||
// FILE: TestNN.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class TestNN {
|
||||
public interface JNull {
|
||||
@Nullable Object foo();
|
||||
}
|
||||
|
||||
public interface JNotNull {
|
||||
@NotNull Object foo();
|
||||
}
|
||||
|
||||
public static class JNullVsNotNull implements JNull, JNotNull {
|
||||
public Object foo() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JNullBase {
|
||||
@Nullable public Object foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JUnknownImpl extends JNullBase {
|
||||
public Object foo() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JUnknownVsNotNull extends JUnknownImpl implements JNotNull {
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: K.kt
|
||||
abstract class ATest1 : TestNN.JNullVsNotNull()
|
||||
|
||||
|
||||
Vendored
-29
@@ -1,29 +0,0 @@
|
||||
open class A {
|
||||
open fun foo(): Boolean = true
|
||||
}
|
||||
|
||||
interface IA {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
interface IAA {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
interface IGA<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class B1: A(), IA
|
||||
|
||||
class B2: A(), IA, IAA
|
||||
|
||||
abstract class B3: IA, IAA
|
||||
|
||||
class BS1: A(), IGA<Boolean>
|
||||
|
||||
class BS2: A(), IGA<Any>
|
||||
|
||||
class BS3: A(), IGA<String>
|
||||
|
||||
class BG1<T>: A(), IGA<T>
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
open class A {
|
||||
open fun foo(): Boolean = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user