Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import core.Decorators.*
import core.Constants.*
import core.Definitions.*
import core.Annotations.BodyAnnotation
import core.TypeError
import typer.NoChecking
import inlines.Inlines
import typer.ProtoTypes.*
Expand Down Expand Up @@ -49,7 +50,7 @@ class Erasure extends Phase with DenotTransformer {
override def changesMembers: Boolean = true // the phase adds bridges
override def changesParents: Boolean = true // the phase drops Any

def transform(ref: SingleDenotation)(using Context): SingleDenotation = ref match {
def transform(ref: SingleDenotation)(using Context): SingleDenotation = try ref match {
case ref: SymDenotation =>
def isCompacted(symd: SymDenotation) =
symd.isAnonymousFunction && {
Expand Down Expand Up @@ -130,7 +131,10 @@ class Erasure extends Phase with DenotTransformer {
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), currentStablePeriod, ref.prefix)
case _ =>
ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.symbol.info))
}
} catch case ex: TypeError =>
// Handle missing types from dependencies (e.g., JDK version mismatch)
report.error(ex.toMessage, ref.symbol.srcPos)
ref // Keep old denotation on error

private val eraser = new Erasure.Typer(this)

Expand Down
10 changes: 8 additions & 2 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CompilationTests {

@Test def negAll: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileNeg")
aggregateTests(
var tests = List(
compileFilesInDir("tests/neg", defaultOptions, FileFilter.exclude(TestSources.negScala2LibraryTastyExcludelisted)),
compileFilesInDir("tests/neg-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/neg-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking", "-language:experimental.separationChecking", "-source", "3.8")),
Expand All @@ -160,7 +160,13 @@ class CompilationTests {
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
defaultOptions),
compileFile("tests/neg/i7575.scala", defaultOptions.withoutLanguageFeatures),
).checkExpectedErrors()
)

// i20491: Test JDK version mismatch error - only run on JDK < 21
if !scala.util.Properties.isJavaAtLeast("21") then
tests ::= compileFile("tests/neg-custom-args/i20491/Test.scala", defaultOptions.withClasspath("tests/neg-custom-args/i20491/cp"))

aggregateTests(tests*).checkExpectedErrors()
}

@Test def fuzzyAll: Unit = {
Expand Down
16 changes: 16 additions & 0 deletions tests/neg-custom-args/i20491/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test case for https://github.com/scala/scala3/issues/20491

The `cp/ox/Ox.class` is compiled from the following source using JDK 21:

```scala
// Ox.scala
//> using jvm 21
package ox
import java.util.concurrent.StructuredTaskScope
trait Ox:
def scope: StructuredTaskScope[Any]
```

`$ scala-cli compile Ox.scala -d ./cp`

This test must be run on JDK < 21 to trigger the missing type error for `java.util.concurrent.StructuredTaskScope`.
3 changes: 3 additions & 0 deletions tests/neg-custom-args/i20491/Test.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Error: Ox.scala:6:6 -------------------------------------------------------------------------------------------------
Cannot resolve reference to type java.util.concurrent.type.StructuredTaskScope.
The classfile defining the type might be missing from the classpath.
2 changes: 2 additions & 0 deletions tests/neg-custom-args/i20491/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// anypos-error
given ox.Ox = ???
Binary file added tests/neg-custom-args/i20491/cp/ox/Ox.class
Binary file not shown.
Binary file added tests/neg-custom-args/i20491/cp/ox/Ox.tasty
Binary file not shown.
Loading