diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 90764f4ec981..3058a15572b5 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -240,6 +240,21 @@ class CompilationTests { compileFilesInDir("tests/init-global/warn-tasty", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyExcludelisted)).checkWarnings() compileFilesInDir("tests/init-global/pos-tasty", defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings"), FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyExcludelisted)).checkCompile() end if + locally { + val tastyErrorGroup = TestGroup("checkInitGlobal/safe-value-tasty") + val options = defaultOptions.and("-Wsafe-init", "-Xfatal-warnings", "-Ysafe-init-global") + val tastyErrorOptions = options.without("-Xfatal-warnings") + + val outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/safe-value-tasty/SafeValuesDef" + + val tests = List( + compileFile("tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala", tastyErrorOptions)(tastyErrorGroup), + ).map(_.keepOutput.checkCompile()) + + compileFile("tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala", tastyErrorOptions.withClasspath(outDirDef))(tastyErrorGroup).checkCompile() + + tests.foreach(_.delete()) + } } // initialization tests diff --git a/tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala b/tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala new file mode 100644 index 000000000000..676cb06dfb81 --- /dev/null +++ b/tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala @@ -0,0 +1,5 @@ +object A { // These are safe values, so no warning should be emitted + TestSafeValues.HashCodeLength + TestSafeValues.BitPartitionSize + TestSafeValues.MaxDepth +} \ No newline at end of file diff --git a/tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala b/tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala new file mode 100644 index 000000000000..b12ad98afa04 --- /dev/null +++ b/tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala @@ -0,0 +1,5 @@ +object TestSafeValues { + val HashCodeLength = 32 + val BitPartitionSize = 5 + val MaxDepth = HashCodeLength.toDouble +} \ No newline at end of file diff --git a/tests/init-global/pos-tasty/safe-value.scala b/tests/init-global/pos-tasty/safe-value.scala new file mode 100644 index 000000000000..417485532caf --- /dev/null +++ b/tests/init-global/pos-tasty/safe-value.scala @@ -0,0 +1,11 @@ +object TestSafeValues { + val HashCodeLength = 32 + val BitPartitionSize = 5 + val MaxDepth = HashCodeLength.toDouble +} + +object A { // These are a safe values, so no warning should be emitted + TestSafeValues.HashCodeLength + TestSafeValues.BitPartitionSize + TestSafeValues.MaxDepth +} \ No newline at end of file diff --git a/tests/init-global/pos-tasty/test-safe-value.scala b/tests/init-global/pos-tasty/test-safe-value.scala new file mode 100644 index 000000000000..cb5149864216 --- /dev/null +++ b/tests/init-global/pos-tasty/test-safe-value.scala @@ -0,0 +1,7 @@ +package scala.collection.immutable + +object A { // These are a safe values, so no warning should be emitted + Node.HashCodeLength + Node.BitPartitionSize + Node.MaxDepth +} \ No newline at end of file