@@ -124,9 +124,9 @@ trait TypesSupport:
124
124
++ keyword(" & " ).l
125
125
++ inParens(inner(right, skipThisTypePrefix), shouldWrapInParens(right, tp, false ))
126
126
case ByNameType (CapturingType (tpe, refs)) =>
127
- renderFunctionArrow (using q)(refs, FunKind ( true , false ), skipThisTypePrefix) ++ (plain(" " ) :: inner(tpe, skipThisTypePrefix))
127
+ renderByNameArrow (using q)(Some (refs ), skipThisTypePrefix) ++ (plain(" " ) :: inner(tpe, skipThisTypePrefix))
128
128
case ByNameType (tpe) =>
129
- ( if ccEnabled then keyword( " -> " ) else keyword( " => " )) :: inner(tpe, skipThisTypePrefix)
129
+ renderByNameArrow( using q)( None , skipThisTypePrefix) ++ (plain( " " ) :: inner(tpe, skipThisTypePrefix) )
130
130
case ConstantType (constant) =>
131
131
plain(constant.show).l
132
132
case ThisType (tpe) =>
@@ -139,7 +139,7 @@ trait TypesSupport:
139
139
inner(tpe, skipThisTypePrefix) :+ plain(" *" )
140
140
case CapturingType (base, refs) => base match
141
141
case t @ AppliedType (base, args) if t.isFunctionType =>
142
- functionType(t, base, args, skipThisTypePrefix)(using inCC = Some (refs))
142
+ functionType(base, args, skipThisTypePrefix)(using inCC = Some (refs))
143
143
case _ => inner(base, skipThisTypePrefix) ++ renderCapturing(refs, skipThisTypePrefix)
144
144
case AnnotatedType (tpe, _) =>
145
145
inner(tpe, skipThisTypePrefix)
@@ -258,7 +258,7 @@ trait TypesSupport:
258
258
++ inParens(inner(rhs, skipThisTypePrefix), shouldWrapInParens(rhs, t, false ))
259
259
260
260
case t @ AppliedType (tpe, args) if t.isFunctionType =>
261
- functionType(t, tpe, args, skipThisTypePrefix)
261
+ functionType(tpe, args, skipThisTypePrefix)
262
262
263
263
case t @ AppliedType (tpe, typeList) =>
264
264
inner(tpe, skipThisTypePrefix) ++ plain(" [" ).l ++ commas(typeList.map { t => t match
@@ -346,19 +346,14 @@ trait TypesSupport:
346
346
s " ${tpe.show(using Printer .TypeReprStructure )}"
347
347
throw MatchError (msg)
348
348
349
- private def functionType (using q : Quotes )(t : reflect. TypeRepr , tpe : reflect.TypeRepr , args : List [reflect.TypeRepr ], skipThisTypePrefix : Boolean )(using
349
+ private def functionType (using q : Quotes )(funTy : reflect.TypeRepr , args : List [reflect.TypeRepr ], skipThisTypePrefix : Boolean )(using
350
350
elideThis : reflect.ClassDef ,
351
351
indent : Int ,
352
352
originalOwner : reflect.Symbol ,
353
353
inCC : Option [List [reflect.TypeRepr ]],
354
354
): SSignature =
355
355
import reflect ._
356
- val refs = if ! inCC.isDefined && t.isContextFunctionType then
357
- // This'll ensure that an impure context function type is rendered correctly
358
- Some (List (CaptureDefs .captureRoot.termRef))
359
- else
360
- inCC
361
- val arrow = plain(" " ) :: (renderFunctionArrow(using q)(refs, FunKind (isPure = t.isFunction1, isImplicit = t.isContextFunctionType), skipThisTypePrefix) ++ plain(" " ).l)
356
+ val arrow = plain(" " ) :: (renderFunctionArrow(using q)(funTy, inCC, skipThisTypePrefix) ++ plain(" " ).l)
362
357
given Option [List [TypeRepr ]] = None // FIXME: this is ugly
363
358
args match
364
359
case Nil => Nil
@@ -507,27 +502,33 @@ trait TypesSupport:
507
502
import reflect ._
508
503
Keyword (" ^" ) :: renderCaptureSet(refs, skipThisTypePrefix)
509
504
510
- private def renderFunctionArrow (using q : Quotes )(refs : List [ reflect.TypeRepr ], fun : FunKind , skipThisTypePrefix : Boolean )(
505
+ private def renderFunctionArrow (using q : Quotes )(funTy : reflect.TypeRepr , captures : Option [ List [reflect. TypeRepr ]] , skipThisTypePrefix : Boolean )(
511
506
using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol
512
507
): SSignature =
513
508
import reflect ._
514
- val prefix = if fun.isImplicit then " ?" else " "
509
+ val isContextFun = funTy.isAnyContextFunction || funTy.isAnyImpureContextFunction
510
+ val prefix = if isContextFun then " ?" else " "
515
511
if ! ccEnabled then
516
512
List (Keyword (prefix + " =>" ))
517
513
else
518
- refs match
519
- case Nil => if fun.isPure then List (Keyword (prefix + " ->" )) else List (Keyword (prefix + " =>" ))
520
- case List (ref) if ref.isCaptureRoot => List (Keyword (prefix + " =>" ))
521
- case refs => Keyword (prefix + " ->" ) :: renderCaptureSet(using q)(refs, skipThisTypePrefix)
522
-
523
- private def renderFunctionArrow (using q : Quotes )(refs : Option [List [reflect.TypeRepr ]], fun : FunKind , skipThisTypePrefix : Boolean )(
514
+ val isPureFun = funTy.isAnyFunction || funTy.isAnyContextFunction
515
+ val isImpureFun = funTy.isAnyImpureFunction || funTy.isAnyImpureContextFunction
516
+ captures match
517
+ case None => // means an explicit retains* annotation is missing
518
+ if isPureFun then
519
+ List (Keyword (prefix + " ->" ))
520
+ else if isImpureFun then
521
+ List (Keyword (prefix + " =>" ))
522
+ else
523
+ report.error(s " Cannot render function arrow: expected a (Context)Function* or Impure(Context)Function*, but got: ${funTy.show}" )
524
+ Nil
525
+ case Some (refs) => // there is some capture set
526
+ refs match
527
+ case Nil => List (Keyword (prefix + " ->" ))
528
+ case List (ref) if ref.isCaptureRoot => List (Keyword (prefix + " =>" ))
529
+ case refs => Keyword (prefix + " ->" ) :: renderCaptureSet(using q)(refs, skipThisTypePrefix)
530
+
531
+ private def renderByNameArrow (using q : Quotes )(captures : Option [List [reflect.TypeRepr ]], skipThisTypePrefix : Boolean )(
524
532
using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol
525
533
): SSignature =
526
- import reflect ._
527
- val prefix = if fun.isImplicit then " ?" else " "
528
- if ! ccEnabled then
529
- List (Keyword (prefix + " =>" ))
530
- else
531
- refs match
532
- case None => if fun.isPure then List (Keyword (prefix + " ->" )) else List (Keyword (prefix + " =>" ))
533
- case Some (refs) => renderFunctionArrow(using q)(refs, fun, skipThisTypePrefix)
534
+ renderFunctionArrow(using q)(CaptureDefs .Function1 .typeRef, captures, skipThisTypePrefix)
0 commit comments