- Notifications
You must be signed in to change notification settings - Fork1.1k
Fix -Wconf:src Windows path conversion#24772
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Fix -Wconf:src Windows path conversion#24772
Conversation
Updates the -Wconf:src filter to avoid using `java.nio.file.Path.toURI`in order to fix Windows source path conversions.`Path.toURI` prepends the current working directory to Windows-likepaths unconditionally, and converts backslashes in such paths to `%5C`escape sequences This can cause `-Wconf:src` filters that work onnon-Windows platforms to fail on Windows.For example, before this change, the `Path.toURI` conversion in the`SourcePattern` case from `MessageFilter.matches()` produced:```txtoriginal: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:%5Cfoo%5Cbar%5Cmyfile.scala```After this change, it produces the following, which still prepends thecurrent working directory, but properly converts path separators to `/`:```txtoriginal: Optional[C:\foo\bar\myfile.scala]resolved: /Users/mbland/src/scala/scala3/C:/foo/bar/myfile.scala```This change is based onscala/scala#11192, and also adapts some testcases from that pull request to validate symlink and normalized pathhandling. This change also extracts the `diagnosticWarning` helpermethod to reduce duplication between new and existing test cases.
lrytz commentedDec 18, 2025
After blowing the dust off my Windows VM, I can confirm this is platform dependent. On Windows: scala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.normalizevalres0: java.nio.file.Path=C:\bar\f.txtscala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.toUri.normalize.getRawPathvalres1:String=/C:/bar/f.txt On macOS: scala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.normalizevalres0: java.nio.file.Path=/Users/luc/code/scala/scala13/sandbox/C:\foo\..\bar\f.txtscala> java.io.File("C:\\foo\\..\\bar\\f.txt").toPath.toAbsolutePath.toUri.normalize.getRawPathvalres1:String=/Users/luc/code/scala/scala13/sandbox/C:%5Cfoo%5C..%5Cbar%5Cf.txt So arguably the current implementation using |
mbland commentedDec 18, 2025
Hmm, arguably, yes. So if you want, I could:
One other thing I noticed was that, unlike the Scala 2 implementation, the @Testdef`Wconf src filter only matches entire directory path components`:Unit=valpath=Path("foobar/File.scala")valresult= wconfSrcFilterTest( argsStr="-Wconf:src=bar/.*\\.scala:s", warning= diagnosticWarning(util.SourceFile(newPlainFile(path),"UTF-8")) ) assertEquals(result,Right(reporting.Action.Warning)) Note that the current tests reverse the [error] Test dotty.tools.dotc.config.ScalaSettingsTests.Wconf src filter only matches entire directory path components failed: java.lang.AssertionError: expected:<Right(Silent)> but was:<Right(Warning)>, took 0.001 sec[error] at dotty.tools.dotc.config.ScalaSettingsTests.Wconf src filter only matches entire directory path components(ScalaSettingsTests.scala:308) So the fourth option would be:
|
Updates the -Wconf:src filter to avoid using
java.nio.file.Path.toURIin order to fix Windows source path conversions.Path.toURIprepends the current working directory to Windows-like paths unconditionally, and converts backslashes in such paths to%5Cescape sequences This can cause-Wconf:srcfilters that work on non-Windows platforms to fail on Windows.For example, before this change, the
Path.toURIconversion in theSourcePatterncase fromMessageFilter.matches()produced:After this change, it produces the following, which still prepends the current working directory, but properly converts path separators to
/:This change is based onscala/scala#11192, and also adapts some test cases from that pull request to validate symlink and normalized path handling. This change also extracts the
diagnosticWarninghelper method to reduce duplication between new and existing test cases.Fixes#24771. Review by@lrytz.