Skip to content

Commit

Permalink
TreeOps: skip empty types in defDefReturnType
Browse files Browse the repository at this point in the history
Historically, the parser returns `Type.Name("Unit")` for declarations
or definitions using the procedure syntax (i.e., no explicit `: type`).

However, that tree occupies no tokens and hence needs to be ignored.
  • Loading branch information
kitbellew committed Jul 10, 2023
1 parent 5bfe04b commit 4f63202
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ object TreeOps {
}

@tailrec
def defDefReturnType(tree: Tree): Option[Type] =
private def defDefReturnTypeImpl(tree: Tree): Option[Type] =
tree match {
case d: Decl.Def => Some(d.decltpe)
case d: Defn.Def => d.decltpe
Expand All @@ -363,11 +363,14 @@ object TreeOps {
case _: Pat.Var | _: Term.Name | _: Member.ParamClause |
_: Member.ParamClauseGroup =>
tree.parent match {
case Some(p) => defDefReturnType(p)
case Some(p) => defDefReturnTypeImpl(p)
case _ => None
}
case _ => None
}
def defDefReturnType(tree: Tree): Option[Type] =
defDefReturnTypeImpl(tree).filter(!_.pos.isEmpty)

val DefDefReturnTypeLeft =
new FormatToken.ExtractFromMeta(x => defDefReturnType(x.leftOwner))
val DefDefReturnTypeRight =
Expand Down

0 comments on commit 4f63202

Please sign in to comment.