@@ -81,7 +81,6 @@ trait TypesSupport:
81
81
case tpe => inner(tpe, skipThisTypePrefix)
82
82
83
83
// TODO #23 add support for all types signatures that make sense
84
- @ nowarn(" id=E219" )
85
84
private def inner (
86
85
using Quotes ,
87
86
)(
@@ -156,24 +155,25 @@ trait TypesSupport:
156
155
.reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
157
156
++ plain(" )" ).l
158
157
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
160
160
case m : MethodType => {
161
161
val paramList = getParamList(m)
162
162
keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType, skipThisTypePrefix)
163
163
}
164
- case t : PolyType => {
164
+ case t : PolyType =>
165
165
val paramBounds = getParamBounds(t)
166
- val parsedMethod = parseRefinedElem(name, t.resType)
167
- if (! paramBounds.isEmpty){
166
+ if ! paramBounds.isEmpty then
168
167
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 )
171
170
case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp, skipThisTypePrefix)
172
171
case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t, skipThisTypePrefix)
173
172
case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
174
173
case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
175
174
case other => noSupported(s " Not supported type in refinement $info" )
176
- } ) ++ plain(" ; " ).l
175
+
176
+ ssig ++ plain(" ; " ).l
177
177
178
178
def parsePolyFunction (info : TypeRepr ): SSignature = info match {
179
179
case t : PolyType =>
@@ -254,6 +254,7 @@ trait TypesSupport:
254
254
}) ++ plain(" ]" ).l
255
255
256
256
case tp @ TypeRef (qual, typeName) =>
257
+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
257
258
qual match {
258
259
case r : RecursiveThis => tpe(s " this. $typeName" ).l
259
260
case ThisType (tr) =>
@@ -270,23 +271,28 @@ trait TypesSupport:
270
271
if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
271
272
tpe(tp.typeSymbol)
272
273
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)
275
279
276
280
case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
277
281
tpe(tp.typeSymbol)
278
282
case _ : TermRef | _ : ParamRef =>
279
283
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
281
287
case _ =>
282
- val sig = inParens(inner(qual, skipThisTypePrefix), shouldWrapInParens(qual, tp, true ) )
288
+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
283
289
sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
284
290
}
285
291
286
292
case tr @ TermRef (qual, typeName) =>
287
293
val prefix = qual match
288
294
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
290
296
val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
291
297
val typeSig = tr.termSymbol.tree match
292
298
case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -305,9 +311,17 @@ trait TypesSupport:
305
311
val spaces = " " * (indent)
306
312
val casesTexts = cases.flatMap {
307
313
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
309
319
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
311
325
}
312
326
inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
313
327
0 commit comments