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

The REPL incorrectly prints some strings with dollars in them #9335

Open
scabug opened this issue May 28, 2015 · 7 comments
Open

The REPL incorrectly prints some strings with dollars in them #9335

scabug opened this issue May 28, 2015 · 7 comments
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 28, 2015

scala> val x = "Foo$line3.$read$"
x: String = Foo

scala> x
res66: String = Foo

scala> println(x)
Foo$line3.$read$
@scabug
Copy link
Author

@scabug scabug commented May 28, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9335?orig=1
Reporter: Guillaume Martres (Smarter)
Affected Versions: 2.11.6
See #4884

@scabug
Copy link
Author

@scabug scabug commented May 28, 2015

@SethTisue said:
This comes up from time to time and is always good for yucks. See also #4884

@scabug
Copy link
Author

@scabug scabug commented May 28, 2015

Guillaume Martres (Smarter) said (edited on May 28, 2015 1:29:38 AM UTC):
I guess I shoudl also say that I discovered that while playing with reflection:

scala> class A { val x: Int = 1 }
defined class A

scala> val a = classOf[A].getDeclaredFields
a: Array[java.lang.reflect.Field] = Array(private final int A.x)

scala> a(0).toString
res2: String = private final int A.x

scala> a(0).toString.toList
res3: List[Char] = List(p, r, i, v, a, t, e,  , f, i, n, a, l,  , i, n, t,  , $, l, i, n, e, 6, ., $, r, e, a, d, $, $, i, w, $, $, i, w, $, A, ., x)

@scabug
Copy link
Author

@scabug scabug commented May 28, 2015

@som-snytt said:
There's a ticket for documenting the REPL, but until then, this ought to be less of a secret:

scala> $intp.isettings.unwrapStrings = false
$intp.isettings.unwrapStrings: Boolean = false

scala> val x = "Foo$line3.$read$"
x: String = Foo$line3.$read$

scala> class A { val x: Int = 1 }
defined class A

scala> classOf[A].getDeclaredFields()(0)
res1: java.lang.reflect.Field = private final int $line7.$read$$iw$$iw$A.x

I wonder if Ammonite resolves the documentation bug already.

@SethTisue
Copy link
Member

@SethTisue SethTisue commented Aug 11, 2019

There's a ticket for documenting the REPL, but until then, this ought to be less of a secret

a PR adding $intp.isettings.unwrapStrings to https://docs.scala-lang.org/overviews/repl/overview.html would be welcome

@som-snytt
Copy link

@som-snytt som-snytt commented Aug 12, 2019

The fluid idiom in 2.13:

$ scala
Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 12.0.1).
Type in expressions for evaluation. Or try :help.

scala> $intp.reporter.asInstanceOf[tools.nsc.interpreter.shell.ReplReporterImpl].unwrapStrings = false
mutated $intp.reporter.asInstanceOf[tools.nsc.interpreter.shell.ReplReporterImpl].unwrapStrings

scala> class A { val x: Int = 1 }
defined class A

scala> classOf[A].getDeclaredFields()(0)
res0: java.lang.reflect.Field = private final int $line4.$read$$iw$$iw$A.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.