From 44d5ada477d8ffaadce6364e85adefb433e48319 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 7 Aug 2023 16:03:59 +0200 Subject: [PATCH] Test for #18345 Closes #18345 [Cherry-picked 072b2e5b2e660096bb6dbb4328d5f05894e9e0fc] --- tests/pos/i18345.scala | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/pos/i18345.scala diff --git a/tests/pos/i18345.scala b/tests/pos/i18345.scala new file mode 100644 index 000000000000..2064a4ce75e9 --- /dev/null +++ b/tests/pos/i18345.scala @@ -0,0 +1,28 @@ +extension (vec: Seq[Int]) + def iterate[T](body: (() => Int) => T): T = + val iterator = vec.iterator + body(() => iterator.nextOption().getOrElse(0)) + +def withSequence[T](n: Int)(body: Seq[Int] => T): T = + body((0 to n)) + +def test = + + withSequence(2): + _.iterate: next => + next() + next() + next() + next() + + withSequence(2): + _.iterate: + next => + next() + next() + next() + next() + + withSequence(2): x => + x.iterate: + next => + next() + next() + next() + next() + + withSequence(2): x => + x.iterate: next => + next() + next() + next() + next() +