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 3 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", "-Ysafe-init-global")
val tastyErrorOptions = options.without("-Xfatal-warnings")

val outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/safe-value-tasty/SafeValuesDef"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/safe-value-tasty/SafeValuesDef"
val outDirDef = defaultOutputDir + tastyErrorGroup + "/SafeValuesDef/def/SafeValuesDef"

This seems to be the correct directory path for the generated tasty files. I've found that toDouble in the tasty files has been regarded as method call trees in our checker, instead of selection trees before, so the test can pass now. Maybe the tasty disassembler has been updated and resolved this issue. There are no errors safe unexpected selections on base values in the latest logs, either.


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

Copy link
Author

Choose a reason for hiding this comment

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

There are no different effects. The test still passes. Added the change to a new commit below

Copy link
Contributor

Choose a reason for hiding this comment

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

From the latest errors, it seems there is a problem with the class path:

-- [E006] Not Found Error: tests/init-global/pos-tasty/safe-value-tasty/SafeValuesUse.scala:3:2 ------------------------
3 |  TestSafeValues.BitPartitionSize
  |  ^^^^^^^^^^^^^^
  |  Not found: TestSafeValues

Copy link
Author

Choose a reason for hiding this comment

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

I don't seem to be getting that issue on my end. I used to get that error before but my path was incorrect so perhaps try pulling again? I am running with sbt testCompilation safe-value-tasty and I get the following

============================================================================

Test Report

============================================================================

2 suites passed, 0 failed, 2 total


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