Skip to content

Commit f2a3adb

Browse files
committed
Comprehension with alias is never trailing map
1 parent 05f4d59 commit f2a3adb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import util.{Property, SourceFile, SourcePosition, SrcPos, Chars}
1313
import config.{Feature, Config}
1414
import config.Feature.{sourceVersion, migrateTo3, enabled}
1515
import config.SourceVersion.*
16-
import collection.mutable
16+
import collection.mutable, mutable.ListBuffer
1717
import reporting.*
1818
import printing.Formatting.hl
1919
import config.Printers
2020
import parsing.Parsers
21-
import dotty.tools.dotc.util.chaining.*
21+
import util.chaining.*
2222

2323
import scala.annotation.{unchecked as _, *}, internal.sharable
24-
import scala.collection.mutable, mutable.ListBuffer
2524

2625
object desugar {
2726
import untpd.*
@@ -2234,7 +2233,7 @@ object desugar {
22342233
case (Tuple(ts1), Tuple(ts2)) => ts1.corresponds(ts2)(deepEquals)
22352234
case _ => false
22362235

2237-
def markTrailingMap(aply: Apply, gen: GenFrom, selectName: TermName, body: Tree): Unit =
2236+
def markTrailingMap(aply: Apply, gen: GenFrom, selectName: TermName): Unit =
22382237
if sourceVersion.enablesBetterFors
22392238
&& selectName == mapName
22402239
&& gen.checkMode != GenCheckMode.Filtered // results of withFilter have the wrong type
@@ -2246,7 +2245,7 @@ object desugar {
22462245
case Nil if sourceVersion.enablesBetterFors => body
22472246
case (gen: GenFrom) :: Nil =>
22482247
Apply(rhsSelect(gen, mapName), makeLambda(gen, body))
2249-
.tap(markTrailingMap(_, gen, mapName, body))
2248+
.tap(markTrailingMap(_, gen, mapName))
22502249
case (gen: GenFrom) :: (rest @ (GenFrom(_, _, _) :: _)) =>
22512250
val cont = makeFor(mapName, flatMapName, rest, body)
22522251
Apply(rhsSelect(gen, flatMapName), makeLambda(gen, cont))
@@ -2263,7 +2262,6 @@ object desugar {
22632262
if suffix.exists(_.isInstanceOf[GenFrom]) then flatMapName
22642263
else mapName
22652264
Apply(rhsSelect(gen, selectName), makeLambda(gen, cont))
2266-
.tap(markTrailingMap(_, gen, selectName, cont))
22672265
else
22682266
val (pats, rhss) = valeqs.map { case GenAlias(pat, rhs) => (pat, rhs) }.unzip
22692267
val (defpat0, id0) = makeIdPat(gen.pat)

tests/run/better-fors-map-elim.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ object MyOption:
4242
extension (i: Int) def map[A](f: Int => A): A = ???
4343

4444
val _ = for j <- 42 yield j
45+
46+
val _ = for x = 42; x <- MyOption(x) yield x

0 commit comments

Comments
 (0)