Skip to content

Commit eb9952e

Browse files
committed
Only pretty-print variance where it would be legal in code
1 parent 5aac2dc commit eb9952e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ object NameOps {
124124
name.rewrite { case ExpandedName(_, unexp) => unexp }
125125
}
126126

127+
/** Remove the variance from the name. */
128+
def invariantName: N = likeSpaced {
129+
name.rewrite { case VariantName(invariant, _) => invariant }
130+
}
131+
127132
def implClassName: N = likeSpaced(name ++ tpnme.IMPL_CLASS_SUFFIX)
128133

129134
def errorName: N = likeSpaced(name ++ nme.ERROR)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
635635
if (tree.exists(!_.isEmpty)) encl(blockText(tree)) else ""
636636

637637
override protected def ParamRefNameString(name: Name): String =
638-
name.unexpandedName.toString
638+
name.unexpandedName.invariantName.toString
639639

640640
override protected def treatAsTypeParam(sym: Symbol): Boolean = sym is TypeParam
641641

tests/repl/names.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
scala> case class Foo[M[_]](x: M[Int])
22
defined class Foo
33
scala> Foo(Option(1))
4-
val res0: Foo[[+A] => Option[+A]] = Foo(Some(1))
4+
val res0: Foo[[+A] => Option[A]] = Foo(Some(1))
55
scala> :quit

0 commit comments

Comments
 (0)