Skip to content
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

$file doesn't work correctly when run from ammonite predef file #616

Closed
abgruszecki opened this issue May 26, 2017 · 3 comments
Closed

$file doesn't work correctly when run from ammonite predef file #616

abgruszecki opened this issue May 26, 2017 · 3 comments

Comments

@abgruszecki
Copy link

As in the title:

$ cat predef.sc
import $file.test
$ cat test.sc
val f = 5
$ coursier launch com.lihaoyi:ammonite_2.12.2:0.9.3 -- -f predef.sc
Loading...
Compiling /Users/aleksbg/amm/predef.sc
Compiling /Users/aleksbg/amm/test.sc
Welcome to the Ammonite Repl 0.9.3
(Scala 2.12.2 Java 1.8.0_112)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ test
cmd0.sc:1: not found: value test
val res0 = test
           ^
Compilation Failed
@ $file.test
res0: $file.test.type = test
@
@lihaoyi
Copy link
Member

lihaoyi commented May 26, 2017

Specifically, the issue is the imports in the respective predef file are meant to be automatically propagated to the REPL/scripts, but I guess the logic around the ImportHooks in the predef isn't doing it correctly so the magic-imported $file.test isn't being made available in the REPL as test

ImportHook imports are generally handled via a different code-path from "normal" imports and other declarations, so we probably just forgot to take the ImportHook imports coming from the various predefs and plumb them into the right place

@lihaoyi
Copy link
Member

lihaoyi commented May 26, 2017

Fixed by 49e007d

@lihaoyi lihaoyi closed this as completed May 26, 2017
@lihaoyi
Copy link
Member

lihaoyi commented May 26, 2017

Fixed in the latest unstable

lihaoyi Ammonite$ cat ~/.ammonite/predef.sc
import $file.foo
lihaoyi Ammonite$ cat ~/.ammonite/foo.sc
val bar = 1337
lihaoyi Ammonite$ amm
Loading...
Welcome to the Ammonite Repl 49e007d
(Scala 2.12.2 Java 1.8.0_112)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ foo.bar
res0: Int = 1337

lihaoyi added a commit that referenced this issue May 29, 2017
Now the files imported by `predef.sc` will all be sandboxed within the
`ammonite.predef` package, and kept separate from "normally" imported
files which end up in the `$file` package. This fixes an issue that
appeared when #616 was fixed,
where the files imported from your predef would end up at different
package paths depending on what your `pwd` is, resulting in the cached
scripts not lining up with the real package structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants