Combining `by lazy` and `object` results in compiler-error “cannot find symbol”

别来无恙 提交于 2020-02-29 05:37:07

问题


I cannot compile anymore after the update to Kotlin 1.3.0 (works in 1.2.71) when trying to use by lazy and object. This seems to happen only on my project. A demo-project is working fine.

I want to add an interface to a given class and lazy-load its values.

I've created a small example which is not working in my project but working fine in any other:

open class Foo

interface Bar {
    val lazyLoadedString : String
}

class Test {
    private val foo by lazy {
        object : Foo(), Bar {
            override val lazyLoadedString  = "Demo"
        }
    }
}

As soon as I combine object and by lazy, it cannot compile anymore and shows the following error. Using each one alone works.

Test.java:9: error: cannot find symbol
private final my.package.Test$foo$2$1 getFoo()

symbol: class Test$foo$2$1
location: package my.package

When looking closer, you'll see that the generated java file shows this error and not the kotlin-code.

Any ideas on this?


回答1:


It looks like kapt is broken in Kotlin 1.3.0 for this particular kind of code.

In the code above, it was the annotation processor registered by Realm that triggered it, but any other annotation processor would have resulted in the same error.

The issue is being tracked here: https://youtrack.jetbrains.net/issue/KT-28053



来源:https://stackoverflow.com/questions/53168385/combining-by-lazy-and-object-results-in-compiler-error-cannot-find-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!