Skip to content

Commit 84fdbc9

Browse files
committed
Add test case.
1 parent f64ce59 commit 84fdbc9

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,13 +1353,11 @@ object Semantic:
13531353

13541354
case closureDef(ddef) =>
13551355
val rhs = ddef.getRhs
1356-
if rhs.isEmpty then Hot
1357-
else Fun(rhs, thisV, klass)
1356+
Fun(rhs, thisV, klass)
13581357

13591358
case PolyFun(ddef) =>
13601359
val rhs = ddef.getRhs
1361-
if rhs.isEmpty then Hot
1362-
else Fun(rhs, thisV, klass)
1360+
Fun(rhs, thisV, klass)
13631361

13641362
case Block(stats, expr) =>
13651363
eval(stats, thisV, klass)
@@ -1414,7 +1412,6 @@ object Semantic:
14141412
val rhs = vdef.getRhs
14151413
eval(rhs, thisV, klass)
14161414

1417-
14181415
case ddef : DefDef =>
14191416
// local method
14201417
Hot

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,29 @@ class CompilationTests {
263263

264264
tests.foreach(_.delete())
265265
}
266+
267+
/* This tests for errors in the program's TASTy trees.
268+
* The test consists of three files: (a) v1/A, (b) v1/B, and (c) v0/A. (a) and (b) are
269+
* compatible, but (b) and (c) are not. If (b) and (c) are compiled together, there should be
270+
* an error when reading the files' TASTy trees. */
271+
locally {
272+
val tastyErrorGroup = TestGroup("checkInit/tasty-error")
273+
val tastyErrorOptions = options.without("-Xfatal-warnings")
274+
275+
val a0 = defaultOutputDir + tastyErrorGroup + "/A/v0/A"
276+
val a1 = defaultOutputDir + tastyErrorGroup + "/A/v1/A"
277+
val b1 = defaultOutputDir + tastyErrorGroup + "/B/v1/B"
278+
val a0b1 = a0 + ":" + b1
279+
280+
val tests = List(
281+
compileFile("tests/init/tasty-error/v1/A.scala", tastyErrorOptions)(tastyErrorGroup),
282+
compileFile("tests/init/tasty-error/v1/B.scala", tastyErrorOptions.withClasspath(a1))(tastyErrorGroup),
283+
compileFile("tests/init/tasty-error/v0/A.scala", tastyErrorOptions)(tastyErrorGroup),
284+
).map(_.keepOutput.checkCompile())
285+
compileFile("tests/init/tasty-error/Main.scala", tastyErrorOptions.withClasspath(a0b1))(tastyErrorGroup).expectFailure.checkCompile()
286+
287+
tests.foreach(_.delete())
288+
}
266289
}
267290

268291
// parallel backend tests

tests/init/tasty-error/Main.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Main extends B{}

tests/init/tasty-error/v0/A.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
def fail(a: Int, b: Int): Int = a
3+
}

tests/init/tasty-error/v1/A.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
def fail(a: Int): Int = a
3+
}

tests/init/tasty-error/v1/B.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class B {
2+
val a: A = new A
3+
val x = a.fail(0)
4+
}

0 commit comments

Comments
 (0)