Dotty: Invalid file name for class files on Windows

Created on 4 Nov 2019  路  5Comments  路  Source: lampepfl/dotty

minimized code

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.

expectation

Dotty should not generate the file name A$given_=:_of_Int$.class which depend on method names.

Thanks to @michelou for reporting the bug.

bug

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:

given (self: Int)  { ... }

would desugar to:

given `given (self: Int)` { ... }

This has multiple advantages:

  • Easy to generate, does not require traversing trees
  • No chance of name clashes (https://github.com/lampepfl/dotty-feature-requests/issues/59)
  • Error messages sometimes refer to these generated names, by using the source code as the generated name, this makes it easy to grep for the corresponding definition.

All 5 comments

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:

  • Easy to generate, does not require traversing trees
  • No chance of name clashes (https://github.com/lampepfl/dotty-feature-requests/issues/59)
  • Error messages sometimes refer to these generated names, by using the source code as the generated name, this makes it easy to grep for the corresponding definition.

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)

Was this page helpful?
0 / 5 - 0 ratings