FIR: report ABSTRACT_*_NOT_IMPLEMENTED on appropriate intersections

This commit is contained in:
Mikhail Glukhikh
2021-04-06 00:07:18 +03:00
parent 0fa2821ac1
commit 818c54e3a6
26 changed files with 30 additions and 107 deletions
@@ -6,8 +6,8 @@ public interface MyList<E> extends java.util.List<E>, I {}
fun <R> elemAndList(r: R, t: MutableList<R>): R = TODO()
interface I
class A : Comparable<A>, I
class B : Comparable<B>, I
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class A<!> : Comparable<A>, I
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class B<!> : Comparable<B>, I
fun test() {
elemAndList(A(), list(B()))
@@ -3,7 +3,7 @@ interface Message<M : Message<M>> {
fun <T> ext(e: Ext<M, T>): T
}
class MyMessage : Message<MyMessage>
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class MyMessage<!> : Message<MyMessage>
class MyExt : Ext<MyMessage, String>
fun <M : Message<M>, T> Message<M>.extF(e: Ext<M, T>): T = ext(e)
@@ -9,8 +9,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.HASHCODE_NAME
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClass
import org.jetbrains.kotlin.fir.analysis.checkers.modality
@@ -25,9 +24,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_IMPL_MEMBER_
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.OVERRIDING_FINAL_MEMBER_BY_DELEGATION
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.containingClass
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirIntersectionCallableSymbol
@@ -69,7 +66,7 @@ object FirNotImplementedOverrideChecker : FirClassChecker() {
fun FirCallableMemberDeclaration<*>.shouldBeImplemented(): Boolean {
if (!isAbstract) return false
val containingClass = getContainingClass(context)
if (containingClass === declaration) return false
if (containingClass === declaration && origin == FirDeclarationOrigin.Source) return false
if (containingClass is FirRegularClass && containingClass.isExpect) return false
return true
}
@@ -121,7 +118,7 @@ object FirNotImplementedOverrideChecker : FirClassChecker() {
}
if (notImplementedSymbols.isNotEmpty()) {
val notImplemented = notImplementedSymbols.first().fir
val notImplemented = notImplementedSymbols.first().unwrapFakeOverrides().fir
if (notImplemented.isFromInterfaceOrEnum(context)) {
reporter.reportOn(source, ABSTRACT_MEMBER_NOT_IMPLEMENTED, declaration, notImplemented, context)
} else {
@@ -25,7 +25,7 @@ interface G<T> {
fun foo(t : T) : T
}
class GC() : G<Int> {
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class GC<!>() : G<Int> {
}
+1 -1
View File
@@ -5,7 +5,7 @@ abstract class A<T> {
public abstract fun bar(x: T)
public inner abstract class B<S> : A<B<S>>() {
public inner class C<U> : <!UNRESOLVED_REFERENCE!>B<C<U>><!>()
public inner <!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class C<!><U> : <!UNRESOLVED_REFERENCE!>B<C<U>><!>()
{
// Here B<C<U>> means A<A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>>.B<A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>.C<U>>
// while for being a correct override it should be A<A<T>.B<S>>.B<A<T>.B<S>.C<U>>
@@ -1,3 +1,3 @@
package typeReferenceError
class Pair<<!SYNTAX!><!>:<!UNRESOLVED_REFERENCE!>(val c: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!><!>()
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Pair<!><<!SYNTAX!><!>:<!UNRESOLVED_REFERENCE!>(val c: <!SYNTAX!><!SYNTAX!><!>fun<!><!SYNTAX!><!> <!UNRESOLVED_REFERENCE!>main<!><!>()
@@ -108,7 +108,7 @@ public class A extends AImpl implements List<String> {
}
// FILE: X.kt
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class X<!> : A()
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class X<!> : A()
fun main() {
val x = X()
@@ -95,7 +95,7 @@ public class A extends AImpl implements List<String> {
}
// FILE: X.kt
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class X<!> : A()
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class X<!> : A()
fun main() {
val x = X()
@@ -1,13 +0,0 @@
interface ILeft {
fun foo()
}
interface IRight {
fun foo()
}
interface IDerived : ILeft, IRight
class CDerived : ILeft, IRight
abstract class ADerived : ILeft, IRight
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface ILeft {
fun foo()
}
@@ -1,9 +0,0 @@
package extendFunctionClass
class A : Function1<Int, Int> {
}
class B : Function1<Int, Int> {
override fun invoke(p1 : Int) = p1
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package extendFunctionClass
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class A<!> : Function1<Int, Int> {
@@ -1,14 +0,0 @@
interface A {
fun foo() {}
}
interface B : A {
abstract override fun foo()
}
interface C {
abstract fun foo()
}
// Fake override Z#foo should be abstract
class Z : B, C
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
fun foo() {}
}
@@ -1,16 +0,0 @@
interface A {
fun foo() {}
}
interface B : A {
abstract override fun foo()
}
interface C : A {
abstract override fun foo()
}
interface D : A
// Fake override Z#foo should be abstract
class Z : B, C, D
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
fun foo() {}
}
@@ -40,15 +40,15 @@ abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
override fun bar(t: String) = t
}
class MyIllegalGenericClass1<T> : MyTrait<T>, MyAbstractClass<T>() {}
class MyIllegalGenericClass2<T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T>() {}
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
override fun foo(r: R) = r
override val <T> pr : R = r
}
class MyIllegalClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String>() {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
class MyIllegalClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
@@ -6,5 +6,5 @@ interface Y {
fun foo(a : Int = 1)
}
class Z1 : X, Y {} // BUG
object Z1O : X, Y {} // BUG
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Z1<!> : X, Y {} // BUG
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>object Z1O<!> : X, Y {} // BUG
@@ -1,17 +0,0 @@
package test
interface A {
val a: String
}
interface B {
val a: String
}
open class C {
private val a: String = ""
}
class Subject : C(), A, B {
val c = a
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package test
interface A {
@@ -1,11 +0,0 @@
// http://youtrack.jetbrains.com/issue/KT-1996
interface Foo {
fun foo(): Unit
}
interface Bar {
fun foo(): Unit
}
class Baz : Foo, Bar
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// http://youtrack.jetbrains.com/issue/KT-1996
interface Foo {
@@ -19,7 +19,7 @@ interface IDerived : ILeft, IRight {
}
// Error: ILeft::copy and IRight::copy have unrelated return types
class CDerivedInvalid1 : ILeft, IRight
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class CDerivedInvalid1<!> : ILeft, IRight
// Error: CLeft::copy and IRight::copy have unrelated return types
class CDerivedInvalid2 : CLeft(), IRight
@@ -9,7 +9,7 @@ fun test() {
<!INAPPLICABLE_CANDIDATE!>a<!> {}
}
class Ext : String.() -> Unit {
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Ext<!> : String.() -> Unit {
}
fun test2() {
@@ -97,7 +97,7 @@ abstract class BaseCase4(val a: String) : InterfaceCase4 {}
* NOTE: abstract class implements java interface
*/
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class Case5<!>(a: String) : BaseCase5(a) {}
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Case5<!>(a: String) : BaseCase5(a) {}
abstract class BaseCase5(val a: String) : java.util.Deque<String> {}
+4 -4
View File
@@ -23,13 +23,13 @@
override fun bar(t: String) = t
}
class MyIllegalGenericClass1<T> : MyTrait<T>, MyAbstractClass<T>() {}
class MyIllegalGenericClass2<T, R> : MyTrait<T>, MyAbstractClass<R>() {
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalGenericClass1 is not abstract and does not implement abstract member foo">class MyIllegalGenericClass1</error><T> : MyTrait<T>, MyAbstractClass<T>() {}
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalGenericClass2 is not abstract and does not implement abstract member foo">class MyIllegalGenericClass2</error><T, R> : MyTrait<T>, MyAbstractClass<R>() {
override fun foo(r: R) = r
}
class MyIllegalClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass1 is not abstract and does not implement abstract member foo">class MyIllegalClass1</error> : MyTrait<Int>, MyAbstractClass<String>() {}
class MyIllegalClass2<T> : MyTrait<Int>, MyAbstractClass<Int>() {
<error descr="[ABSTRACT_MEMBER_NOT_IMPLEMENTED] Class MyIllegalClass2 is not abstract and does not implement abstract member foo">class MyIllegalClass2</error><T> : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
}