Skip to content

Commit 38b9fd8

Browse files
committed
Fix & reuse printing of dummyTreeOfType
The main fix is the unsplice, which was making the pattern not match for FunProto. But also, when the tree is applied to the dummy, print the dummy in the Apply node. And print null as a constant literal. Also, given AnyFunctionProto and AnyTypeConstructorProto shorter toStrings.
1 parent d99d9bf commit 38b9fd8

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotc
33
package printing
44

55
import core._
6+
import Constants.*
67
import Texts._
78
import Types._
89
import Flags._
@@ -286,14 +287,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
286287
case tp: ViewProto =>
287288
toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
288289
case tp @ FunProto(args, resultType) =>
289-
val argsText = args match {
290-
case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp)
291-
case _ => toTextGlobal(args, ", ")
292-
}
293290
"[applied to ("
294291
~ keywordText("using ").provided(tp.isContextualMethod)
295292
~ keywordText("erased ").provided(tp.isErasedMethod)
296-
~ argsText
293+
~ argsTreeText(args)
297294
~ ") returning "
298295
~ toText(resultType)
299296
~ "]"
@@ -309,6 +306,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
309306
protected def exprToText(tp: ExprType): Text =
310307
"=> " ~ toText(tp.resType)
311308

309+
protected def argsTreeText(args: List[untpd.Tree]): Text = args match
310+
case dummyTreeOfType(tp) :: Nil if !tp.isRef(defn.NullClass) => toText(Constant(null)) ~ ": " ~ toText(tp)
311+
case _ => toTextGlobal(args, ", ")
312+
312313
protected def blockToText[T <: Untyped](block: Block[T]): Text =
313314
blockText(block.stats :+ block.expr)
314315

@@ -442,7 +443,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
442443
toTextLocal(fun)
443444
~ "("
444445
~ Str("using ").provided(app.applyKind == ApplyKind.Using && !homogenizedView)
445-
~ toTextGlobal(args, ", ")
446+
~ argsTreeText(args)
446447
~ ")"
447448
case tree: TypeApply =>
448449
typeApplyText(tree)

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,12 @@ object ProtoTypes {
671671
*
672672
* [] _
673673
*/
674-
@sharable object AnyFunctionProto extends UncachedGroundType with MatchAlways
674+
@sharable object AnyFunctionProto extends UncachedGroundType with MatchAlways:
675+
override def toString = "AnyFunctionProto"
675676

676677
/** A prototype for type constructors that are followed by a type application */
677-
@sharable object AnyTypeConstructorProto extends UncachedGroundType with MatchAlways
678+
@sharable object AnyTypeConstructorProto extends UncachedGroundType with MatchAlways:
679+
override def toString = "AnyTypeConstructorProto"
678680

679681
extension (pt: Type)
680682
def isExtensionApplyProto: Boolean = pt match
@@ -946,8 +948,8 @@ object ProtoTypes {
946948
object dummyTreeOfType {
947949
def apply(tp: Type)(implicit src: SourceFile): Tree =
948950
untpd.Literal(Constant(null)) withTypeUnchecked tp
949-
def unapply(tree: untpd.Tree): Option[Type] = tree match {
950-
case Literal(Constant(null)) => Some(tree.typeOpt)
951+
def unapply(tree: untpd.Tree): Option[Type] = untpd.unsplice(tree) match {
952+
case tree @ Literal(Constant(null)) => Some(tree.typeOpt)
951953
case _ => None
952954
}
953955
}

0 commit comments

Comments
 (0)