Skip to content

Commit 92ddf85

Browse files
safe value test without standard library import
1 parent 90cacad commit 92ddf85

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ class CompilationTests {
240240
compileFilesInDir("tests/init-global/warn-tasty", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyExcludelisted)).checkWarnings()
241241
compileFilesInDir("tests/init-global/pos-tasty", defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings"), FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyExcludelisted)).checkCompile()
242242
end if
243+
locally {
244+
val tastyErrorGroup = TestGroup("checkInitGlobal/safe-value-tasty")
245+
val options = defaultOptions.and("-Wsafe-init", "-Xfatal-warnings")
246+
val tastyErrorOptions = options.without("-Xfatal-warnings")
247+
248+
val outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/safe-value-tasty/SafeValuesDef"
249+
250+
val tests = List(
251+
compileFile("tests/init-global/pos-tasty/safe-value-tasty/def/SafeValuesDef.scala", tastyErrorOptions)(tastyErrorGroup),
252+
).map(_.keepOutput.checkCompile())
253+
254+
compileFile("tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala", tastyErrorOptions.withClasspath(outDirDef))(tastyErrorGroup).checkCompile()
255+
256+
tests.foreach(_.delete())
257+
}
243258
}
244259

245260
// initialization tests
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A { // These are safe values, so no warning should be emitted
2+
TestSafeValues.HashCodeLength
3+
TestSafeValues.BitPartitionSize
4+
TestSafeValues.MaxDepth
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object TestSafeValues {
2+
val HashCodeLength = 32
3+
val BitPartitionSize = 5
4+
val MaxDepth = HashCodeLength.toDouble
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object TestSafeValues {
2+
val HashCodeLength = 32
3+
val BitPartitionSize = 5
4+
val MaxDepth = HashCodeLength.toDouble
5+
}
6+
7+
object A { // These are a safe values, so no warning should be emitted
8+
TestSafeValues.HashCodeLength
9+
TestSafeValues.BitPartitionSize
10+
TestSafeValues.MaxDepth
11+
}

0 commit comments

Comments
 (0)