Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

ThrowInvalidReceiverTypeException from devirtualization #1847

Closed
Tobi29 opened this issue Aug 7, 2018 · 2 comments
Closed

ThrowInvalidReceiverTypeException from devirtualization #1847

Tobi29 opened this issue Aug 7, 2018 · 2 comments
Assignees

Comments

@Tobi29
Copy link

Tobi29 commented Aug 7, 2018

When declaring a class holding a collection

class Wrapper(val list: List<String>)

and declaring a function that calls .map on that collection in another module

fun test(wrapper: Wrapper) {
    println(wrapper.list) // Prints fine
    println(wrapper.list.map { it }) // Crashes
}

and then in turn calling this function from yet another module

fun main(args: Array<String>) {
    test(Wrapper(listOf("A", "B", "C", "D")))
}

the resulting program crashes with:

[A, B, C, D]
Uncaught exception from Kotlin's main: kotlin.RuntimeException: Unexpected receiver type: kotlin.collections.ArrayList
        at kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception (0x405626)
        at kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException (0x405546)
        at kfun:konan.internal.ThrowInvalidReceiverTypeException(kotlin.reflect.KClass<#STAR>)kotlin.Nothing (0x404539)
        at kfun:test(Wrapper) (0x4228cc)
        at kfun:main(kotlin.Array<kotlin.String>) (0x403d81)
        at EntryPointSelector (0x403d16)
        at Konan_start (0x403c87)
        at Konan_run_start (0x403c02)
        at Konan_main (0x403b77)
        at __libc_start_main (0x7f66780d6003)
        at  (0x403a0a)
        at  ((nil))

Merging any of these into a single module fixes the issue as well as disabling devirtualization on the second module.

Archive which reproduces the issue:
konan-bug.tar.gz

Tested with ba30936.

@soywiz
Copy link
Contributor

soywiz commented Aug 8, 2018

I triggered this same error:

https://github.com/korlibs/korlibs/tree/ThrowInvalidReceiverTypeException

kotlin.RuntimeException: Unexpected receiver type: kotlin.collections.ArrayList
        at 3   sample1-native.kexe                 0x000000010d518146 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
        at 4   sample1-native.kexe                 0x000000010d518066 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
        at 5   sample1-native.kexe                 0x000000010d517089 kfun:konan.internal.ThrowInvalidReceiverTypeException(kotlin.reflect.KClass<#STAR>)kotlin.Nothing + 169
        at 6   sample1-native.kexe                 0x000000010d7a4c68 kfun:com.soywiz.korag.AGOpengl.draw(com.soywiz.korag.AG.Buffer;com.soywiz.korag.shader.Program;com.soywiz.korag.AG.DrawType;com.soywiz.korag.shader.VertexLayout;kotlin.Int;com.soywiz.korag.AG.Buffer?;kotlin.Int;com.soywiz.korag.AG.Blending;kotlin.collections.Map<com.soywiz.korag.shader.Uniform,kotlin.Any>;com.soywiz.korag.AG.StencilState;com.soywiz.korag.AG.ColorMaskState;com.soywiz.korag.AG.RenderState;com.soywiz.korag.AG.Scissor?) + 4072

With some traces, in my case the problem happens here: https://github.com/korlibs/korlibs/blob/ThrowInvalidReceiverTypeException/korag/korag-opengl/common/src/com/soywiz/korag/OpenglAG.kt#L183

soywiz added a commit to korlibs/korlibs-all that referenced this issue Aug 8, 2018
@homuroll homuroll self-assigned this Aug 8, 2018
@homuroll
Copy link
Contributor

Fixed in master

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants