@@ -40,11 +40,10 @@ class FrontEnd extends Phase {
4040
4141 def monitor (doing : String )(body : => Unit )(using Context ): Unit =
4242 try body
43- catch {
43+ catch
4444 case NonFatal (ex) =>
4545 report.echo(s " exception occurred while $doing ${ctx.compilationUnit}" )
4646 throw ex
47- }
4847
4948 def parse (using Context ): Unit = monitor(" parsing" ) {
5049 val unit = ctx.compilationUnit
@@ -84,17 +83,23 @@ class FrontEnd extends Phase {
8483 case ex : CompilationUnit .SuspendException =>
8584 }
8685
87- private def firstTopLevelDef (trees : List [tpd.Tree ])(using Context ): Symbol = trees match {
86+ def javaCheck (using Context ): Unit = monitor(" checking java" ) {
87+ val unit = ctx.compilationUnit
88+ if unit.isJava then
89+ JavaChecks .check(unit.tpdTree)
90+ }
91+
92+
93+ private def firstTopLevelDef (trees : List [tpd.Tree ])(using Context ): Symbol = trees match
8894 case PackageDef (_, defs) :: _ => firstTopLevelDef(defs)
8995 case Import (_, _) :: defs => firstTopLevelDef(defs)
9096 case (tree @ TypeDef (_, _)) :: _ => tree.symbol
9197 case _ => NoSymbol
92- }
9398
9499 protected def discardAfterTyper (unit : CompilationUnit )(using Context ): Boolean =
95100 unit.isJava || unit.suspended
96101
97- override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] = {
102+ override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
98103 val unitContexts =
99104 for unit <- units yield
100105 report.inform(s " compiling ${unit.source}" )
@@ -106,13 +111,15 @@ class FrontEnd extends Phase {
106111 enterSyms(using remaining.head)
107112 remaining = remaining.tail
108113
109- if ( firstXmlPos.exists && ! defn.ScalaXmlPackageClass .exists)
114+ if firstXmlPos.exists && ! defn.ScalaXmlPackageClass .exists then
110115 report.error(""" To support XML literals, your project must depend on scala-xml.
111116 |See https://github.com/scala/scala-xml for more information.""" .stripMargin,
112117 firstXmlPos)
113118
114119 unitContexts.foreach(typeCheck(using _))
115120 record(" total trees after typer" , ast.Trees .ntrees)
121+ unitContexts.foreach(javaCheck(using _)) // after typechecking to avoid cycles
122+
116123 val newUnits = unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
117124 val suspendedUnits = ctx.run.suspendedUnits
118125 if newUnits.isEmpty && suspendedUnits.nonEmpty && ! ctx.reporter.errorsReported then
@@ -123,14 +130,13 @@ class FrontEnd extends Phase {
123130 | ${suspendedUnits.toList}%, %
124131 | """
125132 val enableXprintSuspensionHint =
126- if ( ctx.settings.XprintSuspension .value) " "
133+ if ctx.settings.XprintSuspension .value then " "
127134 else " \n\n Compiling with -Xprint-suspension gives more information."
128135 report.error(em """ Cyclic macro dependencies $where
129136 |Compilation stopped since no further progress can be made.
130137 |
131138 |To fix this, place macros in one set of files and their callers in another. $enableXprintSuspensionHint""" )
132139 newUnits
133- }
134140
135141 def run (using Context ): Unit = unsupported(" run" )
136142}
0 commit comments