Skip to content

Commit 7658cba

Browse files
committed
Fix rendering of context function types
1 parent edc1c4d commit 7658cba

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

local/project/dummy/arrows.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ trait Arrows:
4545
def pathDependent2(n: Nested^)(g: AnyRef^{n.next.c} => Any): Any
4646
def pathDependent3(n: Nested^)(g: AnyRef^{n.c} => AnyRef^{n.next.c} ->{n.c} Any): Any
4747
def pathDependent4(n: Nested^)(g: AnyRef^{n.c} => AnyRef^{n.next.c} ->{n.c} Any): AnyRef^{n.next.next.c}
48-
def pathDependent5(n: Nested^)(g: AnyRef^{n.c} => AnyRef^{n.next.c} ->{n.c} Any): AnyRef^{n.next.next.c*, n.c}
48+
def pathDependent5(n: Nested^)(g: AnyRef^{n.c} => AnyRef^{n.next.c} ->{n.c} Any): AnyRef^{n.next.next.c*, n.c}
49+
50+
def contextPure(f: AnyRef^{a} ?-> Int): Int
51+
def contextImpure(f: AnyRef^{a} ?=> Int): Int
52+
def contextImpure2(f: AnyRef^{a} ?->{b,c} Int): Int
53+
def contextImpure3(f: AnyRef^{a} ?->{b,c} Int => AnyRef^{a} ?=> Int): Int

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ trait TypesSupport:
122122
++ keyword(" & ").l
123123
++ inParens(inner(right, skipThisTypePrefix), shouldWrapInParens(right, tp, false))
124124
case ByNameType(CapturingType(tpe, refs)) =>
125-
renderCaptureArrow(using q)(Some(refs), skipThisTypePrefix)(using elideThis, originalOwner) ++ (plain(" ") :: inner(tpe, skipThisTypePrefix))
126-
case ByNameType(tpe) => keyword("=>!! ") :: inner(tpe, skipThisTypePrefix) // FIXME: does it need change for CC?
125+
renderCaptureArrow(using q)(refs, false, skipThisTypePrefix) ++ (plain(" ") :: inner(tpe, skipThisTypePrefix))
126+
case ByNameType(tpe) =>
127+
tpe.typeSymbol.pos.map(p => report.warning(s"Pure ByNameType at ${p}"))
128+
keyword("-> ") :: inner(tpe, skipThisTypePrefix) // FIXME need to check if cc is enabled in current file first!!!
127129
case ConstantType(constant) =>
128130
plain(constant.show).l
129131
case ThisType(tpe) =>
@@ -349,9 +351,13 @@ trait TypesSupport:
349351
inCC: Option[List[reflect.TypeRepr]],
350352
): SSignature =
351353
import reflect._
352-
val arrow = if t.isContextFunctionType then keyword(" ?=> ").l // FIXME: can we have contextual functions with capture sets?
353-
else plain(" ") :: (renderCaptureArrow(using q)(inCC, skipThisTypePrefix) ++ plain(" ").l)
354-
given Option[List[TypeRepr]] = None
354+
val refs = if !inCC.isDefined && t.isContextFunctionType then
355+
// This'll ensure that an impure context function type is rendered correctly
356+
Some(List(CaptureDefs.captureRoot.termRef))
357+
else
358+
inCC
359+
val arrow = plain(" ") :: (renderCaptureArrow(using q)(refs, t.isContextFunctionType, skipThisTypePrefix) ++ plain(" ").l)
360+
given Option[List[TypeRepr]] = None // FIXME: this is ugly
355361
args match
356362
case Nil => Nil
357363
case List(rtpe) => plain("()").l ++ arrow ++ inner(rtpe, skipThisTypePrefix)
@@ -499,19 +505,21 @@ trait TypesSupport:
499505
import reflect._
500506
Keyword("^") :: renderCaptureSet(refs, skipThisTypePrefix)
501507

502-
private def renderCaptureArrow(using q: Quotes)(refs: List[reflect.TypeRepr], skipThisTypePrefix: Boolean)(
508+
private def renderCaptureArrow(using q: Quotes)(refs: List[reflect.TypeRepr], isImplicitFun: Boolean, skipThisTypePrefix: Boolean)(
503509
using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol
504510
): SSignature =
505-
import reflect.*
511+
import reflect._
512+
val prefix = if isImplicitFun then "?" else ""
506513
refs match
507-
case Nil => List(Keyword("->"))
508-
case List(ref) if ref.isCaptureRoot => List(Keyword("=>"))
509-
case refs => Keyword("->") :: renderCaptureSet(using q)(refs, skipThisTypePrefix)
514+
case Nil => List(Keyword(prefix + "->")) // FIXME need to check if cc is enabled in current file first!!!
515+
case List(ref) if ref.isCaptureRoot => List(Keyword(prefix + "=>"))
516+
case refs => Keyword(prefix + "->") :: renderCaptureSet(using q)(refs, skipThisTypePrefix)
510517

511-
private def renderCaptureArrow(using q: Quotes)(refs: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(
518+
private def renderCaptureArrow(using q: Quotes)(refs: Option[List[reflect.TypeRepr]], isImplicitFun: Boolean, skipThisTypePrefix: Boolean)(
512519
using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol
513520
): SSignature =
514-
import reflect.*
521+
import reflect._
522+
val prefix = if isImplicitFun then "?" else ""
515523
refs match
516-
case None => List(Keyword("=>")) // FIXME: is this correct? or should it be `->` by default?
517-
case Some(refs) => renderCaptureArrow(using q)(refs, skipThisTypePrefix)
524+
case None => List(Keyword(prefix + "->")) // FIXME need to check if cc is enabled in current file first!!!
525+
case Some(refs) => renderCaptureArrow(using q)(refs, isImplicitFun, skipThisTypePrefix)

0 commit comments

Comments
 (0)