Skip to content

Fix & reuse printing of dummyTreeOfType #16750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package printing

import core._
import Constants.*
import Texts._
import Types._
import Flags._
Expand Down Expand Up @@ -286,14 +287,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case tp: ViewProto =>
toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
case tp @ FunProto(args, resultType) =>
val argsText = args match {
case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp)
case _ => toTextGlobal(args, ", ")
}
"[applied to ("
~ keywordText("using ").provided(tp.isContextualMethod)
~ keywordText("erased ").provided(tp.isErasedMethod)
~ argsText
~ argsTreeText(args)
~ ") returning "
~ toText(resultType)
~ "]"
Expand All @@ -309,6 +306,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
protected def exprToText(tp: ExprType): Text =
"=> " ~ toText(tp.resType)

protected def argsTreeText(args: List[untpd.Tree]): Text = args match
case dummyTreeOfType(tp) :: Nil if !tp.isRef(defn.NullClass) && !homogenizedView => toText(Constant(null)) ~ ": " ~ toText(tp)
case _ => toTextGlobal(args, ", ")

protected def blockToText[T <: Untyped](block: Block[T]): Text =
blockText(block.stats :+ block.expr)

Expand Down Expand Up @@ -442,7 +443,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
toTextLocal(fun)
~ "("
~ Str("using ").provided(app.applyKind == ApplyKind.Using && !homogenizedView)
~ toTextGlobal(args, ", ")
~ argsTreeText(args)
~ ")"
case tree: TypeApply =>
typeApplyText(tree)
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,12 @@ object ProtoTypes {
*
* [] _
*/
@sharable object AnyFunctionProto extends UncachedGroundType with MatchAlways
@sharable object AnyFunctionProto extends UncachedGroundType with MatchAlways:
override def toString = "AnyFunctionProto"

/** A prototype for type constructors that are followed by a type application */
@sharable object AnyTypeConstructorProto extends UncachedGroundType with MatchAlways
@sharable object AnyTypeConstructorProto extends UncachedGroundType with MatchAlways:
override def toString = "AnyTypeConstructorProto"

extension (pt: Type)
def isExtensionApplyProto: Boolean = pt match
Expand Down Expand Up @@ -946,8 +948,8 @@ object ProtoTypes {
object dummyTreeOfType {
def apply(tp: Type)(implicit src: SourceFile): Tree =
untpd.Literal(Constant(null)) withTypeUnchecked tp
def unapply(tree: untpd.Tree): Option[Type] = tree match {
case Literal(Constant(null)) => Some(tree.typeOpt)
def unapply(tree: untpd.Tree): Option[Type] = untpd.unsplice(tree) match {
case tree @ Literal(Constant(null)) => Some(tree.typeOpt)
case _ => None
}
}
Expand Down