Skip to content

The REPL stopped reading classfiles from the current working directory #16715

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
julienrf opened this issue Jan 18, 2023 · 4 comments
Closed
Labels
area:repl itype:bug regression This worked in a previous version but doesn't anymore

Comments

@julienrf
Copy link
Contributor

julienrf commented Jan 18, 2023

Compiler version

Regression appeared in 3.1.0.

Minimized code

First, I create a file and I compile it in the current directory.

echo 'class Foo' > Foo.scala
cs launch scalac:3.0.0 -- Foo.scala

Then:

/tmp/scala3-3.1.0/bin/scala
Welcome to Scala 3.1.0 (17.0.4, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                         
scala> new Foo()
-- Error:
1 |new Foo()
  |    ^^^
  |    Not found: type Foo

However, in Scala 3.0.2:

/tmp/scala3-3.0.2/bin/scala     
scala> new Foo()
val res0: Foo = Foo@71c0b742

Also note that if I run scala with cs launch scala:3.1.0 instead of using the binary published in the release, then it works as in 3.0.2.

Expectation

The current working directory should be included in the classpath, by default, as it was the case in 3.0.2, as it is the case in 2.13, and as it is documented:

/tmp/scala3-3.1.0/bin/scala --help
Usage: scala <options> <source files>
where possible standard options include:
[…]
-classpath            Specify where to find user class files.
                      Default: .

Related discussion: VirtusLab/scala-cli#1686

@julienrf julienrf added itype:bug regression This worked in a previous version but doesn't anymore stat:needs triage Every issue needs to have an "area" and "itype" label area:tooling and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 18, 2023
@som-snytt
Copy link
Contributor

Note that this is showing the perils of punctuation, not the parent directory:

-classpath            Specify where to find user class files.
                      Default: ..

It "defaults" to $CLASSPATH if set, and . otherwise.

https://github.com/lampepfl/dotty/blob/main/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala#L38

and redundantly

https://github.com/lampepfl/dotty/blob/main/compiler/src/dotty/tools/dotc/config/PathResolver.scala#L209

The debug option is -Ylog-classpath which shows the disappearance of the dot from user classpath. (-Vclasspath in Scala 2.) Actually scala jars were on boot classpath and got moved to user classpath in 3.1. Scala 2 uses scala.boot.class.path to work around class loading changes in modern jvm.

I see 3.1 is when the generic runner entrypoint was introduced?

There is an ancient history of wishing to remove cwd from the repl classpath and default -Dscala.usejavacp=false. So maybe a design decision was taken at some point?

@SethTisue
Copy link
Member

SethTisue commented Jan 19, 2023

related history at #12571

I doubt that having . on the classpath by default is desirable — it seems likelier to produce gotchas than to truly be helpful. In any case, I don't think we need to do it just because some past Scala versions did, I think the issue should be considered on its merits, independent of history.

@som-snytt
Copy link
Contributor

The scala-cli thread asks WWJD? jshell requires --class-path but also:

Code in the default package, which is also known as the unnamed package, can’t be accessed from JShell.

That makes zero sense to me. Less than zero. I have snippets for testing, and obviously I want to try them out from the REPL.

IIRC there is a special line of code in Scala 2 that allows REPL-hosted code to hack the "empty" package.

JLS adds that we're living in the least useful of all possible worlds:

In implementations of the Java SE Platform that use a hierarchical file system for storing
packages, one typical strategy is to associate an unnamed package with each directory; only
one unnamed package is observable at a time, namely the one that is associated with the
"current working directory". The precise meaning of "current working directory" depends
on the host system.

@Gedochao
Copy link
Contributor

Gedochao commented Jul 3, 2024

It seems we won't be changing the current behaviour.
Closing this.

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

5 participants