@@ -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
)(
@@ -158,24 +157,25 @@ trait TypesSupport:
158
157
.reduceLeftOption((acc : SSignature , elem : SSignature ) => acc ++ plain(" , " ).l ++ elem).getOrElse(List ())
159
158
++ plain(" )" ).l
160
159
161
- def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature = ( info match {
160
+ def parseRefinedElem (name : String , info : TypeRepr , polyTyped : SSignature = Nil ): SSignature =
161
+ val ssig = info match
162
162
case m : MethodType => {
163
163
val paramList = getParamList(m)
164
164
keyword(" def " ).l ++ plain(name).l ++ polyTyped ++ paramList ++ plain(" : " ).l ++ inner(m.resType, skipThisTypePrefix)
165
165
}
166
- case t : PolyType => {
166
+ case t : PolyType =>
167
167
val paramBounds = getParamBounds(t)
168
- val parsedMethod = parseRefinedElem(name, t.resType)
169
- if (! paramBounds.isEmpty){
168
+ if ! paramBounds.isEmpty then
170
169
parseRefinedElem(name, t.resType, plain(" [" ).l ++ paramBounds ++ plain(" ]" ).l)
171
- } else parseRefinedElem(name, t.resType)
172
- }
170
+ else
171
+ parseRefinedElem(name, t.resType, polyTyped = Nil )
173
172
case ByNameType (tp) => keyword(" def " ).l ++ plain(s " $name: " ).l ++ inner(tp, skipThisTypePrefix)
174
173
case t : TypeBounds => keyword(" type " ).l ++ plain(name).l ++ inner(t, skipThisTypePrefix)
175
174
case t : TypeRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
176
175
case t : TermRef => keyword(" val " ).l ++ plain(s " $name: " ).l ++ inner(t, skipThisTypePrefix)
177
176
case other => noSupported(s " Not supported type in refinement $info" )
178
- } ) ++ plain(" ; " ).l
177
+
178
+ ssig ++ plain(" ; " ).l
179
179
180
180
def parsePolyFunction (info : TypeRepr ): SSignature = info match {
181
181
case t : PolyType =>
@@ -256,6 +256,7 @@ trait TypesSupport:
256
256
}) ++ plain(" ]" ).l
257
257
258
258
case tp @ TypeRef (qual, typeName) =>
259
+ inline def wrapping = shouldWrapInParens(inner = qual, outer = tp, isLeft = true )
259
260
qual match {
260
261
case r : RecursiveThis => tpe(s " this. $typeName" ).l
261
262
case ThisType (tr) =>
@@ -272,23 +273,28 @@ trait TypesSupport:
272
273
if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
273
274
tpe(tp.typeSymbol)
274
275
else
275
- val sig = inParens(inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
276
- sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
276
+ val sig = inParens(
277
+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ), wrapping)
278
+ sig
279
+ ++ plain(" ." ).l
280
+ ++ tpe(tp.typeSymbol)
277
281
278
282
case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
279
283
tpe(tp.typeSymbol)
280
284
case _ : TermRef | _ : ParamRef =>
281
285
val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
282
- inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
286
+ inner(qual, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true )
287
+ ++ plain(" ." ).l
288
+ ++ suffix
283
289
case _ =>
284
- val sig = inParens(inner(qual, skipThisTypePrefix), shouldWrapInParens(qual, tp, true ) )
290
+ val sig = inParens(inner(qual, skipThisTypePrefix), wrapping )
285
291
sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
286
292
}
287
293
288
294
case tr @ TermRef (qual, typeName) =>
289
295
val prefix = qual match
290
296
case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) => Nil
291
- case tp => inner(tp, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l
297
+ case tp => inner(tp, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = true ) ++ plain(" ." ).l
292
298
val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
293
299
val typeSig = tr.termSymbol.tree match
294
300
case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -307,9 +313,17 @@ trait TypesSupport:
307
313
val spaces = " " * (indent)
308
314
val casesTexts = cases.flatMap {
309
315
case MatchCase (from, to) =>
310
- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
316
+ keyword(caseSpaces + " case " ).l
317
+ ++ inner(from, skipThisTypePrefix)
318
+ ++ keyword(" => " ).l
319
+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
320
+ ++ plain(" \n " ).l
311
321
case TypeLambda (_, _, MatchCase (from, to)) =>
312
- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
322
+ keyword(caseSpaces + " case " ).l
323
+ ++ inner(from, skipThisTypePrefix)
324
+ ++ keyword(" => " ).l
325
+ ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , skipTypeSuffix = skipTypeSuffix)
326
+ ++ plain(" \n " ).l
313
327
}
314
328
inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
315
329
0 commit comments