Skip to content

Commit c5bd0c3

Browse files
committed
Change encoding of capturing ByNameTypeTrees
1 parent 24cb35b commit c5bd0c3

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
@@ -1935,9 +1935,10 @@ object Parsers {
19351935
def paramTypeOf(core: () => Tree): Tree =
19361936
if in.token == ARROW || isPureArrow(nme.PUREARROW) then
19371937
val isImpure = in.token == ARROW
1938-
val tp = atSpan(in.skipToken()):
1939-
ByNameTypeTree(if isImpure then core() else capturesAndResult(core))
1940-
if isImpure && Feature.pureFunsEnabled then ImpureByNameTypeTree(tp) else tp
1938+
atSpan(in.skipToken()):
1939+
val tp = if isImpure then core() else capturesAndResult(core)
1940+
if isImpure && Feature.pureFunsEnabled then ImpureByNameTypeTree(tp)
1941+
else ByNameTypeTree(tp)
19411942
else
19421943
core()
19431944

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
570570
toText(sel) ~ keywordStr(" match ") ~ blockText(cases) ~
571571
(" <: " ~ toText(bound) provided !bound.isEmpty)
572572
}
573+
case ImpureByNameTypeTree(tpt) =>
574+
"=> " ~ toTextLocal(tpt)
573575
case ByNameTypeTree(tpt) =>
574-
(if Feature.pureFunsEnabled then "-> " else "=> ")
575-
~ toTextLocal(tpt)
576+
(if Feature.pureFunsEnabled then "-> " else "=> ") ~ toTextLocal(tpt)
576577
case TypeBoundsTree(lo, hi, alias) =>
577578
if (lo eq hi) && alias.isEmpty then optText(lo)(" = " ~ _)
578579
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)