Given the following code:
class A {
given (self: Int) {
def =:(x: Int) = ???
def f: Int = ???
}
}
Dotty generates a class file A$given_=:_of_Int$.class, which is invalid on Windows, as : is not allowed in file names.
A walkaround is to switch the order of the two methods.
Dotty should not generate the file name A$given_=:_of_Int$.class which depend on method names.
Thanks to @michelou for reporting the bug.
Yep, I'm working on fixing https://github.com/lampepfl/dotty/issues/5936 which should fix this.
Or, can we avoid using the method name for anonymous given?
Yes I think that's a bug, there's no reason to use the name of the first method, but fixing that won't fix the encoding problem with windows since : could still show up in the name of a given parameter.
This is a separate discussion but my proposal for generating names of givens is to simply reuse the source code definition of the given, so for example:
given (self: Int) { ... }
would desugar to:
given `given (self: Int)` { ... }
This has multiple advantages:
I don't think this is fixed. I just got the following error on Windows:
[error] java.nio.file.InvalidPathException: Illegal char <:> at index 23: TypeOrBoundsOps$given_=:=_of_Type$.class
[error] at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
[error] at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
[error] at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
[error] at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
[error] at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
[error] at sun.nio.fs.AbstractPath.resolve(AbstractPath.java:53)
[error] at dotty.tools.io.Path.$div(Path.scala:93)
[error] at dotty.tools.io.PlainFile.lookupName(PlainFile.scala:78)
[error] at dotty.tools.io.AbstractFile.fileOrSubdirectoryNamed(AbstractFile.scala:239)
[error] at dotty.tools.io.AbstractFile.fileNamed(AbstractFile.scala:256)
[error] at dotty.tools.backend.jvm.BytecodeWriters.getFile(BytecodeWriters.scala:31)
[error] at dotty.tools.backend.jvm.GenBCodePipeline.getFile(GenBCode.scala:72)
...
The reference compiler is still using the old encoding, so this won't be truly fixed until we re-bootstrap (at the latest in a couple of weeks with the new release)
Most helpful comment
Yes I think that's a bug, there's no reason to use the name of the first method, but fixing that won't fix the encoding problem with windows since
:could still show up in the name of a given parameter.This is a separate discussion but my proposal for generating names of givens is to simply reuse the source code definition of the given, so for example:
would desugar to:
This has multiple advantages: