@@ -192,13 +192,20 @@ trait Printers
192192 this += " TypeBoundsTree(" += lo += " , " += hi += " )"
193193 case SyntheticBounds () =>
194194 this += s " SyntheticBounds() "
195+ case TypeTree .MatchType (bound, selector, cases) =>
196+ this += " TypeTree.MatchType(" += bound += " , " += selector += " , " ++= cases += " )"
195197 }
196198
197199 def visitCaseDef (x : CaseDef ): Buffer = {
198200 val CaseDef (pat, guard, body) = x
199201 this += " CaseDef(" += pat += " , " += guard += " , " += body += " )"
200202 }
201203
204+ def visitTypeCaseDef (x : TypeCaseDef ): Buffer = {
205+ val TypeCaseDef (pat, body) = x
206+ this += " TypeCaseDef(" += pat += " , " += body += " )"
207+ }
208+
202209 def visitPattern (x : Pattern ): Buffer = x match {
203210 case Pattern .Value (v) =>
204211 this += " Pattern.Value(" += v += " )"
@@ -252,6 +259,8 @@ trait Printers
252259 this += " Type.AndType(" += left += " , " += right += " )"
253260 case Type .OrType (left, right) =>
254261 this += " Type.OrType(" += left += " , " += right += " )"
262+ case Type .MatchType (bound, scrutinee, cases) =>
263+ this += " Type.MatchType(" += bound += " , " += scrutinee += " , " ++= cases += " )"
255264 case Type .ByNameType (underlying) =>
256265 this += " Type.ByNameType(" += underlying += " )"
257266 case Type .ParamRef (binder, idx) =>
@@ -326,6 +335,11 @@ trait Printers
326335 def ++= (x : List [CaseDef ]): Buffer = { visitList(x, visitCaseDef); buff }
327336 }
328337
338+ private implicit class TypeCaseDefOps (buff : Buffer ) {
339+ def += (x : TypeCaseDef ): Buffer = { visitTypeCaseDef(x); buff }
340+ def ++= (x : List [TypeCaseDef ]): Buffer = { visitList(x, visitTypeCaseDef); buff }
341+ }
342+
329343 private implicit class PatternOps (buff : Buffer ) {
330344 def += (x : Pattern ): Buffer = { visitPattern(x); buff }
331345 def ++= (x : List [Pattern ]): Buffer = { visitList(x, visitPattern); buff }
@@ -871,6 +885,19 @@ trait Printers
871885 this
872886 }
873887
888+ def printTypes (trees : List [Type ], sep : String ): Buffer = {
889+ def printSeparated (list : List [Type ]): Unit = list match {
890+ case Nil =>
891+ case x :: Nil => printType(x)
892+ case x :: xs =>
893+ printType(x)
894+ this += sep
895+ printSeparated(xs)
896+ }
897+ printSeparated(trees)
898+ this
899+ }
900+
874901 def printImportSelectors (selectors : List [ImportSelector ]): Buffer = {
875902 def printSeparated (list : List [ImportSelector ]): Unit = list match {
876903 case Nil =>
@@ -898,6 +925,19 @@ trait Printers
898925 this
899926 }
900927
928+ def printTypeCases (cases : List [TypeCaseDef ], sep : String ): Buffer = {
929+ def printSeparated (list : List [TypeCaseDef ]): Unit = list match {
930+ case Nil =>
931+ case x :: Nil => printTypeCaseDef(x)
932+ case x :: xs =>
933+ printTypeCaseDef(x)
934+ this += sep
935+ printSeparated(xs)
936+ }
937+ printSeparated(cases)
938+ this
939+ }
940+
901941 def printPatterns (cases : List [Pattern ], sep : String ): Buffer = {
902942 def printSeparated (list : List [Pattern ]): Unit = list match {
903943 case Nil =>
@@ -976,6 +1016,12 @@ trait Printers
9761016 }
9771017 inSquare(printSeparated(tparams))
9781018 if (isMember) {
1019+ body match {
1020+ case TypeTree .MatchType (Some (bound), _, _) =>
1021+ this += " <: "
1022+ printTypeTree(bound)
1023+ case _ =>
1024+ }
9791025 this += " = "
9801026 printTypeOrBoundsTree(body)
9811027 }
@@ -1067,6 +1113,14 @@ trait Printers
10671113 this
10681114 }
10691115
1116+ def printTypeCaseDef (caseDef : TypeCaseDef ): Buffer = {
1117+ this += highlightValDef(" case " , color)
1118+ printTypeTree(caseDef.pattern)
1119+ this += highlightValDef(" => " , color)
1120+ printTypeTree(caseDef.rhs)
1121+ this
1122+ }
1123+
10701124 def printPattern (pattern : Pattern ): Buffer = pattern match {
10711125 case Pattern .Value (v) =>
10721126 v match {
@@ -1201,6 +1255,11 @@ trait Printers
12011255 this += highlightTypeDef(" | " , color)
12021256 printTypeTree(right)
12031257
1258+ case TypeTree .MatchType (bound, selector, cases) =>
1259+ printTypeTree(selector)
1260+ this += highlightKeyword(" match " , color)
1261+ inBlock(printTypeCases(cases, lineBreak()))
1262+
12041263 case TypeTree .ByName (result) =>
12051264 this += highlightTypeDef(" => " , color)
12061265 printTypeTree(result)
@@ -1300,6 +1359,11 @@ trait Printers
13001359 this += highlightTypeDef(" | " , color)
13011360 printType(right)
13021361
1362+ case Type .MatchType (bound, scrutinee, cases) =>
1363+ printType(scrutinee)
1364+ this += highlightKeyword(" match " , color)
1365+ inBlock(printTypes(cases, lineBreak()))
1366+
13031367 case Type .ByNameType (tp) =>
13041368 this += highlightTypeDef(" => " , color)
13051369 printType(tp)
@@ -1553,7 +1617,7 @@ trait Printers
15531617 }
15541618 }
15551619
1556- // TODO Provide some of these in scala.tasty.Reflect .scala and implement them using checks on symbols for performance
1620+ // TODO Provide some of these in scala.tasty.Reflection .scala and implement them using checks on symbols for performance
15571621 private object Types {
15581622
15591623 object JavaLangObject {
0 commit comments