Skip to content

Commit ab2ff3b

Browse files
committed
Change encoding of capturing ByNameTypeTrees
1 parent 9127445 commit ab2ff3b

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,15 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
473473
*/
474474
object ImpureByNameTypeTree:
475475

476-
def apply(tp: ByNameTypeTree)(using Context): untpd.CapturingTypeTree =
477-
untpd.CapturingTypeTree(
478-
untpd.captureRoot.withSpan(tp.span.startPos) :: Nil, tp)
479-
480-
def unapply(tp: Tree)(using Context): Option[ByNameTypeTree] = tp match
481-
case untpd.CapturingTypeTree(id @ Select(_, nme.CAPTURE_ROOT) :: Nil, bntp: ByNameTypeTree)
482-
if id.span == bntp.span.startPos => Some(bntp)
476+
def apply(tp: Tree)(using Context): untpd.ByNameTypeTree =
477+
untpd.ByNameTypeTree(
478+
untpd.CapturesAndResult(
479+
untpd.captureRoot.withSpan(tp.span.startPos) :: Nil, tp))
480+
481+
def unapply(tp: Tree)(using Context): Option[Tree] = tp match
482+
case untpd.ByNameTypeTree(
483+
untpd.CapturesAndResult(id @ Select(_, nme.CAPTURE_ROOT) :: Nil, result))
484+
if id.span == result.span.startPos => Some(result)
483485
case _ => None
484486
end ImpureByNameTypeTree
485487
}

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,10 @@ object Parsers {
19361936
def paramTypeOf(core: () => Tree): Tree =
19371937
if in.token == ARROW || isPureArrow(nme.PUREARROW) then
19381938
val isImpure = in.token == ARROW
1939-
val tp = atSpan(in.skipToken()):
1940-
ByNameTypeTree(if isImpure then core() else capturesAndResult(core))
1941-
if isImpure && Feature.pureFunsEnabled then ImpureByNameTypeTree(tp) else tp
1939+
atSpan(in.skipToken()):
1940+
val tp = if isImpure then core() else capturesAndResult(core)
1941+
if isImpure && Feature.pureFunsEnabled then ImpureByNameTypeTree(tp)
1942+
else ByNameTypeTree(tp)
19421943
else
19431944
core()
19441945

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
566566
toText(sel) ~ keywordStr(" match ") ~ blockText(cases) ~
567567
(" <: " ~ toText(bound) provided !bound.isEmpty)
568568
}
569+
case ImpureByNameTypeTree(tpt) =>
570+
"=> " ~ toTextLocal(tpt)
569571
case ByNameTypeTree(tpt) =>
570-
(if Feature.pureFunsEnabled then "-> " else "=> ")
571-
~ toTextLocal(tpt)
572+
(if Feature.pureFunsEnabled then "-> " else "=> ") ~ toTextLocal(tpt)
572573
case TypeBoundsTree(lo, hi, alias) =>
573574
if (lo eq hi) && alias.isEmpty then optText(lo)(" = " ~ _)
574575
else optText(lo)(" >: " ~ _) ~ optText(hi)(" <: " ~ _) ~ optText(alias)(" = " ~ _)
@@ -742,12 +743,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
742743
case CapturesAndResult(refs, parent) =>
743744
changePrec(GlobalPrec)("^{" ~ Text(refs.map(toText), ", ") ~ "} " ~ toText(parent))
744745
case CapturingTypeTree(refs, parent) =>
745-
parent match
746-
case ImpureByNameTypeTree(bntpt) =>
747-
"=> " ~ toTextLocal(bntpt)
748-
case _ =>
749-
toText(parent) ~ "^"
750-
~ changePrec(GlobalPrec)("{" ~ Text(refs.map(toText), ", ") ~ "}")
746+
toText(parent) ~ "^"
747+
~ changePrec(GlobalPrec)("{" ~ Text(refs.map(toText), ", ") ~ "}")
751748
case _ =>
752749
tree.fallbackToText(this)
753750
}

0 commit comments

Comments
 (0)