Skip to content

Commit 2095471

Browse files
bracevacnatsukagami
authored andcommitted
Fix rendering of dependent function types
1 parent dc786ba commit 2095471

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

local/project/dummy/arrows.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,18 @@ trait Arrows:
5959
def contextPure(f: AnyRef^{a} ?-> Int): Int
6060
def contextImpure(f: AnyRef^{a} ?=> Int): Int
6161
def contextImpure2(f: AnyRef^{a} ?->{b,c} Int): Int
62-
def contextImpure3(f: AnyRef^{a} ?->{b,c} Int => AnyRef^{a} ?=> Int): Int
62+
def contextImpure3(f: AnyRef^{a} ?->{b,c} Int => AnyRef^{a} ?=> Int): Int
63+
64+
val noParams: () -> () -> Int
65+
val noParams2: () ->{} () ->{} Int
66+
val noParamsImpure: () => () => Int => Unit
67+
68+
val uncurried: (x: AnyRef^, y: AnyRef^) -> AnyRef^{x,y} => Int ->{x,y} Int
69+
val uncurried2: (x: AnyRef^, y: AnyRef^) -> AnyRef => Int ->{x,y} Int
70+
val uncurried3: (x: AnyRef^, y: AnyRef^) => AnyRef
71+
val uncurried4: (x: AnyRef^, y: AnyRef^) ->{a,b} AnyRef^ => Int ->{x,y} Int
72+
73+
val contextUncurried: (x: AnyRef^{a}, y: AnyRef^{b}) ?-> AnyRef^{x,y} ?-> Int ?->{x,y} Int
74+
val contextUncurried2: (x: AnyRef^{a}, y: AnyRef^{b}) ?-> AnyRef ?-> Int ?->{x,y} Int
75+
val contextUncurried3: (x: AnyRef^{a}, y: AnyRef^{b}) ?=> AnyRef
76+
val contextUncurried4: (x: AnyRef^{a}, y: AnyRef^{b}) ?->{a,b} AnyRef^ ?=> Int ?->{x,y} Int

local/project/dummy/nocc.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ trait NoCaptureChecking:
44
def byName(f: => Int): Int
55
def impure(f: Int => Int): Int
66
def context(f: Int ?=> Int): Int
7+
def dependent(f: (x: Int) => x.type): Int

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ trait TypesSupport:
140140
case CapturingType(base, refs) => base match
141141
case t @ AppliedType(base, args) if t.isFunctionType =>
142142
functionType(base, args, skipThisTypePrefix)(using inCC = Some(refs))
143+
case t : Refinement if t.isFunctionType =>
144+
inner(base, skipThisTypePrefix)(using inCC = Some(refs))
143145
case _ => inner(base, skipThisTypePrefix) ++ renderCapturing(refs, skipThisTypePrefix)
144146
case AnnotatedType(tpe, _) =>
145147
inner(tpe, skipThisTypePrefix)
@@ -213,12 +215,19 @@ trait TypesSupport:
213215
val isCtx = isContextualMethod(m)
214216
if isDependentMethod(m) then
215217
val paramList = getParamList(m)
216-
val arrow = keyword(if isCtx then " ?=> " else " => ").l
217-
val resType = inner(m.resType, skipThisTypePrefix)
218-
paramList ++ arrow ++ resType
218+
val arrPrefix = if isCtx then "?" else ""
219+
val arrow =
220+
if ccEnabled then
221+
inCC match
222+
case None | Some(Nil) => keyword(arrPrefix + "->").l
223+
case Some(List(c)) if c.isCaptureRoot => keyword(arrPrefix + "=>").l
224+
case Some(refs) => keyword(arrPrefix + "->") :: renderCaptureSet(refs, skipThisTypePrefix)
225+
else keyword(arrPrefix + "=>").l
226+
val resType = inner(m.resType, skipThisTypePrefix)(using inCC = None)
227+
paramList ++ (plain(" ") :: arrow) ++ (plain(" ") :: resType)
219228
else
220229
val sym = defn.FunctionClass(m.paramTypes.length, isCtx)
221-
inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType), skipThisTypePrefix)
230+
inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType), skipThisTypePrefix)(using inCC = None)
222231
case other => noSupported("Dependent function type without MethodType refinement")
223232
}
224233

@@ -523,13 +532,14 @@ trait TypesSupport:
523532
else
524533
report.error(s"Cannot render function arrow: expected a (Context)Function* or Impure(Context)Function*, but got: ${funTy.show}")
525534
Nil
526-
case Some(refs) => // there is some capture set
535+
case Some(refs) =>
536+
// there is some capture set
527537
refs match
528538
case Nil => List(Keyword(prefix + "->"))
529539
case List(ref) if ref.isCaptureRoot => List(Keyword(prefix + "=>"))
530540
case refs => Keyword(prefix + "->") :: renderCaptureSet(using q)(refs, skipThisTypePrefix)
531541

532-
private def renderByNameArrow(using q: Quotes)(captures: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(
542+
private def renderByNameArrow(using Quotes)(captures: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(
533543
using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol
534544
): SSignature =
535-
renderFunctionArrow(using q)(CaptureDefs.Function1.typeRef, captures, skipThisTypePrefix)
545+
renderFunctionArrow(CaptureDefs.Function1.typeRef, captures, skipThisTypePrefix)

0 commit comments

Comments
 (0)