Skip to content

Commit bf41a7e

Browse files
Also check generic bounds and method parameters
1 parent 8a1bb48 commit bf41a7e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
7171
override def run(using Context): Unit =
7272
val unit = ctx.compilationUnit
7373
if unit.isJava then
74-
checkBounds(unit.tpdTree)
74+
checkAppliedTypes(unit.tpdTree)
7575
else
7676
super.run
7777

@@ -126,26 +126,32 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
126126
tree
127127
end normalizeTypeArgs
128128

129-
/** Scan a tree and check the type bounds. */
130-
def checkBounds(tree: Tree)(using Context): Unit = tree match
129+
/** Scan a tree and check all the AppliedTypeTrees in it. */
130+
def checkAppliedTypes(tree: Tree)(using Context): Unit = tree match
131131
case tpt: TypeTree =>
132132
Checking.checkAppliedTypesIn(tpt)
133-
case app: AppliedTypeTree =>
134-
Checking.checkAppliedType(app, EmptyTree)
133+
case tree: AppliedTypeTree =>
134+
Checking.checkAppliedType(tree, EmptyTree)
135+
case tree: TypeBoundsTree =>
136+
checkAppliedTypes(tree.hi)
135137
case tree: TypeApply =>
136138
val TypeApply(fn, args) = normalizeTypeArgs(tree)
137-
args.foreach(checkBounds)
138-
case tree: ValOrDefDef =>
139-
checkBounds(tree.tpt)
139+
args.foreach(checkAppliedTypes)
140+
case tree: ValDef =>
141+
checkAppliedTypes(tree.tpt)
142+
case tree: DefDef =>
143+
checkAppliedTypes(tree.tpt)
144+
tree.vparamss.flatten.foreach(checkAppliedTypes)
145+
tree.tparams.foreach(checkAppliedTypes)
140146
case PackageDef(pid, stats) =>
141-
stats.foreach(checkBounds)
147+
stats.foreach(checkAppliedTypes)
142148
case TypeDef(name, rhs) =>
143-
checkBounds(rhs)
149+
checkAppliedTypes(rhs)
144150
case t: Template =>
145-
t.parents.foreach(checkBounds)
146-
t.body.foreach(checkBounds)
151+
t.parents.foreach(checkAppliedTypes)
152+
t.body.foreach(checkAppliedTypes)
147153
case a: Annotated =>
148-
checkBounds(a.arg)
154+
checkAppliedTypes(a.arg)
149155
case _ =>
150156
// no need to check this
151157

0 commit comments

Comments
 (0)