Skip to content

Commit 161b9ee

Browse files
committed
Future-proof paramSymss API
In the future, we might support arbitrary combination of type and term parameter lists, so we shouldn't hardcode the assumption that there is at most one type parameter list. Also removed a debug println.
1 parent eff5496 commit 161b9ee

File tree

8 files changed

+26
-41
lines changed

8 files changed

+26
-41
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,15 @@ object SymDenotations {
386386
final def setParamssFromDefs(tparams: List[TypeDef[?]], vparamss: List[List[ValDef[?]]])(using Context): Unit =
387387
setParamss(tparams.map(_.symbol), vparamss.map(_.map(_.symbol)))
388388

389-
/** A pair consisting of type parameter symbols and value parameter symbol lists
390-
* of this method definition, or (Nil, Nil) for other symbols.
389+
390+
/** The symbols of each type parameter list and value parameter list of this
391+
* method, or Nil if this isn't a method.
392+
*
393+
*
391394
* Makes use of `rawParamss` when present, or constructs fresh parameter symbols otherwise.
392395
* This method can be allocation-heavy.
393396
*/
394-
final def paramSymss(using ctx: Context): (List[TypeSymbol], List[List[TermSymbol]]) =
397+
final def paramSymss(using ctx: Context): List[List[Symbol]] =
395398

396399
def recurWithParamss(info: Type, paramss: List[List[Symbol]]): List[List[Symbol]] =
397400
info match
@@ -412,17 +415,8 @@ object SymDenotations {
412415
case _ =>
413416
Nil
414417

415-
try
416-
val allParamss =
417-
if rawParamss.isEmpty then recurWithoutParamss(info)
418-
else recurWithParamss(info, rawParamss)
419-
val result = info match
420-
case info: PolyType => (allParamss.head, allParamss.tail)
421-
case _ => (Nil, allParamss)
422-
result.asInstanceOf[(List[TypeSymbol], List[List[TermSymbol]])]
423-
catch case NonFatal(ex) =>
424-
println(i"paramSymss failure for $symbol, $info, $rawParamss")
425-
throw ex
418+
if rawParamss.isEmpty then recurWithoutParamss(info)
419+
else recurWithParamss(info, rawParamss)
426420
end paramSymss
427421

428422
/** The denotation is completed: info is not a lazy type and attributes have defined values */

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private class ExtractAPICollector(implicit ctx: Context) extends ThunkHolder {
339339
def apiDef(sym: TermSymbol): api.Def = {
340340
def paramLists(t: Type, paramss: List[List[Symbol]]): List[api.ParameterList] = t match {
341341
case pt: TypeLambda =>
342-
paramLists(pt.resultType, paramss)
342+
paramLists(pt.resultType, paramss.drop(1))
343343
case mt @ MethodTpe(pnames, ptypes, restpe) =>
344344
assert(paramss.nonEmpty && paramss.head.hasSameLengthAs(pnames),
345345
i"mismatch for $sym, ${sym.info}, ${sym.paramSymss}")
@@ -359,7 +359,7 @@ private class ExtractAPICollector(implicit ctx: Context) extends ThunkHolder {
359359
case _ =>
360360
Nil
361361
}
362-
val vparamss = paramLists(sym.info, sym.paramSymss._2)
362+
val vparamss = paramLists(sym.info, sym.paramSymss)
363363
val retTp = sym.info.finalResultType.widenExpr
364364

365365
api.Def.of(sym.name.toString, apiAccess(sym), apiModifiers(sym),

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
17491749
private def isMethod(sym: Symbol)(using ctx: Context): Boolean =
17501750
sym.isTerm && sym.is(Flags.Method) && !sym.isConstructor
17511751

1752-
def Symbol_paramSymss(self: Symbol)(using ctx: Context): (List[Symbol], List[List[Symbol]]) =
1752+
def Symbol_paramSymss(self: Symbol)(using ctx: Context): List[List[Symbol]] =
17531753
self.paramSymss
17541754

17551755
def Symbol_primaryConstructor(self: Symbol)(using Context): Symbol =

library/src/scala/tasty/Reflection.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,10 +2223,10 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
22232223
def methods(using ctx: Context): List[Symbol] =
22242224
internal.Symbol_methods(sym)
22252225

2226-
/** A pair consisting of type parameter symbols and value parameter symbol lists
2227-
* of this method definition, or (Nil, Nil) for other symbols.
2226+
/** The symbols of each type parameter list and value parameter list of this
2227+
* method, or Nil if this isn't a method.
22282228
*/
2229-
def paramSymss(using ctx: Context): (List[Symbol], List[List[Symbol]]) =
2229+
def paramSymss(using ctx: Context): List[List[Symbol]] =
22302230
internal.Symbol_paramSymss(sym)
22312231

22322232
/** The primary constructor of a class or trait, `noSymbol` if not applicable. */

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,10 +1305,10 @@ trait CompilerInterface {
13051305
/** Get all non-private methods declared or inherited */
13061306
def Symbol_methods(self: Symbol)(using ctx: Context): List[Symbol]
13071307

1308-
/** A pair consisting of type parameter symbols and value parameter symbol lists
1309-
* of this method definition, or (Nil, Nil) for other symbols.
1308+
/** The symbols of each type parameter list and value parameter list of this
1309+
* method, or Nil if this isn't a method.
13101310
*/
1311-
def Symbol_paramSymss(self: Symbol)(using ctx: Context): (List[Symbol], List[List[Symbol]])
1311+
def Symbol_paramSymss(self: Symbol)(using ctx: Context): List[List[Symbol]]
13121312

13131313
/** The primary constructor of a class or trait, `noSymbol` if not applicable. */
13141314
def Symbol_primaryConstructor(self: Symbol)(using Context): Symbol

tests/run-macros/paramSymss.check

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
sym: Test$.a
2-
tparams: List()
3-
vparamss: List()
2+
paramSymss: List()
43

54
sym: Test$.b
6-
tparams: List()
7-
vparamss: List(List(Test$._$i))
5+
paramSymss: List(List(Test$._$i))
86

97
sym: Test$.c
10-
tparams: List()
11-
vparamss: List(List(Test$._$x), List(Test$._$y), List(Test$._$z))
8+
paramSymss: List(List(Test$._$x), List(Test$._$y), List(Test$._$z))
129

1310
sym: Test$.d
14-
tparams: List(Test$._$T)
15-
vparamss: List()
11+
paramSymss: List(List(Test$._$T))
1612

1713
sym: Test$.c
18-
tparams: List(Test$._$T, Test$._$U)
19-
vparamss: List(List(Test$._$x, Test$._$x2), List(Test$._$y), List(Test$._$z))
14+
paramSymss: List(List(Test$._$T, Test$._$U), List(Test$._$x, Test$._$x2), List(Test$._$y), List(Test$._$z))
2015

2116
sym: Test.<init>
22-
tparams: List(Test._$T)
23-
vparamss: List(List(Test._$a))
17+
paramSymss: List(List(Test._$T), List(Test._$a))
2418

2519
sym: Test.<init>
26-
tparams: List(Test._$T)
27-
vparamss: List(List(Test._$a, Test._$b))
20+
paramSymss: List(List(Test._$T), List(Test._$a, Test._$b))
2821

tests/run-macros/paramSymss/Macro_1.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ inline def showParamSyms(inline x: Any): String =
66
def showParamSymsExpr(using QuoteContext)(x: Expr[Any]): Expr[String] =
77
val '{ $y: Any } = x // Drop Inlined not to access the symbol
88
val sym = y.unseal.symbol
9-
val (tparams, vparamss) = sym.paramSymss
109
Expr(
1110
s"""sym: ${sym.show}
12-
|tparams: ${tparams.map(_.show)}
13-
|vparamss: ${vparamss.map(_.map(_.show))}
11+
|paramSymss: ${sym.paramSymss.map(_.map(_.show))}
1412
|""".stripMargin)

0 commit comments

Comments
 (0)