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 b5a75c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 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
2 changes: 1 addition & 1 deletion amm/src/main/scala/ammonite/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ case class Main(predefCode: String = "",

loadedPredefFile.right.map{ predefFileInfoOpt =>
val augmentedImports =
if (defaultPredef) Defaults.replImports ++ Interpreter.predefImports
if (defaultPredef) Defaults.replImports(compilerBuilder.scalaVersion) ++ Interpreter.predefImports
else Imports()

val argString = replArgs.zipWithIndex.map{ case (b, idx) =>
Expand Down

0 comments on commit b5a75c0

Please sign in to comment.