Skip to content

Commit

Permalink
Fix recent regression with import hooks in blocks (#1369)
Browse files Browse the repository at this point in the history
This fixes a regression introduced in
#1361. This makes the
following work again as expected:
```scala
@ {
    import $ivy.`org.typelevel::cats-kernel:2.6.1`
  }
```

Before the changes here, in Scala 2.x, one gets an error like
```text
cmd0.sc:2: object org.typelevel::cats-kernel:2.6.1 is not a member of package ammonite.$ivy
import $ivy.`org.typelevel::cats-kernel:2.6.1`
       ^
Compilation Failed
```
  • Loading branch information
alexarchambault authored Jul 18, 2023
1 parent 8b1a558 commit 151446c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Parsers extends IParser {
}

def ImportSplitter[_: P]: P[Seq[ammonite.util.ImportTree]] =
P( `import` ~/ ImportExpr.rep(1, sep = ","./) )
P( WL ~ `import` ~/ ImportExpr.rep(1, sep = ","./) )

def ImportFinder[_: P]: P[String] =
P(WL ~ `import` ~/ ImportExpr.! ~ End)
Expand Down
13 changes: 13 additions & 0 deletions amm/repl/src/test/scala/ammonite/session/AdvancedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,19 @@ object AdvancedTests extends TestSuite{
"""
)
}
test("hook in block") {
check.session(
"""
@ {
@ import $ivy.`org.typelevel::cats-kernel:2.6.1`
@ }
import $ivy.$
@ import cats.kernel._
import cats.kernel._
"""
)
}
test("class-path-hook") {
val sbv = check.scalaBinaryVersion
check.session(
Expand Down

0 comments on commit 151446c

Please sign in to comment.