Skip to content

Safe val test #23533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the test is compiled with the option -Ysafe-init-global. Consider adding it to the option variable before


tests.foreach(_.delete())
}
}

// initialization tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object A { // These are safe values, so no warning should be emitted
TestSafeValues.HashCodeLength
TestSafeValues.BitPartitionSize
TestSafeValues.MaxDepth
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object TestSafeValues {
val HashCodeLength = 32
val BitPartitionSize = 5
val MaxDepth = HashCodeLength.toDouble
}
11 changes: 11 additions & 0 deletions tests/init-global/pos-tasty/safe-value.scala
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions tests/init-global/pos-tasty/test-safe-value.scala
Original file line number Diff line number Diff line change
@@ -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
}
Loading