Skip to content

Commit 882b141

Browse files
committed
Pretty-print LambdaParams
Customized printer instead of falling back to toString
1 parent 09b06ef commit 882b141

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4039,7 +4039,7 @@ object Types {
40394039
// ----- Type application: LambdaParam, AppliedType ---------------------
40404040

40414041
/** The parameter of a type lambda */
4042-
case class LambdaParam(tl: TypeLambda, n: Int) extends ParamInfo {
4042+
case class LambdaParam(tl: TypeLambda, n: Int) extends ParamInfo, printing.Showable {
40434043
type ThisName = TypeName
40444044

40454045
def isTypeParam(using Context): Boolean = tl.paramNames.head.isTypeName
@@ -4084,6 +4084,8 @@ object Types {
40844084
case _ =>
40854085
myVariance = Invariant
40864086
myVariance
4087+
4088+
def toText(printer: Printer): Text = printer.toText(this)
40874089
}
40884090

40894091
/** A type application `C[T_1, ..., T_n]` */

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ class PlainPrinter(_ctx: Context) extends Printer {
540540

541541
def toText(annot: Annotation): Text = s"@${annot.symbol.name}" // for now
542542

543+
def toText(param: LambdaParam): Text =
544+
varianceSign(param.paramVariance)
545+
~ toText(param.paramName)
546+
~ (if param.isTypeParam then "" else ": ")
547+
~ toText(param.paramInfo)
548+
543549
protected def escapedString(str: String): String = str flatMap escapedChar
544550

545551
def dclsText(syms: List[Symbol], sep: String): Text = Text(syms map dclText, sep)

compiler/src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ package printing
44

55
import core._
66
import Texts._, ast.Trees._
7-
import Types.{Type, SingletonType}, Symbols.Symbol, Scopes.Scope, Constants.Constant,
7+
import Types.{Type, SingletonType, LambdaParam},
8+
Symbols.Symbol, Scopes.Scope, Constants.Constant,
89
Names.Name, Denotations._, Annotations.Annotation
910
import typer.Implicits.SearchResult
1011
import util.SourcePosition
@@ -130,6 +131,9 @@ abstract class Printer {
130131
/** Textual representation of type */
131132
def toText(tp: Type): Text
132133

134+
/** Textual representation of lambda param */
135+
def toText(tree: LambdaParam): Text
136+
133137
/** Textual representation of all symbols in given list,
134138
* using `dclText` for displaying each.
135139
*/

0 commit comments

Comments
 (0)