Hi, if my compiler plugin runs on a multiplatform ...
# compiler
n
Hi, if my compiler plugin runs on a multiplatform project (jvm with IR & macos), how can I reference common stdlib classes like
HashMap
?
pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
• On JVM returns
null
• On Macos (K/N) returns the symbol Since
HashMap
is a typealias to
java.util.HashMap
I thought using
pluginContext.referenceTypeAlias(FqName("kotlin.collections.HashMap"))
could work but it's behaving differently • ON JVM it throws
Copy code
AssertionError: Package or class expected: typealias HashMap; for K
t org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase$createLazyParent$1.invoke(IrLazyDeclarationBase.kt:70)
• On K/N (macos) it returns
null
How can one reference an available common class from the stdlib like
kotlin.collections.HashMap
? The only work around I can see is to test if
pluginContext.referenceClass(FqName("java.util.HashMap"))
returns null, which indicates I'm running the compiler plugin within a K/N context and fallback to
pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
... Any thoughts appreciated 🙂
s
Hi!
The only work around I can see is to test if 
pluginContext.referenceClass(FqName("java.util.HashMap"))
 returns null, which indicates I’m running the compiler plugin within a K/N context and fallback to 
pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
 ...
What’s wrong with this one, if it works? Generally, backends handle expect-actual not like frontend does, and I’m not sure one can reliably consider there is such thing as “common class” in this case (since there is no such class on JVM). Also, it should be possible to get information about platform directly, with
pluginContext.platform
.
🙏 1