@@ -57,6 +57,7 @@ import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl
57
57
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeParameterImpl
58
58
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
59
59
import org.jetbrains.kotlin.name.FqName
60
+ import org.jetbrains.kotlin.name.Name
60
61
import org.jetbrains.kotlin.psi.*
61
62
import org.jetbrains.kotlin.resolve.*
62
63
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
@@ -99,7 +100,7 @@ class ResolverImpl(
99
100
100
101
private val typeMapper = KotlinTypeMapper (
101
102
BindingContext .EMPTY , ClassBuilderMode .LIGHT_CLASSES ,
102
- JvmProtoBufUtil . DEFAULT_MODULE_NAME ,
103
+ module.name.getNonSpecialIdentifier() ,
103
104
KotlinTypeMapper .LANGUAGE_VERSION_SETTINGS_DEFAULT // TODO use proper LanguageVersionSettings
104
105
)
105
106
@@ -629,3 +630,26 @@ private fun TypeSubstitutor.toNewSubstitutor() = composeWith(
629
630
private fun KotlinType.createTypeSubstitutor (): NewTypeSubstitutor {
630
631
return SubstitutionUtils .buildDeepSubstitutor(this ).toNewSubstitutor()
631
632
}
633
+
634
+ /* *
635
+ * Extracts the identifier from a module Name.
636
+ *
637
+ * One caveat here is that kotlin passes a special name into the plugin which cannot be used as an identifier.
638
+ * On the other hand, to construct the correct TypeMapper, we need a non-special name.
639
+ * This function extracts the non-special name from a given name if it is special.
640
+ *
641
+ * @see: https://github.com/JetBrains/kotlin/blob/master/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/TopDownAnalyzerFacadeForJVM.kt#L305
642
+ */
643
+ private fun Name.getNonSpecialIdentifier () :String {
644
+ // the analyzer might pass down a special name which will break type mapper name computations.
645
+ // If it is a special name, we turn it back to an id
646
+ if (! isSpecial || asString().isBlank()) {
647
+ return asString()
648
+ }
649
+ // special names starts with a `<` and usually end with `>`
650
+ return if (asString().last() == ' >' ) {
651
+ asString().substring(1 , asString().length - 1 )
652
+ } else {
653
+ asString().substring(1 )
654
+ }
655
+ }
0 commit comments