Raw FIR: add Any/Enum/Annotation to supertypes iff no supertypes exists

This commit is contained in:
Mikhail Glukhikh
2019-04-02 15:16:12 +03:00
parent 7dd89a48f0
commit 33729aaf9b
36 changed files with 75 additions and 63 deletions
@@ -44,6 +44,8 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
private val implicitEnumType = FirImplicitEnumTypeRef(session, null)
private val implicitAnnotationType = FirImplicitAnnotationTypeRef(session, null)
fun buildFirFile(file: KtFile): FirFile {
return file.accept(Visitor(), Unit) as FirFile
}
@@ -339,13 +341,18 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
}
}
}
if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef
fun isEnum() = this is KtClass && this.isEnum()
val defaultDelegatedSuperTypeRef = if (isEnum()) implicitEnumType else implicitAnyType
if (delegatedSuperTypeRef == null && this.hasPrimaryConstructor()) {
val defaultDelegatedSuperTypeRef = when {
this is KtClass && this.isEnum() -> implicitEnumType
this is KtClass && this.isAnnotation() -> implicitAnnotationType
else -> implicitAnyType
}
// TODO: for enum / annotations, it *should* be empty
if (container.superTypeRefs.isEmpty()) {
container.superTypeRefs += defaultDelegatedSuperTypeRef
}
if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef
// TODO: in case we have no primary constructor,
// it may be not possible to determine delegated super type right here
delegatedSuperTypeRef = delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef
@@ -3,7 +3,7 @@ FILE: F.kt
public? constructor(): super<kotlin/Any>()
}
public? final? class B : A, kotlin/Any {
public? final? class B : A {
public? constructor(): super<kotlin/Any>()
}
@@ -8,7 +8,7 @@ FILE: complexTypes.kt
}
}
public? final? interface Test {
public? final? interface Test : kotlin/Any {
public? final? val x: a.b.C<out CharSequence, *>.D<in List<*>, *>
public? get(): a.b.C<out CharSequence, *>.D<in List<*>, *>
@@ -1,11 +1,11 @@
FILE: enums2.kt
public? final? interface Some {
public? final? interface Some : kotlin/Any {
}
public? final? object O1 : Some, kotlin/Any {
public? final? object O1 : Some {
public? constructor(): super<kotlin/Any>()
}
public? final? object O2 : Some, kotlin/Any {
public? final? object O2 : Some {
public? constructor(): super<kotlin/Any>()
}
@@ -1,5 +1,5 @@
FILE: genericFunctions.kt
public? final? interface Any {
public? final? interface Any : kotlin/Any {
}
<reified T : Any> public? final? inline fun Any.safeAs(): T? {
^safeAs (this# as? T)
@@ -1,5 +1,5 @@
FILE: noPrimaryConstructor.kt
public? final? class NoPrimary {
public? final? class NoPrimary : kotlin/Any {
public? final? val x: String
public? get(): String
@@ -1,12 +1,12 @@
FILE: simpleClass.kt
public? final? interface SomeInterface {
public? final? interface SomeInterface : kotlin/Any {
public? final? fun foo(x: Int, y: String): String
public? final? val bar: Boolean
public? get(): Boolean
}
public? final? class SomeClass : SomeInterface, kotlin/Any {
public? final? class SomeClass : SomeInterface {
public? constructor(): super<kotlin/Any>()
private final? val baz: <implicit> = Int(42)
@@ -1,8 +1,8 @@
FILE: simpleTypeAlias.kt
public? final? interface B {
public? final? interface B : kotlin/Any {
}
public? final typealias C = B
public? final? class D : C, kotlin/Any {
public? final? class D : C {
public? constructor(): super<kotlin/Any>()
}
@@ -3,10 +3,10 @@ FILE: typeAliasWithGeneric.kt
public? constructor(): super<kotlin/Any>()
}
<S, T : A> public? final? interface B {
<S, T : A> public? final? interface B : kotlin/Any {
}
<T> public? final typealias C = B<T, A>
public? final? class D : C<A>, kotlin/Any {
public? final? class D : C<A> {
public? constructor(): super<kotlin/Any>()
}
@@ -1,5 +1,5 @@
FILE: typeParameterVsNested.kt
public? final? interface Some {
public? final? interface Some : kotlin/Any {
}
<T : Some> public? abstract class My : kotlin/Any {
public? constructor(): super<kotlin/Any>()
@@ -1,5 +1,5 @@
FILE: typeParameters.kt
<out T : Any> public? final? interface List {
<out T : Any> public? final? interface List : kotlin/Any {
public? final? operator fun get(index: Int): T
public? final? infix fun concat(other: List<T>): List<T>
@@ -7,7 +7,7 @@ FILE: typeParameters.kt
}
public? final typealias StringList = List<out String>
public? final typealias AnyList = List<*>
<out T : Any> public? abstract class AbstractList : List<T>, kotlin/Any {
<out T : Any> public? abstract class AbstractList : List<T> {
public? constructor(): super<kotlin/Any>()
}
@@ -1,7 +1,7 @@
FILE: where.kt
public? final? interface A {
public? final? interface A : kotlin/Any {
}
public? final? interface B {
public? final? interface B : kotlin/Any {
}
<T : A, B> public? final? class C : kotlin/Any {
public? constructor(): super<kotlin/Any>()
@@ -1,6 +1,6 @@
FILE: annotated.kt
@Target(AnnotationTarget#.EXPRESSION#) @Retention(AnnotationRetention#.SOURCE#) public? final? annotation class Ann : kotlin/Any {
public? constructor(): super<kotlin/Any>()
@Target(AnnotationTarget#.EXPRESSION#) @Retention(AnnotationRetention#.SOURCE#) public? final? annotation class Ann : kotlin/Annotation {
public? constructor(): super<kotlin/Annotation>()
}
public? final? fun foo(arg: Int): Int {
@@ -1,20 +1,20 @@
FILE: collectionLiterals.kt
public? final? annotation class Ann1 : kotlin/Any {
public? constructor(arr: IntArray): super<kotlin/Any>()
public? final? annotation class Ann1 : kotlin/Annotation {
public? constructor(arr: IntArray): super<kotlin/Annotation>()
public? final? val arr: IntArray = R|<local>/arr|
public? get(): IntArray
}
public? final? annotation class Ann2 : kotlin/Any {
public? constructor(arr: DoubleArray): super<kotlin/Any>()
public? final? annotation class Ann2 : kotlin/Annotation {
public? constructor(arr: DoubleArray): super<kotlin/Annotation>()
public? final? val arr: DoubleArray = R|<local>/arr|
public? get(): DoubleArray
}
public? final? annotation class Ann3 : kotlin/Any {
public? constructor(arr: Array<String>): super<kotlin/Any>()
public? final? annotation class Ann3 : kotlin/Annotation {
public? constructor(arr: Array<String>): super<kotlin/Annotation>()
public? final? val arr: Array<String> = R|<local>/arr|
public? get(): Array<String>
@@ -1,10 +1,10 @@
FILE: super.kt
public? final? interface A {
public? final? interface A : kotlin/Any {
public? final? fun foo(): kotlin/Unit {
}
}
public? final? interface B {
public? final? interface B : kotlin/Any {
public? final? fun foo(): kotlin/Unit {
}
@@ -12,7 +12,7 @@ FILE: super.kt
}
}
public? final? class C : A, B, kotlin/Any {
public? final? class C : A, B {
public? constructor(): super<kotlin/Any>()
public? open? override fun bar(): kotlin/Unit {
@@ -1,5 +1,5 @@
FILE: typeOperators.kt
public? final? interface IThing {
public? final? interface IThing : kotlin/Any {
}
public? final? fun test1(x: Any): <implicit> {
^test1 (x# is IThing)
+2 -2
View File
@@ -1,9 +1,9 @@
FILE: lists.kt
public abstract class MyStringList : R|kotlin/collections/List<kotlin/String>|, R|kotlin/Any| {
public abstract class MyStringList : R|kotlin/collections/List<kotlin/String>| {
public constructor(): super<R|kotlin/Any|>()
}
public abstract class MyMutableStringList : R|kotlin/collections/MutableList<kotlin/String>|, R|kotlin/Any| {
public abstract class MyMutableStringList : R|kotlin/collections/MutableList<kotlin/String>| {
public constructor(): super<R|kotlin/Any|>()
}
+3 -3
View File
@@ -1,11 +1,11 @@
FILE: enum.kt
public abstract interface Some {
public abstract interface Some : R|kotlin/Any| {
}
public final object O1 : R|Some|, R|kotlin/Any| {
public final object O1 : R|Some| {
public constructor(): super<R|kotlin/Any|>()
}
public final object O2 : R|Some|, R|kotlin/Any| {
public final object O2 : R|Some| {
public constructor(): super<R|kotlin/Any|>()
}
@@ -1,5 +1,5 @@
FILE: dispatchReceiver.kt
public abstract interface Base {
public abstract interface Base : R|kotlin/Any| {
public abstract fun check(): R|kotlin/Unit|
}
@@ -8,7 +8,7 @@ FILE: complexTypes.kt
}
}
public abstract interface Test {
public abstract interface Test : R|kotlin/Any| {
public abstract val x: R|a/b/C.D<out kotlin/CharSequence, *, in kotlin/collections/List<*>, *>|
public get(): R|a/b/C.D<out kotlin/CharSequence, *, in kotlin/collections/List<*>, *>|
@@ -1,5 +1,5 @@
FILE: noPrimaryConstructor.kt
public final class NoPrimary {
public final class NoPrimary : R|kotlin/Any| {
public final val x: R|kotlin/String|
public get(): R|kotlin/String|
@@ -1,12 +1,12 @@
FILE: simpleClass.kt
public abstract interface SomeInterface {
public abstract interface SomeInterface : R|kotlin/Any| {
public abstract fun foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String|
public abstract val bar: R|kotlin/Boolean|
public get(): R|kotlin/Boolean|
}
public final class SomeClass : R|SomeInterface|, R|kotlin/Any| {
public final class SomeClass : R|SomeInterface| {
public constructor(): super<R|kotlin/Any|>()
private final val baz: R|kotlin/Int| = Int(42)
@@ -1,5 +1,5 @@
FILE: typeParameters.kt
<out T : R|kotlin/Any|> public abstract interface List {
<out T : R|kotlin/Any|> public abstract interface List : R|kotlin/Any| {
public abstract operator fun get(index: R|kotlin/Int|): R|T|
public abstract infix fun concat(other: R|List<T>|): R|List<T>|
@@ -7,7 +7,7 @@ FILE: typeParameters.kt
}
public final typealias StringList = R|List<out kotlin/String>|
public final typealias AnyList = R|List<*>|
<out T : R|kotlin/Any|> public abstract class AbstractList : R|List<T>|, R|kotlin/Any| {
<out T : R|kotlin/Any|> public abstract class AbstractList : R|List<T>| {
public constructor(): super<R|kotlin/Any|>()
}
+2 -2
View File
@@ -11,7 +11,7 @@ FILE: functionTypes.kt
}
<T, out R> public abstract interface KProperty1 : R|KProperty<R>|, R|kotlin/Function1| {
}
<out R> public abstract interface KProperty {
<out R> public abstract interface KProperty : R|kotlin/Any| {
}
<R> public abstract interface KMutableProperty {
<R> public abstract interface KMutableProperty : R|kotlin/Any| {
}
+1 -1
View File
@@ -1,5 +1,5 @@
FILE: genericFunctions.kt
public abstract interface Any {
public abstract interface Any : R|kotlin/Any| {
}
<reified T : R|Any|> public final inline fun R|Any|.safeAs(): R|T|? {
^safeAs (this# as? R|T|)
@@ -1,5 +1,5 @@
FILE: ByteArray.kt
public abstract interface My {
public abstract interface My : R|kotlin/Any| {
public abstract val array: R|kotlin/ByteArray|
public get(): R|kotlin/ByteArray|
+1 -1
View File
@@ -6,7 +6,7 @@ FILE: three.kt
}
}
public abstract interface Y {
public abstract interface Y : R|kotlin/Any| {
public open fun baz(): R|kotlin/Unit| {
}
+2 -2
View File
@@ -1,12 +1,12 @@
FILE: simpleClass.kt
public abstract interface SomeInterface {
public abstract interface SomeInterface : R|kotlin/Any| {
public abstract fun foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String|
public abstract val bar: R|kotlin/Boolean|
public get(): R|kotlin/Boolean|
}
public final class SomeClass : R|SomeInterface|, R|kotlin/Any| {
public final class SomeClass : R|SomeInterface| {
public constructor(): super<R|kotlin/Any|>()
private final val baz: R|kotlin/Int| = Int(42)
+2 -2
View File
@@ -1,8 +1,8 @@
FILE: simpleTypeAlias.kt
public abstract interface B {
public abstract interface B : R|kotlin/Any| {
}
public final typealias C = R|B|
public final class D : R|C|, R|kotlin/Any| {
public final class D : R|C| {
public constructor(): super<R|kotlin/Any|>()
}
+1 -1
View File
@@ -15,7 +15,7 @@ FILE: functionX.kt
}
public get(): R|kotlin/Function1<kotlin/String, kotlin/String>|
public final class MyFunction : R|kotlin/Function2<kotlin/Int, kotlin/String, kotlin/Unit>|, R|kotlin/Any| {
public final class MyFunction : R|kotlin/Function2<kotlin/Int, kotlin/String, kotlin/Unit>| {
public constructor(): super<R|kotlin/Any|>()
public final override fun invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| {
@@ -3,9 +3,9 @@ FILE: typeAliasWithGeneric.kt
public constructor(): super<R|kotlin/Any|>()
}
<S, T : R|A|> public abstract interface B {
<S, T : R|A|> public abstract interface B : R|kotlin/Any| {
}
public final class D : R|C<A>|, R|kotlin/Any| {
public final class D : R|C<A>| {
public constructor(): super<R|kotlin/Any|>()
}
@@ -1,5 +1,5 @@
FILE: typeParameterVsNested.kt
public abstract interface Some {
public abstract interface Some : R|kotlin/Any| {
}
<T : R|test/Some|> public abstract class My : R|kotlin/Any| {
public constructor(): super<R|kotlin/Any|>()
@@ -38,4 +38,9 @@ class FirImplicitAnyTypeRef(
class FirImplicitEnumTypeRef(
session: FirSession,
psi: PsiElement?
) : FirImplicitBuiltinTypeRef(session, psi, KotlinBuiltIns.FQ_NAMES._enum)
) : FirImplicitBuiltinTypeRef(session, psi, KotlinBuiltIns.FQ_NAMES._enum)
class FirImplicitAnnotationTypeRef(
session: FirSession,
psi: PsiElement?
) : FirImplicitBuiltinTypeRef(session, psi, KotlinBuiltIns.FQ_NAMES.annotation.toUnsafe())
@@ -1,5 +1,5 @@
FILE: Base.kt
public abstract interface First {
public abstract interface First : R|kotlin/Any| {
}
public open class Second : R|kotlin/Any| {
public constructor(): super<R|kotlin/Any|>()
@@ -1,5 +1,5 @@
FILE: Strange.kt
<out T> public abstract interface Strange {
<out T> public abstract interface Strange : R|kotlin/Any| {
public abstract fun foo(): R|T|
}
+1 -1
View File
@@ -6,7 +6,7 @@ FILE: jvm.kt
}
}
public abstract interface Y {
public abstract interface Y : R|kotlin/Any| {
public open fun baz(): R|kotlin/Unit| {
}