Skip to content

Commit

Permalink
Import typeOf in Scala 2 only
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Nov 14, 2023
1 parent a668e19 commit 3dad819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions amm/repl/src/main/scala/ammonite/main/Defaults.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

package ammonite.main

import java.io.InputStream

import ammonite.util.{ImportData, Imports, Util}
import ammonite.util.{ImportData, Imports, Name, Util}
import coursierapi.Dependency

import scala.io.Codec
Expand All @@ -21,14 +20,20 @@ object Defaults{
)
}

val replImports = Imports(
ImportData("""ammonite.repl.ReplBridge.value.{
codeColorsImplicit,
tprintColorsImplicit,
show
}""")
)
def ammoniteHome = os.Path(System.getProperty("user.home"))/".ammonite"
def replImports(scalaVersion: String) = {
val sharedFields = Seq("codeColorsImplicit", "tprintColorsImplicit", "show")
val fields = if (scalaVersion.startsWith("2.")) sharedFields :+ "typeOf" else sharedFields
val importss = fields.map(field =>
ImportData(
Name(field),
Name(field),
Name("_root_") :: Name("ammonite") :: Name("repl") :: Name("ReplBridge") :: Name("value") :: Nil,
ImportData.Term
)
)
Imports(importss)
}
def ammoniteHome = os.Path(System.getProperty("user.home")) / ".ammonite"

def alreadyLoadedDependencies(
resourceName: String = "amm-dependencies.txt"
Expand Down
2 changes: 1 addition & 1 deletion amm/repl/src/test/scala/ammonite/TestRepl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TestRepl(compilerBuilder: ICompilerBuilder = CompilerBuilder()) { self =>
val frames = Ref(List(Frame.createInitial(initialClassLoader)))
val sess0 = new SessionApiImpl(frames)

val baseImports = ammonite.main.Defaults.replImports ++ Interpreter.predefImports
val baseImports = ammonite.main.Defaults.replImports(compilerBuilder.scalaVersion) ++ Interpreter.predefImports
val basePredefs = Seq(
PredefInfo(Name("testPredef"), predef._1, false, predef._2)
)
Expand Down

0 comments on commit 3dad819

Please sign in to comment.