Skip to content

Commit 8a1bb48

Browse files
Scan the tree without a Transformer
1 parent c76b81b commit 8a1bb48

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,17 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
6868

6969
override def changesMembers: Boolean = true // the phase adds super accessors and synthetic members
7070

71+
override def run(using Context): Unit =
72+
val unit = ctx.compilationUnit
73+
if unit.isJava then
74+
checkBounds(unit.tpdTree)
75+
else
76+
super.run
77+
7178
override def transformPhase(using Context): Phase = thisPhase.next
7279

7380
protected def newTransformer(using Context): Transformer =
74-
if ctx.compilationUnit.isJava then LimitedChecksTransformer()
75-
else PostTyperTransformer()
81+
PostTyperTransformer()
7682

7783
val superAcc: SuperAccessors = new SuperAccessors(thisPhase)
7884
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
@@ -118,32 +124,30 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
118124
TypeApply(tycon, args1).withSpan(tree.span).withType(tree.tpe)
119125
case _ =>
120126
tree
121-
122-
class LimitedChecksTransformer extends Transformer {
123-
private def checkAppliedTypes(tree: Tree)(using Context): Unit = tree match
124-
case tpt: TypeTree =>
125-
Checking.checkAppliedTypesIn(tpt)
126-
case app: AppliedTypeTree =>
127-
Checking.checkAppliedType(app, EmptyTree)
128-
case _ =>
129-
130-
override def transform(tree: Tree)(using Context): Tree =
131-
ctx.debuglog(s"LimitedChecksTransformer.transform(${tree.show})")
132-
ctx.debuglog(s" -- $tree")
133-
tree match
134-
case Select(qual, name) if name.isTypeName =>
135-
Checking.checkRealizable(qual.tpe, qual.posd)
136-
if name.isTypeName then
137-
super.transform(tree)(using ctx.addMode(Mode.Type))
138-
case tree: TypeApply =>
139-
val TypeApply(fn, args) = normalizeTypeArgs(tree)
140-
args.foreach(checkAppliedTypes)
141-
case tree: ValOrDefDef =>
142-
checkAppliedTypes(tree.tpt)
143-
case _ =>
144-
super.transform(tree)
145-
tree
146-
}
127+
end normalizeTypeArgs
128+
129+
/** Scan a tree and check the type bounds. */
130+
def checkBounds(tree: Tree)(using Context): Unit = tree match
131+
case tpt: TypeTree =>
132+
Checking.checkAppliedTypesIn(tpt)
133+
case app: AppliedTypeTree =>
134+
Checking.checkAppliedType(app, EmptyTree)
135+
case tree: TypeApply =>
136+
val TypeApply(fn, args) = normalizeTypeArgs(tree)
137+
args.foreach(checkBounds)
138+
case tree: ValOrDefDef =>
139+
checkBounds(tree.tpt)
140+
case PackageDef(pid, stats) =>
141+
stats.foreach(checkBounds)
142+
case TypeDef(name, rhs) =>
143+
checkBounds(rhs)
144+
case t: Template =>
145+
t.parents.foreach(checkBounds)
146+
t.body.foreach(checkBounds)
147+
case a: Annotated =>
148+
checkBounds(a.arg)
149+
case _ =>
150+
// no need to check this
147151

148152
class PostTyperTransformer extends Transformer {
149153

0 commit comments

Comments
 (0)