aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing/RefinedPrinter.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-03 18:39:48 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-03 18:39:48 +0100
commitbbf09538e1248ea8907e34633ca5235c88533c97 (patch)
treef5ceaa8a10f586534399c5b6f930338d98b881ff /src/dotty/tools/dotc/printing/RefinedPrinter.scala
parent2023b940f0ec91705d9fd8017fa08d59aa11ac99 (diff)
downloaddotty-bbf09538e1248ea8907e34633ca5235c88533c97.tar.gz
dotty-bbf09538e1248ea8907e34633ca5235c88533c97.tar.bz2
dotty-bbf09538e1248ea8907e34633ca5235c88533c97.zip
Fix printing of wildcard types.
Diffstat (limited to 'src/dotty/tools/dotc/printing/RefinedPrinter.scala')
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index cda753d3a..2afe074b0 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -77,6 +77,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}
override def toText(tp: Type): Text = controlled {
+ def argText(arg: Type): Text = arg match {
+ case arg: TypeBounds => "_" ~ toTextGlobal(arg)
+ case _ => toTextGlobal(arg)
+ }
def toTextTuple(args: List[Type]): Text =
"(" ~ toTextGlobal(args, ", ") ~ ")"
def toTextFunction(args: List[Type]): Text =
@@ -91,7 +95,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
tp match {
case tp: RefinedType =>
val args = tp.typeArgs
- if (args.nonEmpty && (args forall (_.exists))) {
+ if (args.nonEmpty) {
val tycon = tp.unrefine
val cls = tycon.typeSymbol
if (cls.typeParams.length == args.length) {
@@ -99,7 +103,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (defn.FunctionClasses contains cls) return toTextFunction(args)
if (defn.TupleClasses contains cls) return toTextTuple(args)
}
- return (toTextLocal(tycon) ~ "[" ~ toTextGlobal(args, ", ") ~ "]").close
+ return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close
}
case tp @ TypeRef(pre, name) =>
if (tp.symbol is TypeParam | TypeArgument) {
@@ -161,6 +165,16 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
Text(mods.annotations.map(annotText), " ") ~~ modsText ~~ (kw provided !suppressKw)
}
+ def argText(arg: Tree[T]): Text = arg match {
+ case arg: TypeBoundsTree[_] => "_" ~ toTextGlobal(arg)
+ case arg: TypeTree[_] =>
+ arg.typeOpt match {
+ case tp: TypeBounds => "_" ~ toTextGlobal(arg)
+ case _ => toTextGlobal(arg)
+ }
+ case _ => toTextGlobal(arg)
+ }
+
import untpd._
var txt: Text = tree match {
@@ -232,7 +246,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case RefinedTypeTree(tpt, refines) =>
toTextLocal(tpt) ~ " " ~ blockText(refines)
case AppliedTypeTree(tpt, args) =>
- toTextLocal(tpt) ~ "[" ~ toTextGlobal(args, ", ") ~ "]"
+ toTextLocal(tpt) ~ "[" ~ Text(args map argText, ", ") ~ "]"
case TypeBoundsTree(lo, hi) =>
optText(lo)(" >: " ~ _) ~ optText(hi)(" <: " ~ _)
case Bind(name, body) =>