yield 在 maven 项目的 buildSequence 中抛出 KotlinNullPointerException

yield throws KotlinNullPointerException in buildSequence for maven projects

我正在研究 Kotlin 中的 coroutines,从这样的斐波那契数列开始:

import kotlin.coroutines.experimental.buildSequence

fun main(args: Array<String>) {
    val fibo = buildSequence {
        yield(0)

        var a = 0
        var b = 1

        while (true) {
            yield(b)
            b = a + b
            a = b - a
        }
    }

    fibo.take(5).forEach { println(it) }
}

我正在使用 IntelliJ IDEA,当上面的代码在 New Project -> Kotlin -> Kotlin(JVM) 创建的项目中运行时,它工作正常。

当代码在从原型 org.jetbrains.kotlin:kotlin-archetype-jvm kotlin-archetype-jvm:1.1.2-4 创建的 Maven 项目中运行时,它会抛出 KotlinNullPointerException.

Exception in thread "main" kotlin.KotlinNullPointerException at kotlin.coroutines.experimental.SequenceBuilderIterator.yield(SequenceBuilder.kt:163) at com.github.fdudannychen.HelloKt$main$fibo.doResume(Hello.kt:7) at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:54) at kotlin.coroutines.experimental.SequenceBuilderIterator.hasNext(SequenceBuilder.kt:128) at kotlin.sequences.TakeSequence$iterator.hasNext(Sequences.kt:348) at com.github.fdudannychen.HelloKt.main(Hello.kt:22)

this article 中的步骤无助于解决问题。我不知道为什么它不起作用。我错过了什么吗?

问题已在 KT-18026 中报告,并标记为已针对 Kotlin 版本 1.1.2-5

修复