@@ -115,9 +115,9 @@ trait TypesSupport:
115
115
++ keyword(" & " ).l
116
116
++ inParens(inner(right), shouldWrapInParens(right, tp, false ))
117
117
case ByNameType (CapturingType (tpe, refs)) =>
118
- renderFunctionArrow (using qctx)(refs, true , false ) ++ (plain(" " ) :: inner(tpe))
118
+ renderByNameArrow (using qctx)(Some ( refs) ) ++ (plain(" " ) :: inner(tpe))
119
119
case ByNameType (tpe) =>
120
- ( if ccEnabled then keyword( " -> " ) else keyword( " => " )) :: inner(tpe)
120
+ renderByNameArrow( using qctx)( None ) ++ (plain( " " ) :: inner(tpe) )
121
121
case ConstantType (constant) =>
122
122
plain(constant.show).l
123
123
case ThisType (tpe) =>
@@ -132,7 +132,7 @@ trait TypesSupport:
132
132
inner(tpe) :+ plain(" *" )
133
133
case CapturingType (base, refs) => base match
134
134
case t @ AppliedType (base, args) if t.isFunctionType =>
135
- functionType(t, base, args)(using inCC = Some (refs))
135
+ functionType(base, args)(using inCC = Some (refs))
136
136
case _ => inner(base) ++ renderCapturing(refs)
137
137
case AnnotatedType (tpe, _) =>
138
138
inner(tpe)
@@ -248,7 +248,7 @@ trait TypesSupport:
248
248
++ inParens(inner(rhs), shouldWrapInParens(rhs, t, false ))
249
249
250
250
case t @ AppliedType (tpe, args) if t.isFunctionType =>
251
- functionType(t, tpe, args)
251
+ functionType(tpe, args)
252
252
253
253
case t @ AppliedType (tpe, typeList) =>
254
254
inner(tpe) ++ plain(" [" ).l ++ commas(typeList.map { t => t match
@@ -334,19 +334,14 @@ trait TypesSupport:
334
334
s " ${tpe.show(using Printer .TypeReprStructure )}"
335
335
throw MatchError (msg)
336
336
337
- private def functionType (using qctx : Quotes )(t : reflect. TypeRepr , tpe : reflect.TypeRepr , args : List [reflect.TypeRepr ])(using
337
+ private def functionType (using qctx : Quotes )(funTy : reflect.TypeRepr , args : List [reflect.TypeRepr ])(using
338
338
elideThis : reflect.ClassDef ,
339
339
indent : Int ,
340
340
skipTypeSuffix : Boolean ,
341
341
inCC : Option [List [reflect.TypeRepr ]],
342
342
): SSignature =
343
343
import reflect ._
344
- val refs = if ! inCC.isDefined && t.isContextFunctionType then
345
- // This'll ensure that an impure context function type is rendered correctly
346
- Some (List (CaptureDefs .captureRoot.termRef))
347
- else
348
- inCC
349
- val arrow = plain(" " ) :: (renderFunctionArrow(using qctx)(refs, t.isFunction1, t.isContextFunctionType) ++ plain(" " ).l)
344
+ val arrow = plain(" " ) :: (renderFunctionArrow(using qctx)(funTy, inCC) ++ plain(" " ).l)
350
345
given Option [List [TypeRepr ]] = None // FIXME: this is ugly
351
346
args match
352
347
case Nil => Nil
@@ -485,23 +480,29 @@ trait TypesSupport:
485
480
import reflect ._
486
481
Keyword (" ^" ) :: renderCaptureSet(refs)
487
482
488
- private def renderFunctionArrow (using Quotes )(refs : List [reflect.TypeRepr ], isPureFun : Boolean , isImplicitFun : Boolean )(using elideThis : reflect.ClassDef ): SSignature =
489
- import reflect ._
490
- val prefix = if isImplicitFun then " ?" else " "
491
- if ! ccEnabled then
492
- List (Keyword (prefix + " =>" ))
493
- else
494
- refs match
495
- case Nil => if isPureFun then List (Keyword (prefix + " ->" )) else List (Keyword (prefix + " =>" ))
496
- case List (ref) if ref.isCaptureRoot => List (Keyword (prefix + " =>" ))
497
- case refs => Keyword (prefix + " ->" ) :: renderCaptureSet(refs)
498
-
499
- private def renderFunctionArrow (using qctx : Quotes )(refs : Option [List [reflect.TypeRepr ]], isPureFun : Boolean , isImplicitFun : Boolean )(using elideThis : reflect.ClassDef ): SSignature =
483
+ private def renderFunctionArrow (using Quotes )(funTy : reflect.TypeRepr , captures : Option [List [reflect.TypeRepr ]])(using elideThis : reflect.ClassDef ): SSignature =
500
484
import reflect ._
501
- val prefix = if isImplicitFun then " ?" else " "
485
+ val isContextFun = funTy.isAnyContextFunction || funTy.isAnyImpureContextFunction
486
+ val prefix = if isContextFun then " ?" else " "
502
487
if ! ccEnabled then
503
488
List (Keyword (prefix + " =>" ))
504
489
else
505
- refs match
506
- case None => if isPureFun then List (Keyword (prefix + " ->" )) else List (Keyword (prefix + " =>" ))
507
- case Some (refs) => renderFunctionArrow(using qctx)(refs, isPureFun, isImplicitFun)
490
+ val isPureFun = funTy.isAnyFunction || funTy.isAnyContextFunction
491
+ val isImpureFun = funTy.isAnyImpureFunction || funTy.isAnyImpureContextFunction
492
+ captures match
493
+ case None => // means an explicit retains* annotation is missing
494
+ if isPureFun then
495
+ List (Keyword (prefix + " ->" ))
496
+ else if isImpureFun then
497
+ List (Keyword (prefix + " =>" ))
498
+ else
499
+ report.error(s " Cannot render function arrow: expected a (Context)Function* or Impure(Context)Function*, but got: ${funTy.show}" )
500
+ Nil
501
+ case Some (refs) => // there is some capture set
502
+ refs match
503
+ case Nil => List (Keyword (prefix + " ->" ))
504
+ case List (ref) if ref.isCaptureRoot => List (Keyword (prefix + " =>" ))
505
+ case refs => Keyword (prefix + " ->" ) :: renderCaptureSet(refs)
506
+
507
+ private def renderByNameArrow (using Quotes )(captures : Option [List [reflect.TypeRepr ]])(using elideThis : reflect.ClassDef ): SSignature =
508
+ renderFunctionArrow(CaptureDefs .Function1 .typeRef, captures)
0 commit comments