Skip to content

"Could not find TASTY file" error when tasty/class files already exist #11644

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

Closed
griggt opened this issue Mar 7, 2021 · 2 comments · Fixed by #11662
Closed

"Could not find TASTY file" error when tasty/class files already exist #11644

griggt opened this issue Mar 7, 2021 · 2 comments · Fixed by #11662
Assignees
Milestone

Comments

@griggt
Copy link
Contributor

griggt commented Mar 7, 2021

Compiler version

3.0.0-RC1 and 3.0.0-RC2-bin-SNAPSHOT-git-086d1a8
(no issue with 3.0.0-M3)

Minimized code

// hello.scala
@main def hello = println("hello, world")

Output

$ ls -l
total 4
-rw-r--r-- 1 tgrigg tgrigg 43 Mar  7 15:34 hello.scala

$ scalac -version
Scala compiler version 3.0.0-RC1 -- Copyright 2002-2021, LAMP/EPFL

$ scalac hello.scala

$ ls -l
total 24
-rw-r--r-- 1 tgrigg tgrigg 757 Mar  7 15:35 'hello$package$.class'
-rw-r--r-- 1 tgrigg tgrigg 267 Mar  7 15:35 'hello$package.class'
-rw-r--r-- 1 tgrigg tgrigg 554 Mar  7 15:35 'hello$package.tasty'
-rw-r--r-- 1 tgrigg tgrigg 882 Mar  7 15:35  hello.class
-rw-r--r-- 1 tgrigg tgrigg  43 Mar  7 15:34  hello.scala
-rw-r--r-- 1 tgrigg tgrigg 471 Mar  7 15:35  hello.tasty

$ scalac hello.scala
Could not find TASTY file hello.tasty under ./hello.class
1 error found

Expectation

No error

Notes

Seems to only be a problem when the class/tasty files are in the current directory.

@smarter smarter added this to the 3.0.0-RC2 milestone Mar 7, 2021
@griggt
Copy link
Contributor Author

griggt commented Mar 8, 2021

This issue appeared recently after #11308 was merged, but what looks to be the root cause is much older (since #3382): dotty.tools.io.Path#parent appears to be broken for files in the current directory.

https://github.com/lampepfl/dotty/blob/086d1a852a1412fb21124b5afdb1022c6d278d8b/compiler/src/dotty/tools/io/Path.scala#L126-L132

sbt:scala3> console

scala> import dotty.tools.io._

scala> Path("./foo.txt").parent
val res0: dotty.tools.io.Directory = ./foo.txt

scala> Path("foo.txt").parent                                                                                         
val res1: dotty.tools.io.Directory = foo.txt

scala> Path("/foo.txt").parent
val res2: dotty.tools.io.Directory = /

scala> Path("./bar/foo.txt").parent                                                                                     
val res3: dotty.tools.io.Directory = bar

scala> Path(".").parent
val res4: dotty.tools.io.Directory = .

Compare Scala 2.13:

sbt:root> console
[info] Starting scala interpreter...
Welcome to Scala 2.13.5 (OpenJDK 64-Bit Server VM, Java 1.8.0_282).
Type in expressions for evaluation. Or try :help.

scala> import scala.reflect.io._
import scala.reflect.io._

scala> Path("./foo.txt").parent
val res0: scala.reflect.io.Directory = .

scala> Path("foo.txt").parent
val res1: scala.reflect.io.Directory = .

scala> Path("/foo.txt").parent
val res2: scala.reflect.io.Directory = /

scala> Path("./bar/foo.txt").parent
val res3: scala.reflect.io.Directory = ./bar

scala> Path(".").parent
val res4: scala.reflect.io.Directory = ..

The Scala 2.13 implementation is here: https://github.com/scala/scala/blob/262f6e9a6d217a8c95dd6e70235f0c615edd50e6/src/reflect/scala/reflect/io/Path.scala#L155-L171

@odersky
Copy link
Contributor

odersky commented Mar 8, 2021

@bishabosha @nicolasstucki maybe one of you could take a look?

griggt added a commit to griggt/dotty that referenced this issue Mar 9, 2021
The previous implementation wrongly assumed that if
`jpath.normalize.getParent` returns null, then `jpath` must be a root.

However the null in this case really only means that no name elements
remain after normalization and the call to `getParent`. Since redundant
name elements such as "." and ".." may be removed by `normalize`, and
`getParent` may simply remove the last name element, there are cases
other than roots to consider, such as the current directory.

Some examples of broken behavior prior this commit:

  scala> Path("./foo.txt").parent
  val res0: dotty.tools.io.Directory = ./foo.txt  // should be Directory(.)

  scala> Path("foo.txt").parent
  val res1: dotty.tools.io.Directory = foo.txt    // should be Directory(.)

  scala> Path(".").parent
  val res4: dotty.tools.io.Directory = .          // should be Directory(..)

The changes here are based in part on the Scala 2.13 implementation of
scala.reflect.io.Path#parent

Fixes scala#11644
griggt added a commit to griggt/dotty that referenced this issue Mar 16, 2021
The previous implementation wrongly assumed that if
`jpath.normalize.getParent` returns null, then `jpath` must be a root.

However the null in this case really only means that no name elements
remain after normalization and the call to `getParent`. Since redundant
name elements such as "." and ".." may be removed by `normalize`, and
`getParent` may simply remove the last name element, there are cases
other than roots to consider, such as the current directory.

Some examples of broken behavior prior this commit:

  scala> Path("./foo.txt").parent
  val res0: dotty.tools.io.Directory = ./foo.txt  // should be Directory(.)

  scala> Path("foo.txt").parent
  val res1: dotty.tools.io.Directory = foo.txt    // should be Directory(.)

  scala> Path(".").parent
  val res4: dotty.tools.io.Directory = .          // should be Directory(..)

The changes here are based in part on the Scala 2.13 implementation of
scala.reflect.io.Path#parent

Fixes scala#11644
bishabosha added a commit that referenced this issue Mar 16, 2021
Fix #11644: Fix broken dotty.tools.io.Path#parent
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 16, 2021
The previous implementation wrongly assumed that if
`jpath.normalize.getParent` returns null, then `jpath` must be a root.

However the null in this case really only means that no name elements
remain after normalization and the call to `getParent`. Since redundant
name elements such as "." and ".." may be removed by `normalize`, and
`getParent` may simply remove the last name element, there are cases
other than roots to consider, such as the current directory.

Some examples of broken behavior prior this commit:

  scala> Path("./foo.txt").parent
  val res0: dotty.tools.io.Directory = ./foo.txt  // should be Directory(.)

  scala> Path("foo.txt").parent
  val res1: dotty.tools.io.Directory = foo.txt    // should be Directory(.)

  scala> Path(".").parent
  val res4: dotty.tools.io.Directory = .          // should be Directory(..)

The changes here are based in part on the Scala 2.13 implementation of
scala.reflect.io.Path#parent

Fixes scala#11644
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 16, 2021
The previous implementation wrongly assumed that if
`jpath.normalize.getParent` returns null, then `jpath` must be a root.

However the null in this case really only means that no name elements
remain after normalization and the call to `getParent`. Since redundant
name elements such as "." and ".." may be removed by `normalize`, and
`getParent` may simply remove the last name element, there are cases
other than roots to consider, such as the current directory.

Some examples of broken behavior prior this commit:

  scala> Path("./foo.txt").parent
  val res0: dotty.tools.io.Directory = ./foo.txt  // should be Directory(.)

  scala> Path("foo.txt").parent
  val res1: dotty.tools.io.Directory = foo.txt    // should be Directory(.)

  scala> Path(".").parent
  val res4: dotty.tools.io.Directory = .          // should be Directory(..)

The changes here are based in part on the Scala 2.13 implementation of
scala.reflect.io.Path#parent

Fixes scala#11644
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants