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

0.7.5 predef.sc compilation error with `...}}\ndef anything . . . ` #453

Closed
emanresusername opened this Issue Aug 29, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@emanresusername
Contributor

emanresusername commented Aug 29, 2016

predef.sc

{{
}}
def breaks = "in 0.7.5"
LoadedPredef.sc:64: ';' expected but 'def' found.
}def breaks = "in 0.7.5"
 ^
java.lang.RuntimeException: Error during Predef: Compilation Failed
  at ammonite.runtime.Interpreter$$anonfun$10.apply(Interpreter.scala:134)
  at ammonite.runtime.Interpreter$$anonfun$10.apply(Interpreter.scala:118)
  at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:733)
  at scala.collection.immutable.List.foreach(List.scala:381)
  at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:732)
  at ammonite.runtime.Interpreter.<init>(Interpreter.scala:118)
  at ammonite.repl.Repl.<init>(Repl.scala:43)
  at ammonite.Main.instantiateRepl(Main.scala:61)
  at ammonite.Main.run(Main.scala:107)
  ... 39 elided

works fine in 0.7.4
in the mean time, i worked around just putting the {{}} stuff at the end

def works = "fine if before"
{{
}}
@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Aug 29, 2016

Thanks for the report!

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Aug 30, 2016

@emanresusername would one solution be to convert the {{}} stuff to just {} stuff?

{{}} is really only meant to be used in the REPL: the fact that it does stuff (and breaks things!) in scripts is a bug, but when it's fixed it really shouldn't do anything concretely different from {}

lihaoyi pushed a commit that referenced this issue Aug 30, 2016

Li Haoyi
Move the unwrapping of top-level `{}` blocks into the REPL-specific c…
…ode,

rather than having it apply to both REPL and scripts.

This was introduced as a REPL feature (to allow people to enter multiple statements
in one REPL block) and is not useful in scripts. Furthermore, it causes problems
such as #453 due to the way we're parsing
out the `{}`s. Those problems do not exist in the REPL since they only arise when
there are subsequent expressions/statements following the unwrapped `{}` code,
which cannot happen in the REPL since after completing a top-level `{}` entering
a newline will cause the block to be submitted immediately, preventing you from
entering further statements
@emanresusername

This comment has been minimized.

Contributor

emanresusername commented Aug 30, 2016

@lihaoyi yeah, so in my case i was using {{}} limit the scope of some variables i was only using in my prompt

{{
// don't want any of the defs in the repl session
  def current_branch = {
    scala.util.Try {
      ((%%git('branch)).out.lines.filter(grep!("""\*""".r))).head.substring(2)
    }.toOption
  }

  def hostname = {
    (%%hostname).out.lines.head
  }

  def whoami = {
    (%%whoami).out.lines.head
  }

  def date = {
    (%%date("-Is")).out.lines.head.split("-").dropRight(1).mkString("-")
  }

  repl.prompt.bind(
    Seq(
      Option(s"$whoami@$hostname:${wd.toString}[$date]"),
      current_branch.map(branch => {
        s"<$branch>"
      }),
      Option("\nᕕ( ᐛ )ᕗ ")
    ).flatten.mkString
  )
}}

with just {} all those variables leak into the repl session . . . but even though i liked the 0.7.4 behavior, this really isn't a HUGE issue either way. after all, everything breaks SOMEbody's workflow 😅

maybe there's just a better way to do this altogether?

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Aug 30, 2016

5ad48f3 should make {} work in scripts to avoid leakage, and {{}} should be the same as {}, both behaving the same as "normal" Scala. The "unwrapping" behavior on {} will then be reserved for the interactive REPL.

FWIW, just using private within your predef/scripts scripts should also avoid leakage :P

Welcome to the Ammonite Repl 0.7.5
(Scala 2.11.8 Java 1.8.0_102)
haoyi-Ammonite@ %cat "foo.sc"
private[this] val x = 1
val y = x + 1

haoyi-Ammonite@ import $file.foo
import $file.$
haoyi-Ammonite@ foo.x
cmd2.sc:1: value x is not a member of object $file.foo
val res2 = foo.x
               ^
Compilation Failed
haoyi-Ammonite@ foo.y
res2: Int = 2
@emanresusername

This comment has been minimized.

Contributor

emanresusername commented Aug 30, 2016

ahh private, that is definitely better . . . just don't disable spacebar heating!!

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Aug 30, 2016

Fixed in version COMMIT-5ad48f3 http://www.lihaoyi.com/Ammonite/#UnstableVersions

@lihaoyi lihaoyi closed this Aug 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment