Skip to content

Commit

Permalink
Trees: add Type.Block, containing TypeDefs
Browse files Browse the repository at this point in the history
To support SIP-53, it's been defined as `TypeBlock`
under https://dotty.epfl.ch/docs/internals/syntax.html.
  • Loading branch information
kitbellew committed Mar 7, 2024
1 parent ea9cfa2 commit fd56940
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scalameta/trees/shared/src/main/scala/scala/meta/Trees.scala
Expand Up @@ -424,6 +424,9 @@ object Type {
@ast class ParamClause(values: List[Param]) extends Member.ParamClause

@ast class Match(tpe: Type, cases: List[TypeCase] @nonEmpty) extends Type with Tree.WithCases

@ast class Block(typeDefs: List[Stat.TypeDef], tpe: Type) extends Type

def fresh(): Type.Name = fresh("fresh")
def fresh(prefix: String): Type.Name = Type.Name(prefix + Fresh.nextId())
}
Expand Down
Expand Up @@ -705,6 +705,7 @@ object TreeSyntax {
}
val cbounds = r(t.cbounds.map { s(kw(":"), " ", _) })
s(w(mods, " "), variance, t.name, t.tparamClause, tbounds, vbounds, cbounds)
case t: Type.Block => s(w(r(t.typeDefs, "; "), "; "), t.tpe)

// Pat
case t: Pat.Var =>
Expand Down
Expand Up @@ -469,6 +469,7 @@ class SurfaceSuite extends FunSuite {
|scala.meta.Type.Apply
|scala.meta.Type.ApplyInfix
|scala.meta.Type.ArgClause
|scala.meta.Type.Block
|scala.meta.Type.Bounds
|scala.meta.Type.ByName
|scala.meta.Type.ContextFunction
Expand Down
Expand Up @@ -24,7 +24,7 @@ class ReflectionSuite extends FunSuite {
val sym = symbolOf[scala.meta.Tree]
assert(sym.isRoot)
val root = sym.asRoot
assertEquals((root.allBranches.length, root.allLeafs.length), (50, 408))
assertEquals((root.allBranches.length, root.allLeafs.length), (50, 410))
}

test("If") {
Expand Down Expand Up @@ -98,6 +98,7 @@ class ReflectionSuite extends FunSuite {
|List[scala.meta.Mod]
|List[scala.meta.Pat]
|List[scala.meta.Source]
|List[scala.meta.Stat.TypeDef]
|List[scala.meta.Stat]
|List[scala.meta.Term.Name]
|List[scala.meta.Term.Param]
Expand Down
Expand Up @@ -2064,4 +2064,19 @@ class SyntacticSuite extends scala.meta.tests.parsers.ParseSuite {
)
}

test("#3610 Type.Block 1") {
val tree = Type.Block(Nil, pname("Int"))
assertEquals(tree.syntax, "Int")
}

test("#3610 Type.Block 2") {
val tree = Type.Block(List(Decl.Type(Nil, pname("t"), Nil, noBounds)), pname("t"))
assertEquals(tree.syntax, "type t; t")
}

test("#3610 Type.Block 3") {
val tree = Type.Block(List(Defn.Type(Nil, pname("t"), Nil, pname("Int"))), pname("t"))
assertEquals(tree.syntax, "type t = Int; t")
}

}

0 comments on commit fd56940

Please sign in to comment.