Skip to content

Commit 15a44fb

Browse files
committed
Check for tasty error in Template trees.
1 parent fbe970e commit 15a44fb

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,18 @@ object Semantic:
448448
object TreeCache:
449449
class CacheData:
450450
private val emptyTrees = mutable.Set[ValOrDefDef]()
451-
private val emptyTemplates = mutable.Set[Template]()
451+
private val templatesToSkip = mutable.Set[Template]()
452452

453-
def checkTemplateBodyValidity(tpl: Template, className: String)(using Context): Unit = {
454-
if (emptyTemplates.contains(tpl))
455-
throw new Exception("Error in body of " + className)
453+
def checkTemplateBodyValidity(tpl: Template, className: String)(using Context): Unit =
454+
if (templatesToSkip.contains(tpl))
455+
throw new TastyTreeException(className)
456456

457457
val errorCount = ctx.reporter.errorCount
458458
tpl.forceFields()
459459

460460
if (ctx.reporter.errorCount > errorCount)
461-
report.warning("Skipping the analysis of " + className + " due to an error reading the body of " + className + "'s TASTy.")
462-
emptyTemplates.add(tpl)
463-
throw new Exception("Error in body of " + className)
464-
}
461+
templatesToSkip.add(tpl)
462+
throw new TastyTreeException(className)
465463

466464
extension (tree: ValOrDefDef)
467465
def getRhs(using Context): Tree =
@@ -1193,7 +1191,7 @@ object Semantic:
11931191
try
11941192
checkClass(classSym)
11951193
catch
1196-
case e: Exception =>
1194+
case TastyTreeException(className) => report.warning("Skipping the analysis of " + classSym.show + " due to an error reading the body of " + className + "'s TASTy.")
11971195

11981196
// ----- Semantic definition --------------------------------
11991197
type ArgInfo = TraceValue[Value]

Diff for: compiler/src/dotty/tools/dotc/transform/init/Util.scala

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import config.Printers.init as printer
1515
import Trace.*
1616

1717
object Util:
18+
/** Exception used for errors encountered when reading TASTy. */
19+
case class TastyTreeException(msg: String) extends RuntimeException(msg)
20+
1821
/** Utility definition used for better error-reporting of argument errors */
1922
case class TraceValue[T](value: T, trace: Trace)
2023

Diff for: compiler/test/dotty/tools/dotc/CompilationTests.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ class CompilationTests {
297297
}
298298

299299
/* This tests for errors in the program's TASTy trees.
300-
* The test consists of four files: C, v1/A, v1/B, and v0/A. v1/A, v1/B, and v0/A all depend on C. v1/A and v1/B are
300+
* The test consists of five files: Main, C, v1/A, v1/B, and v0/A. The files v1/A, v1/B, and v0/A all depend on C. v1/A and v1/B are
301301
* compatible, but v1/B and v0/A are not. If v1/B and v0/A are compiled together, there should be
302-
* an error when reading the files' TASTy trees. */
302+
* an error when reading the files' TASTy trees. This fact is demonstrated by the compilation of Main. */
303303
locally {
304304
val tastyErrorGroup = TestGroup("checkInit/tasty-error/typedef")
305-
val tastyErrorOptions = options.without("-Xfatal-warnings")
305+
val tastyErrorOptions = options.without("-Xfatal-warnings").without("-Ycheck:all")
306306

307307
val classC = defaultOutputDir + tastyErrorGroup + "/C/typedef/C"
308308
val classA0 = defaultOutputDir + tastyErrorGroup + "/A/v0/A"
@@ -317,7 +317,6 @@ class CompilationTests {
317317
).map(_.keepOutput.checkCompile())
318318

319319
compileFile("tests/init/tasty-error/typedef/Main.scala", tastyErrorOptions.withClasspath(classC).withClasspath(classA0).withClasspath(classB1))(tastyErrorGroup).checkExpectedErrors()
320-
compileFile("tests/init/tasty-error/typedef/DependOnB.scala", tastyErrorOptions.withClasspath(classC).withClasspath(classA0).withClasspath(classB1))(tastyErrorGroup).checkCompile()
321320

322321
tests.foreach(_.delete())
323322
}

Diff for: tests/init/tasty-error/typedef/DependOnB.scala

-1
This file was deleted.

Diff for: tests/init/tasty-error/typedef/Main.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
class Main extends B{} // anypos-error
1+
class Main extends B{} // anypos-error
2+
class ExtendsB extends B{}

0 commit comments

Comments
 (0)