Skip to content

Commit 432ceac

Browse files
authored
Merge pull request #3228 from CucumisSativus/show_as_inflix_used_in_refined_printer
Enchancement #3008
2 parents 13799aa + 5d70d1d commit 432ceac

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,8 @@ class Definitions {
661661
def GetterMetaAnnot(implicit ctx: Context) = GetterMetaAnnotType.symbol.asClass
662662
lazy val SetterMetaAnnotType = ctx.requiredClassRef("scala.annotation.meta.setter")
663663
def SetterMetaAnnot(implicit ctx: Context) = SetterMetaAnnotType.symbol.asClass
664+
lazy val ShowAsInfixAnotType = ctx.requiredClassRef("scala.annotation.showAsInfix")
665+
def ShowAsInfixAnnot(implicit ctx: Context) = ShowAsInfixAnotType.symbol.asClass
664666

665667
// convenient one-parameter method types
666668
def methOfAny(tp: Type) = MethodType(List(AnyType), tp)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
126126
def isInfixType(tp: Type): Boolean = tp match {
127127
case AppliedType(tycon, args) =>
128128
args.length == 2 &&
129-
!Character.isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head)
130-
// TODO: Once we use the 2.12 stdlib, also check the @showAsInfix annotation
129+
tycon.typeSymbol.getAnnotation(defn.ShowAsInfixAnnot).map(_.argumentConstant(0).forall(_.booleanValue))
130+
.getOrElse(!Character.isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head))
131131
case _ => false
132132
}
133133

compiler/test-resources/type-printer/infix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ scala> def foo: (Int && String) &: Boolean = ???
1616
def foo: (Int && String) &: Boolean
1717
scala> def foo: Int && (Boolean &: String) = ???
1818
def foo: Int && (Boolean &: String)
19+
scala> import scala.annotation.showAsInfix
20+
scala> @scala.annotation.showAsInfix class Mappy[T,U]
21+
// defined class Mappy
22+
scala> def foo: Int Mappy (Boolean && String) = ???
23+
def foo: Int Mappy (Boolean && String)
24+
scala> @scala.annotation.showAsInfix(false) class ||[T,U]
25+
// defined class ||
26+
scala> def foo: Int || Boolean = ???
27+
def foo: ||[Int, Boolean]

0 commit comments

Comments
 (0)