Cannot use take/takeWhile on Sequence

Compilation of the following code fails:   var reader = BufferedReader(content)   try {   val pattern = Pattern.compile(somePattern)   return reader.lines()            .filter { pattern.matcher(it).find() }            .map {            val matcher = pattern.matcher(it)            matcher.find()            matcher.group(1)            }            .take(1)            .first()   } finally {   reader.close()   }

with this message:

Error:(170, 14) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun kotlin.ByteArray.take(n: kotlin.Int): kotlin.List<kotlin.Byte> defined in kotlin
public fun kotlin.CharArray.take(n: kotlin.Int): kotlin.List<kotlin.Char> defined in kotlin
kotlin.deprecated public fun <T> kotlin.Stream<kotlin.String>.take(n: kotlin.Int): kotlin.Stream<kotlin.String> defined in kotlin
public fun kotlin.FloatArray.take(n: kotlin.Int): kotlin.List<kotlin.Float> defined in kotlin
public fun kotlin.IntArray.take(n: kotlin.Int): kotlin.List<kotlin.Int> defined in kotlin
public fun <T> kotlin.Collection<kotlin.String>.take(n: kotlin.Int): kotlin.List<kotlin.String> defined in kotlin
public fun <T> kotlin.Iterable<kotlin.String>.take(n: kotlin.Int): kotlin.List<kotlin.String> defined in kotlin
public fun kotlin.DoubleArray.take(n: kotlin.Int): kotlin.List<kotlin.Double> defined in kotlin
public fun kotlin.LongArray.take(n: kotlin.Int): kotlin.List<kotlin.Long> defined in kotlin
public fun <T> kotlin.Sequence<kotlin.String>.take(n: kotlin.Int): kotlin.Sequence<kotlin.String> defined in kotlin
public fun kotlin.BooleanArray.take(n: kotlin.Int): kotlin.List<kotlin.Boolean> defined in kotlin
public fun <T> kotlin.Array<out kotlin.String>.take(n: kotlin.Int): kotlin.List<kotlin.String> defined in kotlin
kotlin.deprecated public fun <T> kotlin.Iterator<kotlin.String>.take(n: kotlin.Int): kotlin.Iterator<kotlin.String> defined in kotlin
public fun kotlin.ShortArray.take(n: kotlin.Int): kotlin.List<kotlin.Short> defined in kotlin
public fun kotlin.String.take(n: kotlin.Int): kotlin.String defined in kotlin

I am using kotlin/stdlib version 0.11.91.1

Is this a bug I should report?
Or how am I supposed to fix this, cannot wrap my head around this error.
This is new code, but I seem to have no issues in using take/takeWhile in similar situations earlier.

Also note that IDE doesn’t higlight any errors, this happens only when I hit ‘compile & run’ button.

Same error occurs for 'takeWhile'' if I use it on this sequence

OK, somehting weird is going on.

I split into declaration and assignment and then added the explicit type:


  val lines: Sequence<String>
  lines = reader.lines() // <- error points to this line

After this compiler throws this error:

Error:(161, 17) Type mismatch: inferred type is java.util.stream.Stream<kotlin.String!>! but kotlin.Sequence<kotlin.String> was expected

Wat?! java’s Stream? where did it come from?..