JS: serialize type of local anonymous class as its denotable supertype. See KT-14888
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
open class KotlinSerializerExtensionBase(private val protocol: SerializerExtensionProtocol) : SerializerExtension() {
|
||||
override final val stringTable = StringTableImpl()
|
||||
override val stringTable = StringTableImpl()
|
||||
|
||||
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder) {
|
||||
for (annotation in descriptor.annotations) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.utils.Interner
|
||||
import java.io.OutputStream
|
||||
|
||||
class StringTableImpl : StringTable {
|
||||
open class StringTableImpl : StringTable {
|
||||
private class FqNameProto(val fqName: QualifiedName.Builder) {
|
||||
override fun hashCode(): Int {
|
||||
var result = 13
|
||||
@@ -72,7 +72,7 @@ class StringTableImpl : StringTable {
|
||||
is ClassDescriptor -> {
|
||||
builder.parentQualifiedName = getFqNameIndex(containingDeclaration)
|
||||
}
|
||||
else -> throw IllegalStateException("Cannot get FQ name of local class: " + descriptor)
|
||||
else -> return getFqNameIndexOfLocalAnonymousClass(descriptor)
|
||||
}
|
||||
|
||||
builder.shortName = getStringIndex(descriptor.name.asString())
|
||||
@@ -80,6 +80,10 @@ class StringTableImpl : StringTable {
|
||||
return qualifiedNames.intern(FqNameProto(builder))
|
||||
}
|
||||
|
||||
open fun getFqNameIndexOfLocalAnonymousClass(descriptor: ClassifierDescriptorWithTypeParameters): Int {
|
||||
throw IllegalStateException("Cannot get FQ name of local class: " + descriptor)
|
||||
}
|
||||
|
||||
fun getPackageFqNameIndex(fqName: FqName): Int {
|
||||
var result = -1
|
||||
for (segment in fqName.pathSegments()) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
interface I {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
abstract class A {
|
||||
abstract fun bar(): String
|
||||
}
|
||||
|
||||
abstract class G<T> {
|
||||
abstract fun baz(): T
|
||||
}
|
||||
|
||||
class C {
|
||||
private val propA = object : A() {
|
||||
override fun bar() = "propA.bar"
|
||||
|
||||
fun x() = "OK"
|
||||
}
|
||||
|
||||
private val propI = object : I {
|
||||
override fun foo() = "propI.foo"
|
||||
|
||||
fun x() = "OK"
|
||||
}
|
||||
|
||||
private val propAI = object : A(), I {
|
||||
override fun foo() = "propAI.foo"
|
||||
|
||||
override fun bar() = "propAI.bar"
|
||||
|
||||
fun x() = "OK"
|
||||
}
|
||||
|
||||
private val propG = object : G<String>() {
|
||||
override fun baz() = "propG.baz"
|
||||
|
||||
fun x() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
fun test() {
|
||||
println(C().<!INVISIBLE_MEMBER!>propA<!>.x())
|
||||
println(C().<!INVISIBLE_MEMBER!>propI<!>.x())
|
||||
println(C().<!INVISIBLE_MEMBER!>propAI<!>.x())
|
||||
println(C().<!INVISIBLE_MEMBER!>propG<!>.x())
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// -- Module: <lib> --
|
||||
package
|
||||
|
||||
public abstract class A {
|
||||
public constructor A()
|
||||
public abstract 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
|
||||
}
|
||||
|
||||
public final class C {
|
||||
public constructor C()
|
||||
private final val propA: C.propA.<no name provided>
|
||||
private final val propAI: C.propAI.<no name provided>
|
||||
private final val propG: C.propG.<no name provided>
|
||||
private final val propI: C.propI.<no name provided>
|
||||
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
|
||||
}
|
||||
|
||||
public abstract class G</*0*/ T> {
|
||||
public constructor G</*0*/ T>()
|
||||
public abstract fun baz(): 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
|
||||
}
|
||||
|
||||
public interface I {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
|
||||
// -- Module: <main> --
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
@@ -36,6 +36,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("localClassMetadata.kt")
|
||||
public void testLocalClassMetadata() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/localClassMetadata.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("runtimeAnnotations.kt")
|
||||
public void testRuntimeAnnotations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/runtimeAnnotations.kt");
|
||||
|
||||
Reference in New Issue
Block a user