FIR mangler: fix alias-based type handling #KT-42770 Fixed

This commit is contained in:
Mikhail Glukhikh
2020-10-19 13:43:44 +03:00
parent 6251568e17
commit 44459e8ac7
6 changed files with 96 additions and 0 deletions
@@ -14,8 +14,10 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visitors.FirVisitor
@@ -199,6 +201,10 @@ open class FirJvmMangleComputer(
when (type) {
is ConeLookupTagBasedType -> {
when (val symbol = type.lookupTag.toSymbol(session)) {
is FirTypeAliasSymbol -> {
mangleType(tBuilder, type.fullyExpandedType(session))
return
}
is FirClassSymbol -> symbol.fir.accept(copy(MangleMode.FQNAME), false)
is FirTypeParameterSymbol -> tBuilder.mangleTypeParameterReference(symbol.fir)
}
@@ -1772,6 +1772,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt");
}
@TestMetadata("SignatureClash.kt")
public void testSignatureClash() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt");
}
@TestMetadata("V8ArrayToList.kt")
public void testV8ArrayToList() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/V8ArrayToList.kt");
@@ -0,0 +1,34 @@
FILE fqName:<root> fileName:/SignatureClash.kt
TYPEALIAS name:Some visibility:public expandedType:kotlin.Function1<kotlin.Any, kotlin.String?>
CLASS OBJECT name:Factory modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Factory
CONSTRUCTOR visibility:private <> () returnType:<root>.Factory [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Factory modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Factory, a:kotlin.String) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Factory
VALUE_PARAMETER name:a index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.String): kotlin.String declared in <root>.Factory'
CONST String type=kotlin.String value="Alpha"
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Factory, a:kotlin.String, f:kotlin.Function1<kotlin.Any, kotlin.String?>) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Factory
VALUE_PARAMETER name:a index:0 type:kotlin.String
VALUE_PARAMETER name:f index:1 type:kotlin.Function1<kotlin.Any, kotlin.String?>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.String, f: kotlin.Function1<kotlin.Any, kotlin.String?>): kotlin.String declared in <root>.Factory'
CONST String type=kotlin.String value="Omega"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,12 @@
typealias Some = (Any) -> String?
object Factory {
fun foo(
a: String,
): String = "Alpha"
fun foo(
a: String,
f: Some
): String = "Omega"
}
@@ -0,0 +1,34 @@
FILE fqName:<root> fileName:/SignatureClash.kt
TYPEALIAS name:Some visibility:public expandedType:kotlin.Function1<kotlin.Any, kotlin.String?>
CLASS OBJECT name:Factory modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Factory
CONSTRUCTOR visibility:private <> () returnType:<root>.Factory [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Factory modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Factory, a:kotlin.String) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Factory
VALUE_PARAMETER name:a index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.String): kotlin.String declared in <root>.Factory'
CONST String type=kotlin.String value="Alpha"
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Factory, a:kotlin.String, f:kotlin.Function1<kotlin.Any, kotlin.String?>{ <root>.Some }) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Factory
VALUE_PARAMETER name:a index:0 type:kotlin.String
VALUE_PARAMETER name:f index:1 type:kotlin.Function1<kotlin.Any, kotlin.String?>{ <root>.Some }
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (a: kotlin.String, f: kotlin.Function1<kotlin.Any, kotlin.String?>{ <root>.Some }): kotlin.String declared in <root>.Factory'
CONST String type=kotlin.String value="Omega"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -1771,6 +1771,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt");
}
@TestMetadata("SignatureClash.kt")
public void testSignatureClash() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/SignatureClash.kt");
}
@TestMetadata("V8ArrayToList.kt")
public void testV8ArrayToList() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/V8ArrayToList.kt");