@@ -125,15 +125,23 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
125
125
(" implicit " provided isImplicit) ~ argStr ~ " => " ~ argText(args.last)
126
126
}
127
127
128
+ def isInfixType (tp : Type ): Boolean = tp match {
129
+ case AppliedType (tycon, args) =>
130
+ args.length == 2 &&
131
+ ! Character .isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head)
132
+ // TODO: Once we use the 2.12 stdlib, also check the @showAsInfix annotation
133
+ case _ => false
134
+ }
135
+
128
136
def toTextInfixType (op : Type , args : List [Type ]): Text = {
129
137
/* SLS 3.2.8: all infix types have the same precedence.
130
138
* In A op B op' C, op and op' need the same associativity.
131
139
* Therefore, if op is left associative, anything on its right
132
140
* needs to be parenthesized if it's an infix type, and vice versa. */
133
141
val l :: r :: Nil = args
134
142
val isRightAssoc = op.typeSymbol.name.endsWith(" :" )
135
- val leftArg = if (isRightAssoc && l. isInfixType) " (" ~ toText (l) ~ " )" else toText (l)
136
- val rightArg = if (! isRightAssoc && r. isInfixType) " (" ~ toText (r) ~ " )" else toText (r)
143
+ val leftArg = if (isRightAssoc && isInfixType(l)) " (" ~ argText (l) ~ " )" else argText (l)
144
+ val rightArg = if (! isRightAssoc && isInfixType(r)) " (" ~ argText (r) ~ " )" else argText (r)
137
145
138
146
leftArg ~ " " ~ toTextLocal(op) ~ " " ~ rightArg
139
147
}
@@ -146,7 +154,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
146
154
if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ " *"
147
155
if (defn.isFunctionClass(cls)) return toTextFunction(args, cls.name.isImplicitFunction)
148
156
if (defn.isTupleClass(cls)) return toTextTuple(args)
149
- if (tp. isInfixType) return toTextInfixType(tycon, args)
157
+ if (isInfixType(tp) ) return toTextInfixType(tycon, args)
150
158
case EtaExpansion (tycon) =>
151
159
return toText(tycon)
152
160
case tp : TypeRef =>
0 commit comments