File tree 4 files changed +27
-7
lines changed
src/dotty/tools/dotc/printing
test-resources/type-printer
4 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1
- package dotty .tools .dotc
1
+ package dotty .tools
2
+ package dotc
2
3
package printing
3
4
4
5
import core ._
@@ -166,13 +167,17 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
166
167
~ " "
167
168
~ toText(appType.resultType)
168
169
169
- def isInfixType (tp : Type ): Boolean = tp match {
170
+ def isInfixType (tp : Type ): Boolean = tp match
170
171
case AppliedType (tycon, args) =>
171
- args.length == 2 &&
172
- tycon.typeSymbol.getAnnotation(defn.ShowAsInfixAnnot ).map(_.argumentConstant(0 ).forall(_.booleanValue))
173
- .getOrElse(! Character .isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head))
172
+ args.length == 2
173
+ && {
174
+ val sym = tycon.typeSymbol
175
+ sym.is(Infix )
176
+ || sym.getAnnotation(defn.ShowAsInfixAnnot )
177
+ .exists(_.argumentConstant(0 ).forall(_.booleanValue))
178
+ || ! Character .isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head)
179
+ }
174
180
case _ => false
175
- }
176
181
177
182
def tyconName (tp : Type ): Name = tp.typeSymbol.name
178
183
def checkAssocMismatch (tp : Type , isRightAssoc : Boolean ) = tp match {
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def foo: Int Mappy Boolean && String
40
40
scala> @scala.annotation.showAsInfix(false) class ||[T,U]
41
41
// defined class ||
42
42
scala> def foo: Int || Boolean = ???
43
- def foo: ||[Int, Boolean]
43
+ def foo: Int || Boolean
44
44
scala> def foo: Int && Boolean & String = ???
45
45
def foo: Int && Boolean & String
46
46
scala> def foo: (Int && Boolean) & String = ???
Original file line number Diff line number Diff line change
1
+ -- [E007] Type Mismatch Error: tests/neg/print-infix-type.scala:8:29 ---------------------------------------------------
2
+ 8 | val x: over[String, Int] = f // error
3
+ | ^
4
+ | Found: Int over String
5
+ | Required: String over Int
6
+
7
+ longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ object A :
2
+
3
+ opaque infix type over [A , B ] = (A , B )
4
+ def f : over[Int , String ] = (1 , " " )
5
+
6
+ object B :
7
+ import A .*
8
+ val x : over[String , Int ] = f // error
You can’t perform that action at this time.
0 commit comments