Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

os-lib typing issues #13

Open
anatoliykmetyuk opened this issue Jul 25, 2019 · 0 comments
Open

os-lib typing issues #13

anatoliykmetyuk opened this issue Jul 25, 2019 · 0 comments
Labels
intent:investigate-behavior You have noticed a behavior that may or may not constitute an issue and want to return to it later

Comments

@anatoliykmetyuk
Copy link
Contributor

Typing Issues

Reproduction

Both available at https://github.com/lihaoyi/os-lib/tree/d7746195925f000c57769ef06c417564def52ac3/.

To reproduce:

  1. git clone https://github.com/lihaoyi/os-lib.git && cd os-lib && git checkout d7746195925f000c57769ef06c417564def52ac3
  2. In build.sc:
    • sed 's/Cross[OsModule]("2.12.7", "2.13.0")/Cross[OsModule]("2.12.7", "2.13.0", "0.16.0-RC3")/g'
    • Comment out lines 21-23
    • sed s/def ivyDeps = Agg(ivy"com.lihaoyi::geny:0.1.8")/def ivyDeps = Agg(ivy"com.lihaoyi:geny_2.12:0.1.8")
  3. mill os[0.16.0-RC3].test

Typing if

Location: ReadWriteOps.scala:31
Typing if clause

val permArray =
  if (perms == null) Array[FileAttribute[PosixFilePermission]]()
  else Array(PosixFilePermissions.asFileAttribute(perms.toSet()))

The if branch’s type:

Array[FileAttribute[PosixFilePermission]]

The else branch’s type:

Array[FileAttribute[java.util.Set[PosixFilePermission]]]

The type of permArray gets inferred as (array of):

>: (
[error]    |  java.nio.file.attribute.FileAttribute[
[error]    |    java.nio.file.attribute.PosixFilePermission
[error]    |  ]
[error]    | &
[error]    |  java.nio.file.attribute.FileAttribute[
[error]    |    java.util.Set[java.nio.file.attribute.PosixFilePermission]
[error]    |  ]
[error]    |) <: (
[error]    |  java.nio.file.attribute.FileAttribute[
[error]    |    java.nio.file.attribute.PosixFilePermission
[error]    |  ]
[error]    | |
[error]    |  java.nio.file.attribute.FileAttribute[
[error]    |    java.util.Set[java.nio.file.attribute.PosixFilePermission]
[error]    |  ]
[error]    |)

The above is the same encoding used in previous version of opaque types meant to say that the type in question is equal to both the if branch’s type and the else branch’s type.

Compiles fine under Scala 2. Should it though?

Fix:

val permArray =
  if (perms == null) Array[FileAttribute[java.util.Set[PosixFilePermission]]]()
  else Array(PosixFilePermissions.asFileAttribute(perms.toSet()))

Overloads

Location: ExampleTests.scala:16

[error] -- [E051] Reference Error: /Users/anatolii/Projects/dotty/ammonite/os-lib/os/test/src/test/os/ExampleTests.scala:16:6
[error] 16 |      os.read(wd/"file.txt") ==> "hello"
[error]    |      ^^^^^^^
[error]    |Ambiguous overload. The overloaded alternatives of method apply in object read with types
[error]    | (arg: os.Path, charSet: io.Codec, offset: Long, count: Int): String
[error]    | (arg: os.ReadablePath, charSet: io.Codec): String
[error]    | (arg: os.ReadablePath): String
[error]    |all match arguments (wd.ThisType)

The context:

  val tests = Tests {
    test("splash") - TestUtil.prep{wd: os.ReadablePath => if (Unix()){
/*...*/
      os.read(wd/"file.txt") ==> "hello"
/*...*/}}

The fix:

os.read(wd/"file.txt": os.ReadablePath) ==> "hello"
@anatoliykmetyuk anatoliykmetyuk added the intent:investigate-behavior You have noticed a behavior that may or may not constitute an issue and want to return to it later label Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
intent:investigate-behavior You have noticed a behavior that may or may not constitute an issue and want to return to it later
Projects
None yet
Development

No branches or pull requests

1 participant