Skip to content

Commit bb5c8b3

Browse files
committed
Comprehension with alias is never trailing map
1 parent e2c0c94 commit bb5c8b3

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.*
@@ -2236,7 +2235,7 @@ object desugar {
22362235
case (Tuple(ts1), Tuple(ts2)) => ts1.corresponds(ts2)(deepEquals)
22372236
case _ => false
22382237

2239-
def markTrailingMap(aply: Apply, gen: GenFrom, selectName: TermName, body: Tree): Unit =
2238+
def markTrailingMap(aply: Apply, gen: GenFrom, selectName: TermName): Unit =
22402239
if sourceVersion.enablesBetterFors
22412240
&& selectName == mapName
22422241
&& gen.checkMode != GenCheckMode.Filtered // results of withFilter have the wrong type
@@ -2248,7 +2247,7 @@ object desugar {
22482247
case Nil if sourceVersion.enablesBetterFors => body
22492248
case (gen: GenFrom) :: Nil =>
22502249
Apply(rhsSelect(gen, mapName), makeLambda(gen, body))
2251-
.tap(markTrailingMap(_, gen, mapName, body))
2250+
.tap(markTrailingMap(_, gen, mapName))
22522251
case (gen: GenFrom) :: (rest @ (GenFrom(_, _, _) :: _)) =>
22532252
val cont = makeFor(mapName, flatMapName, rest, body)
22542253
Apply(rhsSelect(gen, flatMapName), makeLambda(gen, cont))
@@ -2265,7 +2264,6 @@ object desugar {
22652264
if suffix.exists(_.isInstanceOf[GenFrom]) then flatMapName
22662265
else mapName
22672266
Apply(rhsSelect(gen, selectName), makeLambda(gen, cont))
2268-
.tap(markTrailingMap(_, gen, selectName, cont))
22692267
else
22702268
val (pats, rhss) = valeqs.map { case GenAlias(pat, rhs) => (pat, rhs) }.unzip
22712269
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)