FIR2IR: convert qualifiers to companion objects, if any

This commit is contained in:
Mikhail Glukhikh
2020-03-06 19:34:23 +03:00
parent 7ea4c20f3d
commit ed6c9e67a1
72 changed files with 11 additions and 73 deletions
@@ -1262,11 +1262,18 @@ class Fir2IrVisitor(
override fun visitResolvedQualifier(resolvedQualifier: FirResolvedQualifier, data: Any?): IrElement { override fun visitResolvedQualifier(resolvedQualifier: FirResolvedQualifier, data: Any?): IrElement {
val classSymbol = resolvedQualifier.symbol val classSymbol = resolvedQualifier.symbol
if (classSymbol != null) { if (classSymbol != null) {
val resultingSymbol = when (val klass = classSymbol.fir) {
is FirRegularClass -> {
if (klass.classKind in listOf(ClassKind.OBJECT, ClassKind.ENUM_ENTRY)) classSymbol
else klass.companionObject?.symbol ?: classSymbol
}
else -> classSymbol
}
return resolvedQualifier.convertWithOffsets { startOffset, endOffset -> return resolvedQualifier.convertWithOffsets { startOffset, endOffset ->
IrGetObjectValueImpl( IrGetObjectValueImpl(
startOffset, endOffset, startOffset, endOffset,
resolvedQualifier.typeRef.toIrType(), resolvedQualifier.typeRef.toIrType(),
classSymbol.toIrSymbol(session, declarationStorage) as IrClassSymbol resultingSymbol.toIrSymbol(session, declarationStorage) as IrClassSymbol
) )
} }
} }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
class A { class A {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// FILE: CompanionInitialization.java // FILE: CompanionInitialization.java
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class C() { class C() {
companion object { companion object {
fun create() = C() fun create() = C()
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun Any.foo() = 1 fun Any.foo() = 1
class A { class A {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A() { class A() {
companion object { companion object {
val value = 10 val value = 10
@@ -1,5 +1,4 @@
// IGNORE_BACKEND_FIR: JVM_IR // EA-38323 - Illegal field modifiers in class: classObject field in C must be static and final
// EA-38323 - Illegal field modifiers in class: classObject field in C must be static and final
interface C { interface C {
companion object { companion object {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A { class A {
companion object { companion object {
fun values() = "O" fun values() = "O"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TODO: Enable for JS when it supports Java class library. // TODO: Enable for JS when it supports Java class library.
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class C() { class C() {
companion object { companion object {
private fun <T> create() = C() private fun <T> create() = C()
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class C() { class C() {
companion object Foo companion object Foo
} }
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A { class A {
companion object { companion object {
val b = 0 val b = 0
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class Factory(p: Int) open class Factory(p: Int)
class A { class A {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
package mult_constructors_3_bug package mult_constructors_3_bug
public open class Identifier() { public open class Identifier() {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class C() { class C() {
companion object Foo { companion object Foo {
fun create() = 3 fun create() = 3
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Foo private constructor(val param: String = "OK") { class Foo private constructor(val param: String = "OK") {
companion object { companion object {
val s = Foo() val s = Foo()
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A { class A {
companion object { companion object {
fun Int.foo(a: Int = 1): Int { fun Int.foo(a: Int = 1): Int {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KT-5786 NoSuchMethodError: no accessor for private fun with default arguments // KT-5786 NoSuchMethodError: no accessor for private fun with default arguments
class A { class A {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
var state: String = "Fail" var state: String = "Fail"
class A private constructor(x: String = "OK") { class A private constructor(x: String = "OK") {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
var state: String = "Fail" var state: String = "Fail"
class A { class A {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A { class A {
companion object companion object
} }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Test(val prop: String) { class Test(val prop: String) {
companion object { companion object {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
package someTest package someTest
public class Some private constructor(val v: String) { public class Some private constructor(val v: String) {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: NATIVE // IGNORE_BACKEND: NATIVE
fun box(): String { fun box(): String {
if (0.toByte().compareTo(-0.0) != 1) return "fail 1.1" if (0.toByte().compareTo(-0.0) != 1) return "fail 1.1"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Outer { class Outer {
class Nested { class Nested {
companion object { companion object {
@@ -1,5 +1,4 @@
// !JVM_DEFAULT_MODE: enable // !JVM_DEFAULT_MODE: enable
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// JVM_TARGET: 1.8 // JVM_TARGET: 1.8
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,5 +1,4 @@
// !LANGUAGE: +JvmFieldInInterface +NestedClassesInAnnotations // !LANGUAGE: +JvmFieldInInterface +NestedClassesInAnnotations
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,5 +1,4 @@
// !LANGUAGE: +JvmFieldInInterface // !LANGUAGE: +JvmFieldInInterface
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
// FILE: tt.kt // FILE: tt.kt
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
var result = "" var result = ""
class A { class A {
@@ -1,5 +1,4 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField // !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: withCompanionObjectBase.kt // FILE: withCompanionObjectBase.kt
import b.* import b.*
@@ -1,5 +1,4 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField // !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: withCompanionObjectBase.kt // FILE: withCompanionObjectBase.kt
import b.* import b.*
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T> assertEquals(a: T, b: T) { if (a != b) throw AssertionError("$a != $b") } fun <T> assertEquals(a: T, b: T) { if (a != b) throw AssertionError("$a != $b") }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T> assertEquals(a: T, b: T) { if (a != b) throw AssertionError("$a != $b") } fun <T> assertEquals(a: T, b: T) { if (a != b) throw AssertionError("$a != $b") }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
var result = "OK" var result = "OK"
class A { class A {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// Inside of the companion we have to access the instance through the local Companion field, // Inside of the companion we have to access the instance through the local Companion field,
// not by indirection through the Companion field of the enclosing class. // not by indirection through the Companion field of the enclosing class.
// Class initialization might not have finished yet. // Class initialization might not have finished yet.
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Test { class Test {
companion object { companion object {
fun ok() = "OK" fun ok() = "OK"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
abstract class Base(val fn: () -> String) abstract class Base(val fn: () -> String)
class Host { class Host {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
interface Test { interface Test {
companion object { companion object {
fun ok() = "OK" fun ok() = "OK"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
abstract class Base(val fn: () -> String) abstract class Base(val fn: () -> String)
interface Host { interface Host {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.assertEquals import kotlin.test.assertEquals
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
public open class Outer private constructor(val s: String) { public open class Outer private constructor(val s: String) {
companion object { companion object {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// See also KT-6299 // See also KT-6299
public open class Outer private constructor() { public open class Outer private constructor() {
companion object { companion object {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// See also KT-6299 // See also KT-6299
public open class Outer private constructor() { public open class Outer private constructor() {
companion object { companion object {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class A private constructor() { open class A private constructor() {
companion object : A() { companion object : A() {
} }
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class My { class My {
companion object { companion object {
val my: String = "O" val my: String = "O"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// FILE: J.java // FILE: J.java
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class My { class My {
companion object { companion object {
private val my: String = "O" private val my: String = "O"
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class My { class My {
companion object { companion object {
private val my: String = "O" private val my: String = "O"
@@ -1,5 +1,4 @@
// !LANGUAGE: +NoConstantValueAttributeForNonConstVals +JvmFieldInInterface // !LANGUAGE: +NoConstantValueAttributeForNonConstVals +JvmFieldInInterface
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class IntentionsBundle { class IntentionsBundle {
companion object { companion object {
fun message(key: String): String { fun message(key: String): String {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
package test package test
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class TestObject() class TestObject()
{ {
companion object { companion object {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Foo() { class Foo() {
companion object { companion object {
val bar = "OK"; val bar = "OK";
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
public class A { public class A {
fun getFromClass(): Boolean { fun getFromClass(): Boolean {
try { try {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
class Class { class Class {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.* import kotlin.test.*
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS // IGNORE_BACKEND: JS
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS // IGNORE_BACKEND: JS
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_REFLECT // WITH_REFLECT
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// WITH_RUNTIME // WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class Foo { class Foo {
companion object { companion object {
val bar: String val bar: String
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
open class Bar<T>(val prop: String) open class Bar<T>(val prop: String)
class Foo { class Foo {
companion object : Bar<Foo>("OK") { companion object : Bar<Foo>("OK") {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
class C { class C {
companion object { companion object {
private val s: String private val s: String
+1 -1
View File
@@ -129,4 +129,4 @@ FILE fqName:<root> fileName:/values.kt
FUN name:test4 visibility:public modality:FINAL <> () returnType:<root>.Z.Companion FUN name:test4 visibility:public modality:FINAL <> () returnType:<root>.Z.Companion
BLOCK_BODY BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (): <root>.Z.Companion declared in <root>' RETURN type=kotlin.Nothing from='public final fun test4 (): <root>.Z.Companion declared in <root>'
GET_OBJECT 'CLASS CLASS name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Z.Companion GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=<root>.Z.Companion
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/constFromBuiltins.kt
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static] FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]
EXPRESSION_BODY EXPRESSION_BODY
CALL 'public final fun <get-MIN_VALUE> (): kotlin.Int declared in kotlin.Int.Companion' type=kotlin.Int origin=GET_PROPERTY CALL 'public final fun <get-MIN_VALUE> (): kotlin.Int declared in kotlin.Int.Companion' type=kotlin.Int origin=GET_PROPERTY
$this: GET_OBJECT 'CLASS CLASS name:Int modality:FINAL visibility:public superTypes:[kotlin.Number; kotlin.Comparable<kotlin.Int>]' type=kotlin.Int.Companion $this: GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=kotlin.Int.Companion
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val] correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY BLOCK_BODY