Kotlin bug with SAM conversion and Java inner class


Java file:

public class Test {
    public interface Interface {
        int call(int i);

    public class Cls {
        private Interface i;

        public Cls(Interface i) {
            this.i = i;

Kotlin file:

object Main {
    fun main() {
        val a = Test.Cls { it }

Expected behavior:
Report error of “Constructor of inner class can only be called with receiver of containing class”

Current behavior:
When compile, it reports “Internal error: Unsupported receiver value: null” in the codegen. And in IDEA, it reports an “Assertion error” with a long stacktrace. It seems that the the error is not detected in the code analysis phase.

Kotlin version: 1.2


Cls is an inner class, so it can only be created by referencing instance of Test object, but it is strange that you can’t use labda syntax here either way.

This syntax will work:

val a = Test().Cls(Test.Interface { it })