Hey Everyone, I'm struggling to fix this compiler ...
# compiler
c
Hey Everyone, I'm struggling to fix this compiler error, it seems to be struggling with me creating a getter block with my mapof. It' should be generating an companion object with a property of
propertyIndices
I.e. should generate:
Copy code
data class User(
  val name: String
) {
 // basically generate this:
companion object {
  val propertyIndices: Map<String, Int>
    get() = mapOf("name" to 0)
}
}
what stupid thing am I missing?
z
what's the error message? You only pasted the IR dump but the error message is usually below that
c
Copy code
e: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /var/folders/11/343178bs5fgdz44s8lnn3l9r0000gn/T/junit4390338892868527185/compilationDir/sources/simple.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:48)
	at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:107)
	at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException$default(CodegenUtil.kt:90)
	at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invokeSequential(performByIrFile.kt:54)
	at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:41)
	at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:27)
	at org.jetbrains.kotlin.config.phaser.CompilerPhaseKt.invokeToplevel(CompilerPhase.kt:62)
	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.invokeCodegen(JvmIrCodegenFactory.kt:371)

Caused by: java.lang.NullPointerException
	at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.visitCall(ExpressionCodegen.kt:567)
	at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.visitCall(ExpressionCodegen.kt:135)
	at org.jetbrains.kotlin.ir.expressions.IrCall.accept(IrCall.kt:24)
	at org.jetbrains.kotlin.backend.jvm.intrinsics.ArraySet.invoke(ArraySet.kt:32)
	at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.visitCall(ExpressionCodegen.kt:541)
	at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.visitCall(ExpressionCodegen.kt:135)
	at org.jetbrains.kotlin.ir.expressions.IrCall.accept(IrCall.kt:24)
Assuming it's the irCall (of mapOf) the issue based on the exeception
Yeah so I comented out a bunch of stuff so its just doing
mapOf()
no paris, and it compiles, so I must be making my
"name" to 0
pairs wrong
oh think I worked it out, guess I don't know the difference between insertDispatchReceiver and extensionreceiver
z
you probably need to look up the multi-arg symbol it's overloading to
dispatchReceiver = the instance you're calling it on (or object instance if it's an object)
extension = the extension receiver
c
ahh yeah that was the issue then
p
I also think it can be problematic that mapOf expects vararg, while you passing an array. You probably need to wrap it with IrVararg with spread or with just regular elements without creating array yourself. The best option is to write the code manually, dump which IR is created and create the same.
c
oh didn't know you could dump the ir from manually created code
z
yeah TIL on that too. I knew about the PSI viewer and FIR explorers, but not one for IR. How does one do that?
p
There is no IDE support for that, but you can do it with
-Xphases-to-dump-before=ExternalPackageParentPatcherLowering
(this is first phase, but it work with any other, can be different for non-jvm) compiler flag. This would print to stdout. With
-Xdump-directory
flag you can dump it to files instead.
🔥 1
s
Re: dumping IR, you also can use debugger with the compiler plugin and dump any part of the current module from there
👌 1
d
Also note that with internal compiler test framework you are getting FIR and IR dumps for each test out of box using
// FIR_DUMP
and
// DUMP_IR
directives