Kotlin Flow compilation error

TL;DR:
I encourted a compilation error when using Kotlin Flow, that looks similar to the issue:

Details:
I have a mathod that returns a flow from Room’s @Dao:

In Dao:

    @Transaction
    @Query("SELECT * FROM episodes e WHERE e.tripId = :tripId ORDER BY e.minStartDateTime ASC")
    fun findEpisodesWithStartAndEndPlaceAndMovementsAndTravelModesByTripIdFlow(tripId: Long): Flow<List<EpisodeWithStartAndEndPlaceAndMovementsAndTravelModes>>

Than I use this method in some other class (my own reposiotry in MVVM-Repository pattern):

fun findAllEpisodesByTripId(tripId: Long): Flow<RepoResult<List<Episode>>> {
        return episodeDao.findEpisodesWithStartAndEndPlaceAndMovementsAndTravelModesByTripIdFlow(
            tripId
        ).map { episodeEntities ->
            try {
                val episodes = episodeEntities.map { it.toEpisode() }
                RepoResult.Success(episodes)
            } catch (e: MappingException) {
                RepoResult.Error(e, null)
            } catch (e: NotFoundException) {
                RepoResult.Error(e, null)
            }
        }
    }

However, when I try to compile I get the following error (IDE still highlights nothing, it happens in compilation time):

e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't transform method node:
emit$$forInline (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;:
  @Lorg/jetbrains/annotations/Nullable;() // invisible
    @Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 1
    TRYCATCHBLOCK L0 L1 L2 com/pwr/citybreakplanner/citybreakplanner/coroutines/datasource/db/core/mapper/MappingException
    TRYCATCHBLOCK L0 L1 L3 com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/NotFoundException
    ICONST_4
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    NEW com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$$inlined$map$1$2$1
    DUP
    ALOAD 0
    ALOAD 2
    INVOKESPECIAL com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$$inlined$map$1$2$1.<init> (Lkotlinx/coroutines/flow/FlowKt__TransformKt$map$$inlined$unsafeTransform$1$2;Lkotlin/coroutines/Continuation;)V
    ICONST_5
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    POP
   L4
    LINENUMBER 73 L4
    ALOAD 1
    ALOAD 2
    ASTORE 5
    ASTORE 6
   L5
    ICONST_0
    ISTORE 7
   L6
    LINENUMBER 133 L6
    ALOAD 0
    GETFIELD com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$$inlined$map$1$2.$this_unsafeFlow$inlined : Lkotlinx/coroutines/flow/FlowCollector;
    ALOAD 6
    ALOAD 2
    ASTORE 8
    ASTORE 9
    ASTORE 10
   L7
    ICONST_0
    ISTORE 11
   L8
    LINENUMBER 134 L8
    ALOAD 10
    ALOAD 9
    ALOAD 2
    CHECKCAST kotlin/coroutines/Continuation
    ASTORE 12
    CHECKCAST java/util/List
    ASTORE 13
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.beforeInlineCall ()V
   L9
    ICONST_0
    ISTORE 14
   L10
    LINENUMBER 135 L10
   L11
   L0
    NOP
   L12
    LINENUMBER 136 L12
    ALOAD 13
    CHECKCAST java/lang/Iterable
    ASTORE 15
    NOP
   L13
    ICONST_0
    ISTORE 16
   L14
    LINENUMBER 137 L14
    ALOAD 15
    ASTORE 17
    NEW java/util/ArrayList
    DUP
    ALOAD 15
    BIPUSH 10
    INVOKESTATIC kotlin/collections/CollectionsKt.collectionSizeOrDefault (Ljava/lang/Iterable;I)I
    INVOKESPECIAL java/util/ArrayList.<init> (I)V
    CHECKCAST java/util/Collection
    ASTORE 18
   L15
    ICONST_0
    ISTORE 19
   L16
    LINENUMBER 138 L16
    ALOAD 17
    INVOKEINTERFACE java/lang/Iterable.iterator ()Ljava/util/Iterator; (itf)
    ASTORE 20
   L17
    ALOAD 20
    INVOKEINTERFACE java/util/Iterator.hasNext ()Z (itf)
    IFEQ L18
    ALOAD 20
    INVOKEINTERFACE java/util/Iterator.next ()Ljava/lang/Object; (itf)
    ASTORE 21
   L19
    LINENUMBER 139 L19
    ALOAD 18
    ALOAD 21
    CHECKCAST com/pwr/citybreakplanner/citybreakplanner/coroutines/datasource/db/core/composite/EpisodeWithStartAndEndPlaceAndMovementsAndTravelModes
    ASTORE 22
    ASTORE 23
   L20
    ICONST_0
    ISTORE 24
   L21
    LINENUMBER 136 L21
    ALOAD 0
    GETFIELD com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$$inlined$map$1$2.this$0 : Lkotlinx/coroutines/flow/FlowKt__TransformKt$map$$inlined$unsafeTransform$1;
    GETFIELD com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$$inlined$map$1.this$0 : Lcom/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl;
    ALOAD 22
    ALOAD 2
    ICONST_0
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    INVOKEVIRTUAL com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/coroutinebased/impl/CoroutineEpisodeRepositoryImpl.toEpisode (Lcom/pwr/citybreakplanner/citybreakplanner/coroutines/datasource/db/core/composite/EpisodeWithStartAndEndPlaceAndMovementsAndTravelModes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
    ICONST_1
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    CHECKCAST com/pwr/citybreakplanner/citybreakplanner/coroutines/domain/model/Episode
   L22
    NOP
    GOTO L23
   L23
    ASTORE 25
    ALOAD 23
    ALOAD 25
    INVOKEINTERFACE java/util/Collection.add (Ljava/lang/Object;)Z (itf)
    POP
   L24
    LINENUMBER 138 L24
    GOTO L17
   L18
    LINENUMBER 140 L18
    ALOAD 18
   L25
    CHECKCAST java/util/List
    NOP
    GOTO L26
   L26
   L27
    LINENUMBER 136 L27
    ASTORE 26
   L28
    LINENUMBER 141 L28
    NEW com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Success
    DUP
    ALOAD 26
    INVOKESPECIAL com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Success.<init> (Ljava/lang/Object;)V
    CHECKCAST com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult
   L29
    ASTORE 26
   L1
    GOTO L30
   L2
    LINENUMBER 142 L2
    ASTORE 15
   L31
    LINENUMBER 143 L31
    NEW com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Error
    DUP
    ALOAD 15
    CHECKCAST java/lang/Throwable
    ACONST_NULL
    INVOKESPECIAL com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Error.<init> (Ljava/lang/Throwable;Ljava/lang/Integer;)V
    CHECKCAST com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult
   L32
    ASTORE 26
   L33
    GOTO L30
   L3
    LINENUMBER 144 L3
    ASTORE 15
   L34
    LINENUMBER 145 L34
    NEW com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Error
    DUP
    ALOAD 15
    CHECKCAST java/lang/Throwable
    ACONST_NULL
    INVOKESPECIAL com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult$Error.<init> (Ljava/lang/Throwable;Ljava/lang/Integer;)V
    CHECKCAST com/pwr/citybreakplanner/citybreakplanner/coroutines/repository/RepoResult
   L35
    ASTORE 26
   L36
    LINENUMBER 135 L36
   L30
    ALOAD 26
   L37
    LINENUMBER 146 L37
    NOP
    GOTO L38
   L39
   L40
   L38
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.afterInlineCall ()V
    ALOAD 2
    ICONST_0
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    INVOKEINTERFACE kotlinx/coroutines/flow/FlowCollector.emit (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; (itf)
    ICONST_2
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
    ICONST_1
    INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
   L41
    ARETURN
   L42
   L43
    LOCALVARIABLE it Lcom/pwr/citybreakplanner/citybreakplanner/coroutines/datasource/db/core/composite/EpisodeWithStartAndEndPlaceAndMovementsAndTravelModes; L20 L23 22
    LOCALVARIABLE $i$a$-map-CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$1$episodes$1 I L21 L23 24
    LOCALVARIABLE item$iv$iv Ljava/lang/Object; L19 L24 21
    LOCALVARIABLE $this$mapTo$iv$iv Ljava/lang/Iterable; L15 L25 17
    LOCALVARIABLE destination$iv$iv Ljava/util/Collection; L15 L25 18
    LOCALVARIABLE $i$f$mapTo I L16 L25 19
    LOCALVARIABLE $this$map$iv Ljava/lang/Iterable; L13 L26 15
    LOCALVARIABLE $i$f$map I L14 L26 16
    LOCALVARIABLE episodes Ljava/util/List; L28 L29 26
    LOCALVARIABLE e Lcom/pwr/citybreakplanner/citybreakplanner/coroutines/datasource/db/core/mapper/MappingException; L31 L33 15
    LOCALVARIABLE e Lcom/pwr/citybreakplanner/citybreakplanner/coroutines/repository/NotFoundException; L34 L36 15
    LOCALVARIABLE episodeEntities Ljava/util/List; L9 L40 13
    LOCALVARIABLE continuation Lkotlin/coroutines/Continuation; L9 L40 12
    LOCALVARIABLE $i$a$-map-CoroutineEpisodeRepositoryImpl$findAllEpisodesByTripId$1 I L10 L40 14
    LOCALVARIABLE $receiver Lkotlinx/coroutines/flow/FlowCollector; L7 L41 10
    LOCALVARIABLE value Ljava/lang/Object; L7 L41 9
    LOCALVARIABLE continuation Lkotlin/coroutines/Continuation; L7 L41 8
    LOCALVARIABLE $i$a$-unsafeTransform-FlowKt__TransformKt$map$1 I L8 L41 11
    LOCALVARIABLE value Ljava/lang/Object; L5 L41 6
    LOCALVARIABLE continuation Lkotlin/coroutines/Continuation; L5 L41 5
    LOCALVARIABLE $i$a$-collect-FlowKt__EmittersKt$unsafeTransform$1$1 I L6 L41 7
    LOCALVARIABLE this Lkotlinx/coroutines/flow/FlowKt__TransformKt$map$$inlined$unsafeTransform$1$2; L4 L42 0
    LOCALVARIABLE value Ljava/lang/Object; L4 L42 1
    MAXSTACK = 5
    MAXLOCALS = 27

File is unknown
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:34)
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:92)
	at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:813)
	at org.jetbrains.kotlin.codegen.inline.DeferredMethodVisitor.visitEnd(DeferredMethodVisitor.kt:31)
	at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.doTransform(AnonymousObjectTransformer.kt:175)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.handleAnonymousObjectRegeneration(MethodInliner.kt:184)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.anew(MethodInliner.kt:208)
	at org.jetbrains.org.objectweb.asm.commons.InstructionAdapter.visitTypeInsn(InstructionAdapter.java:472)
	at org.jetbrains.org.objectweb.asm.tree.TypeInsnNode.accept(TypeInsnNode.java:77)
	at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:144)
	at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:792)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:391)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:97)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:70)
	at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethod(AnonymousObjectTransformer.kt:305)
	at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethodAndUpdateGlobalResult(AnonymousObjectTransformer.kt:266)
	at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.doTransform(AnonymousObjectTransformer.kt:157)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.handleAnonymousObjectRegeneration(MethodInliner.kt:184)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.anew(MethodInliner.kt:208)
	at org.jetbrains.org.objectweb.asm.commons.InstructionAdapter.visitTypeInsn(InstructionAdapter.java:472)
	at org.jetbrains.org.objectweb.asm.tree.TypeInsnNode.accept(TypeInsnNode.java:77)
	at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:144)
	at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:792)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:391)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:97)
	at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:70)
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.inlineCall(InlineCodegen.kt:251)
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:142)
	at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCallInner(PsiInlineCodegen.kt:68)
	at org.jetbrains.kotlin.codegen.CallGenerator$DefaultImpls.genCall(CallGenerator.kt:115)
	at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCall(PsiInlineCodegen.kt:31)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2563)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2506)
	at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:41)
	at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:13)
	at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:386)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.lambda$visitReturnExpression$11(ExpressionCodegen.java:1642)
	at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
	at org.jetbrains.kotlin.codegen.StackValueWithLeaveTask.putSelector(StackValue.kt:67)
	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:386)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:367)
	at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1731)
	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:64)
	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:84)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:654)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:479)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:261)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:177)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.gen(FunctionCodegen.java:148)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genSimpleMember(MemberCodegen.java:197)
	at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateDeclaration(ClassBodyCodegen.java:166)
	at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:86)
	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:129)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:302)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:286)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:115)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:134)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:70)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:88)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:634)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:194)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:163)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:85)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:105)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:349)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:237)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:79)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:91)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:606)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:99)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
	at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 187: Cannot pop operand off an empty stack.
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:34)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.analyze(MethodTransformer.java:44)
	at org.jetbrains.kotlin.codegen.inline.coroutines.SurroundSuspendLambdaCallsWithSuspendMarkersMethodVisitor.performTransformations(CoroutineTransformer.kt:256)
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.kt:70)
	... 96 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 187: Cannot pop operand off an empty stack.
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:295)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:31)
	... 99 more
Caused by: java.lang.IndexOutOfBoundsException: Cannot pop operand off an empty stack.
	at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.pop(Frame.java:226)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:608)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:187)
	... 100 more


> Task :app:compileDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

I got it.

It’s worth mentioning that the .toEpisode() extension function is a suspending function.

But the main problem was the passing suspending mapping function as lambda to map operator.

I ended up with such code, which compiles correcly (I moved out the anonymous function from the map operator and definied it as a method. Then passing reference to the method works fine)

fun findAllEpisodesByTripId(tripId: Long): Flow<RepoResult<List<Episode>>> {
        return episodeDao.findEpisodesWithStartAndEndPlaceAndMovementsAndTravelModesByTripIdFlow(
            tripId
        ).map(this::transformEpisodesFromDbToModel)

And the extracted function:

    private suspend fun transformEpisodesFromDbToModel(
        episodeEntities: List<EpisodeWithStartAndEndPlaceAndMovementsAndTravelModes>
    ): RepoResult<List<Episode>> {
        return try { 
            val episodes: List<Episode> = episodeEntities
                .asFlow()
                .map { it.toEpisode() }
                .toList()
            RepoResult.Success(episodes)
        } catch (e: MappingException) {
            RepoResult.Error(e, null)
        } catch (e: NotFoundException) {
            RepoResult.Error(e, null)
        }
    }

Although, I suggest making the compile time error more readable :wink:

PS: Here I am using .asFlow and than mapping the flow toEpisode ``it.toEpisode()```. I don’t know if this step is 100% necessary.

1 Like

Yeah well. It’s not a compile time error. Your code is fine (as far as I can tell). This is a bug in the compiler itself. You should never see a stacktrace during compilation.

Also I don’t think this is the same issue you linked above. That issue is caused by recursion of an inner suspending function. Your code neither has an inner function nor recursion.
You should create a bug report at https://kotl.in/issue

2 Likes

I just found this issue https://youtrack.jetbrains.com/issue/KT-35054

It might be the same as yours. It’s caused by the try-catch block within a crossinlined suspend lambda like the one passed to map.
The issue says that it seems to be solved in kotlin 1.4. You could try using the kotlin 1.4-M3 build and see if this fixes your error.

2 Likes

Thank you for your response! :slight_smile: