From 90cacadfa28b1dd5d37fa60921293aa05a2783b2 Mon Sep 17 00:00:00 2001 From: jkhhon Date: Wed, 25 Jun 2025 11:42:52 -0400 Subject: [PATCH 1/4] Added test case --- tests/init-global/pos-tasty/test-safe-value.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/init-global/pos-tasty/test-safe-value.scala 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 From 92ddf8500e206f8c256c837683c37543bb7f02d6 Mon Sep 17 00:00:00 2001 From: sbpatel Date: Tue, 15 Jul 2025 14:22:19 -0400 Subject: [PATCH 2/4] safe value test without standard library import --- .../test/dotty/tools/dotc/CompilationTests.scala | 15 +++++++++++++++ .../safe-value-tasty/SafeValuesUse.scala | 5 +++++ .../safe-value-tasty/def/SafeValuesDef.scala | 5 +++++ tests/init-global/pos-tasty/safe-value.scala | 11 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala create mode 100644 tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala create mode 100644 tests/init-global/pos-tasty/safe-value.scala diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 90764f4ec981..0f2c302f3b1d 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") + 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 From 56cbfec1fe187aa08a86bb1aa5da53c9e41cbfb0 Mon Sep 17 00:00:00 2001 From: sbpatel Date: Mon, 21 Jul 2025 19:00:23 -0400 Subject: [PATCH 3/4] add Ysafe initi option to test compilation for safe val test --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 0f2c302f3b1d..3058a15572b5 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -242,7 +242,7 @@ class CompilationTests { end if locally { val tastyErrorGroup = TestGroup("checkInitGlobal/safe-value-tasty") - val options = defaultOptions.and("-Wsafe-init", "-Xfatal-warnings") + 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" From aee78a27c64e3e4baf5df18783c02b78416b483b Mon Sep 17 00:00:00 2001 From: sbpatel Date: Tue, 29 Jul 2025 09:26:07 -0400 Subject: [PATCH 4/4] edit compilation test path --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 3058a15572b5..525746f909f4 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -245,7 +245,7 @@ class CompilationTests { 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 outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/def/SafeValuesDef" val tests = List( compileFile("tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala", tastyErrorOptions)(tastyErrorGroup),