Skip to content

Commit c998905

Browse files
committed
Fix rendering of dependent function types
1 parent d771fa0 commit c998905

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
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: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ trait TypesSupport:
133133
case CapturingType(base, refs) => base match
134134
case t @ AppliedType(base, args) if t.isFunctionType =>
135135
functionType(base, args)(using inCC = Some(refs))
136+
case t : Refinement if t.isFunctionType =>
137+
inner(base)(using inCC = Some(refs))
136138
case _ => inner(base) ++ renderCapturing(refs)
137139
case AnnotatedType(tpe, _) =>
138140
inner(tpe)
@@ -203,12 +205,19 @@ trait TypesSupport:
203205
val isCtx = isContextualMethod(m)
204206
if isDependentMethod(m) then
205207
val paramList = getParamList(m)
206-
val arrow = keyword(if isCtx then " ?=> " else " => ").l
207-
val resType = inner(m.resType)
208-
paramList ++ arrow ++ resType
208+
val arrPrefix = if isCtx then "?" else ""
209+
val arrow =
210+
if ccEnabled then
211+
inCC match
212+
case None | Some(Nil) => keyword(arrPrefix + "->").l
213+
case Some(List(c)) if c.isCaptureRoot => keyword(arrPrefix + "=>").l
214+
case Some(refs) => keyword(arrPrefix + "->") :: renderCaptureSet(refs)
215+
else keyword(arrPrefix + "=>").l
216+
val resType = inner(m.resType)(using inCC = None)
217+
paramList ++ (plain(" ") :: arrow) ++ (plain(" ") :: resType)
209218
else
210219
val sym = defn.FunctionClass(m.paramTypes.length, isCtx)
211-
inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType))
220+
inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType))(using inCC = None)
212221
case other => noSupported("Dependent function type without MethodType refinement")
213222
}
214223

@@ -499,11 +508,12 @@ trait TypesSupport:
499508
else
500509
report.error(s"Cannot render function arrow: expected a (Context)Function* or Impure(Context)Function*, but got: ${funTy.show}")
501510
Nil
502-
case Some(refs) => // there is some capture set
511+
case Some(refs) =>
512+
// there is some capture set
503513
refs match
504514
case Nil => List(Keyword(prefix + "->"))
505515
case List(ref) if ref.isCaptureRoot => List(Keyword(prefix + "=>"))
506516
case refs => Keyword(prefix + "->") :: renderCaptureSet(refs)
507517

508518
private def renderByNameArrow(using Quotes)(captures: Option[List[reflect.TypeRepr]])(using elideThis: reflect.ClassDef): SSignature =
509-
renderFunctionArrow(CaptureDefs.Function1.typeRef, captures)
519+
renderFunctionArrow(CaptureDefs.Function1.typeRef, captures)

0 commit comments

Comments
 (0)