@@ -4,9 +4,10 @@ package tasty
44import scala .jdk .CollectionConverters ._
55
66import scala .quoted ._
7+ import scala .annotation .*
78
8- import NameNormalizer ._
9- import SyntheticsSupport ._
9+ import NameNormalizer .*
10+ import SyntheticsSupport .*
1011
1112trait TypesSupport :
1213 self : TastyParser =>
@@ -141,24 +142,24 @@ trait TypesSupport:
141142 .reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
142143 ++ plain(" )" ).l
143144
144- def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature = ( info match {
145+ def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature =
146+ val ssig = info match
145147 case m : MethodType => {
146148 val paramList = getParamList(m)
147149 keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType)
148150 }
149- case t : PolyType => {
151+ case t : PolyType =>
150152 val paramBounds = getParamBounds(t)
151- val parsedMethod = parseRefinedElem(name, t.resType)
152- if (! paramBounds.isEmpty){
153+ if ! paramBounds.isEmpty then
153154 parseRefinedElem(name, t.resType, plain(" [" ).l ++ paramBounds ++ plain(" ]" ).l)
154- } else parseRefinedElem(name, t.resType)
155- }
155+ else parseRefinedElem(name, t.resType, polyTyped = Nil )
156156 case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp)
157157 case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t)
158158 case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t)
159159 case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t)
160160 case other => noSupported(s " Not supported type in refinement $info" )
161- } ) ++ plain(" ; " ).l
161+
162+ ssig ++ plain(" ; " ).l
162163
163164 def parsePolyFunction (info : TypeRepr ): SSignature = info match {
164165 case t : PolyType =>
@@ -225,6 +226,7 @@ trait TypesSupport:
225226 }) ++ plain(" ]" ).l
226227
227228 case tp @ TypeRef (qual, typeName) =>
229+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
228230 qual match {
229231 case r : RecursiveThis => tpe(s " this. $typeName" ).l
230232 case t if skipPrefix(t, elideThis) =>
@@ -245,17 +247,17 @@ trait TypesSupport:
245247 case _ => tpe(tp.typeSymbol)
246248 case Some (_) => tpe(tp.typeSymbol)
247249 case None =>
248- val sig = inParens(inner(qual)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
250+ val sig = inParens(inner(qual)(using indent = indent, skipTypeSuffix = true ), wrapping )
249251 sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
250252 case _ =>
251- val sig = inParens(inner(qual), shouldWrapInParens(qual, tp, true ) )
253+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
252254 sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
253255 }
254256
255257 case tr @ TermRef (qual, typeName) =>
256258 val prefix = qual match
257259 case t if skipPrefix(t, elideThis) => Nil
258- case tp => inner(tp)(using skipTypeSuffix = true ) ++ plain(" ." ).l
260+ case tp => inner(tp)(using indent = indent, skipTypeSuffix = true ) ++ plain(" ." ).l
259261 val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
260262 val typeSig = tr.termSymbol.tree match
261263 case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -274,9 +276,9 @@ trait TypesSupport:
274276 val spaces = " " * (indent)
275277 val casesTexts = cases.flatMap {
276278 case MatchCase (from, to) =>
277- keyword(caseSpaces + " case " ).l ++ inner(from) ++ keyword(" => " ).l ++ inner(to)(using indent = indent + 2 ) ++ plain(" \n " ).l
279+ keyword(caseSpaces + " case " ).l ++ inner(from) ++ keyword(" => " ).l ++ inner(to)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix ) ++ plain(" \n " ).l
278280 case TypeLambda (_, _, MatchCase (from, to)) =>
279- keyword(caseSpaces + " case " ).l ++ inner(from) ++ keyword(" => " ).l ++ inner(to)(using indent = indent + 2 ) ++ plain(" \n " ).l
281+ keyword(caseSpaces + " case " ).l ++ inner(from) ++ keyword(" => " ).l ++ inner(to)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix ) ++ plain(" \n " ).l
280282 }
281283 inner(sc) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
282284
0 commit comments