Skip to content

Commit 8972b20

Browse files
committed
Add test for #20491 run in Java < 21
1 parent 082ba9e commit 8972b20

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CompilationTests {
149149

150150
@Test def negAll: Unit = {
151151
implicit val testGroup: TestGroup = TestGroup("compileNeg")
152-
aggregateTests(
152+
var tests = List(
153153
compileFilesInDir("tests/neg", defaultOptions, FileFilter.exclude(TestSources.negScala2LibraryTastyExcludelisted)),
154154
compileFilesInDir("tests/neg-deep-subtype", allowDeepSubtypes),
155155
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking", "-language:experimental.separationChecking", "-source", "3.8")),
@@ -160,7 +160,13 @@ class CompilationTests {
160160
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
161161
defaultOptions),
162162
compileFile("tests/neg/i7575.scala", defaultOptions.withoutLanguageFeatures),
163-
).checkExpectedErrors()
163+
)
164+
165+
// i20491: Test JDK version mismatch error - only run on JDK < 21
166+
if !scala.util.Properties.isJavaAtLeast("21") then
167+
tests ::= compileFile("tests/neg-custom-args/i20491/Test.scala", defaultOptions.withClasspath("tests/neg-custom-args/i20491/cp"))
168+
169+
aggregateTests(tests*).checkExpectedErrors()
164170
}
165171

166172
@Test def fuzzyAll: Unit = {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Test case for https://github.com/scala/scala3/issues/20491
2+
3+
The `cp/ox/Ox.class` is compiled from the following source using JDK 21:
4+
5+
```scala
6+
// Ox.scala
7+
//> using jvm 21
8+
package ox
9+
import java.util.concurrent.StructuredTaskScope
10+
trait Ox:
11+
def scope: StructuredTaskScope[Any]
12+
```
13+
14+
`$ scala-cli compile Ox.scala -d ./cp`
15+
16+
This test must be run on JDK < 21 to trigger the missing type error for `java.util.concurrent.StructuredTaskScope`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Error: Ox.scala:6:6 -------------------------------------------------------------------------------------------------
2+
Cannot resolve reference to type java.util.concurrent.type.StructuredTaskScope.
3+
The classfile defining the type might be missing from the classpath.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// anypos-error
2+
given ox.Ox = ???
283 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)