@@ -68,11 +68,17 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
68
68
69
69
override def changesMembers : Boolean = true // the phase adds super accessors and synthetic members
70
70
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
+
71
78
override def transformPhase (using Context ): Phase = thisPhase.next
72
79
73
80
protected def newTransformer (using Context ): Transformer =
74
- if ctx.compilationUnit.isJava then LimitedChecksTransformer ()
75
- else PostTyperTransformer ()
81
+ PostTyperTransformer ()
76
82
77
83
val superAcc : SuperAccessors = new SuperAccessors (thisPhase)
78
84
val synthMbr : SyntheticMembers = new SyntheticMembers (thisPhase)
@@ -118,32 +124,30 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
118
124
TypeApply (tycon, args1).withSpan(tree.span).withType(tree.tpe)
119
125
case _ =>
120
126
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
147
151
148
152
class PostTyperTransformer extends Transformer {
149
153
0 commit comments