@@ -81,7 +81,6 @@ trait TypesSupport:
8181 case tpe => inner(tpe, skipThisTypePrefix)
8282
8383 // TODO #23 add support for all types signatures that make sense
84- @ nowarn(" id=E219" )
8584 private def inner (
8685 using Quotes ,
8786 )(
@@ -156,24 +155,25 @@ trait TypesSupport:
156155 .reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
157156 ++ plain(" )" ).l
158157
159- def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature = ( info match {
158+ def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature =
159+ val ssig = info match
160160 case m : MethodType => {
161161 val paramList = getParamList(m)
162162 keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType, skipThisTypePrefix)
163163 }
164- case t : PolyType => {
164+ case t : PolyType =>
165165 val paramBounds = getParamBounds(t)
166- val parsedMethod = parseRefinedElem(name, t.resType)
167- if (! paramBounds.isEmpty){
166+ if ! paramBounds.isEmpty then
168167 parseRefinedElem(name, t.resType, plain(" [" ).l ++ paramBounds ++ plain(" ]" ).l)
169- } else parseRefinedElem(name, t.resType)
170- }
168+ else
169+ parseRefinedElem(name, t.resType, polyTyped = Nil )
171170 case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp, skipThisTypePrefix)
172171 case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t, skipThisTypePrefix)
173172 case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
174173 case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
175174 case other => noSupported(s " Not supported type in refinement $info" )
176- } ) ++ plain(" ; " ).l
175+
176+ ssig ++ plain(" ; " ).l
177177
178178 def parsePolyFunction (info : TypeRepr ): SSignature = info match {
179179 case t : PolyType =>
@@ -254,6 +254,7 @@ trait TypesSupport:
254254 }) ++ plain(" ]" ).l
255255
256256 case tp @ TypeRef (qual, typeName) =>
257+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
257258 qual match {
258259 case r : RecursiveThis => tpe(s " this. $typeName" ).l
259260 case ThisType (tr) =>
@@ -270,23 +271,28 @@ trait TypesSupport:
270271 if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
271272 tpe(tp.typeSymbol)
272273 else
273- val sig = inParens(inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
274- sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
274+ val sig = inParens(
275+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ), wrapping)
276+ sig
277+ ++ plain(" ." ).l
278+ ++ tpe(tp.typeSymbol)
275279
276280 case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
277281 tpe(tp.typeSymbol)
278282 case _ : TermRef | _ : ParamRef =>
279283 val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
280- inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
284+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true )
285+ ++ plain(" ." ).l
286+ ++ suffix
281287 case _ =>
282- val sig = inParens(inner(qual, skipThisTypePrefix), shouldWrapInParens(qual, tp, true ) )
288+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
283289 sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
284290 }
285291
286292 case tr @ TermRef (qual, typeName) =>
287293 val prefix = qual match
288294 case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) => Nil
289- case tp => inner(tp, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l
295+ case tp => inner(tp, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ) ++ plain(" ." ).l
290296 val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
291297 val typeSig = tr.termSymbol.tree match
292298 case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -305,9 +311,17 @@ trait TypesSupport:
305311 val spaces = " " * (indent)
306312 val casesTexts = cases.flatMap {
307313 case MatchCase (from, to) =>
308- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
314+ keyword(caseSpaces + " case " ).l
315+ ++ inner(from, skipThisTypePrefix)
316+ ++ keyword(" => " ).l
317+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
318+ ++ plain(" \n " ).l
309319 case TypeLambda (_, _, MatchCase (from, to)) =>
310- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
320+ keyword(caseSpaces + " case " ).l
321+ ++ inner(from, skipThisTypePrefix)
322+ ++ keyword(" => " ).l
323+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
324+ ++ plain(" \n " ).l
311325 }
312326 inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
313327
0 commit comments