Skip to content

REPL cheats me #6623

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

Open
scabug opened this issue Nov 7, 2012 · 10 comments
Open

REPL cheats me #6623

scabug opened this issue Nov 7, 2012 · 10 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 7, 2012

Today, I spend much time to find out why my reflection code does not work in REPL. And finally, I am sure that I had been cheated by REPL:

Welcome to Scala version 2.10.0-RC1 (Java HotSpot(TM) Client VM, Java 1.7.0_09).

Type in expressions to have them evaluated.
Type :help for more information.

scala> """$line3.$read$$iw$$iw$$iw$Hello, World"""
res0: String = Hello, World

I consider replacing $line3.$read$$iw$$iw$$iw$ trick as a bug, because it breaks reflect like class Foo; Class.forName("Foo") and make people confused.

I highly recommend to remove this trick.

@scabug
Copy link
Author

scabug commented Nov 7, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6623?orig=1
Reporter: @Atry
Affected Versions: 2.10.0-RC1

@scabug
Copy link
Author

scabug commented Nov 7, 2012

@paulp said:
I understand your frustration, but it isn't that easy. Showing all identifiers with names like "$line3.$read$$iw$$iw$$iw$" is a non-starter. Selectively rewriting only the desired strings is harder than it looks. The floor is open for suggestions.

@scabug
Copy link
Author

scabug commented Jun 6, 2015

@som-snytt said:
I never remember if it's wrapStrings or unwrapStrings and whether it should be true or false.

scala> $intp.isettings
res0: scala.tools.nsc.interpreter.ISettings =

 ISettings {
   deprecation = false
  maxAutoprintCompletion = 250
  maxPrintString = 800
  unwrapStrings = true

 }

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

The recent simplification of the javap command leaves it un-unwrapped. That is, true names are shown.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
adriaanm pushed a commit to adriaanm/scala that referenced this issue Apr 28, 2017
Use a conventional import to bump context depth in REPL templates.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward scala/bug#6623-like transparency.

 - retronym takes the blame for this innovation;
 - adriaanm collaborated in its commission;
 - som-snytt batted clean-up.
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
adriaanm pushed a commit to adriaanm/scala that referenced this issue Jun 22, 2017
The repl imports scala.tools.nsc.interpreter.{{
to bump the context depth in REPL templates,
instead of wrapping subsequent input in deeper `$iw` objects.

Code is still ordinarily wrapped in a `$read` object.

This is a step toward transparency of the repl encoding
(see scala/bug#6623).

  - retronym takes the blame for this innovation.
  - adriaanm collaborated in its commission.
  - som-snytt batted clean-up.

Other changes:
  - $read is special cased by typer;
    not a good idea to make it a property
  - hide INSTANCE (class-based wrapping) from type toString
    by renaming it to include the `$read` name
@SethTisue SethTisue removed the has PR label Mar 1, 2018
@som-snytt
Copy link

Forward port at scala/scala#8600

Backward at scala/scala#8576

Closing as merged to 2.12 with momentum for 2.13 in the new year.

@dwijnand dwijnand modified the milestones: Backlog, 2.12.11 Jan 15, 2020
@SethTisue
Copy link
Member

SethTisue commented Mar 1, 2020

I note for the record that this is only fixed under a non-default setting (namely -Yrepl-use-magic-imports)

I'm tempted to change the issue title to something more informative, but after all these years I've grown attached to the original title.

@SethTisue
Copy link
Member

actually, is it even fixed at all? am I missing something?

sbt:root> scala -Yrepl-use-magic-imports
[info] running (fork) scala.tools.nsc.MainGenericRunner -usejavacp -Yrepl-use-magic-imports
Welcome to Scala 2.13.2-20200229-113552-09ad166 (OpenJDK 64-Bit Server VM, Java 1.8.0_242).
Type in expressions for evaluation. Or try :help.

scala> """$line3.$read$$iw$$iw$$iw$Hello, World"""
val res0: String = Hello, World

@som-snytt
Copy link

@SethTisue you need a lightbend subscription to get the sbt ScalaOptionParser support.

@dwijnand
Copy link
Member

dwijnand commented Mar 1, 2020

Maybe it's fairer to not call this one fixed. The "magic" import option gets rid of the increased nesting, but we still nest things and try to pretend we don't.

@dwijnand dwijnand reopened this Mar 1, 2020
@dwijnand dwijnand modified the milestones: 2.12.11, Backlog Mar 1, 2020
@som-snytt
Copy link

som-snytt commented Mar 1, 2020

Actually instead of filtering all output, the feedback output should echo the user input (not showing wrapping). Wrapping should be visible otherwise, in :type and toString, etc.

Also turning it off was made harder instead of easier in 2.13.

@SethTisue
Copy link
Member

SethTisue commented Mar 1, 2020

@SethTisue you need a lightbend subscription to get the sbt ScalaOptionParser support.

hehe, I suppose I should have mentioned that I had to add the flag to ScalaOptionParser to even try that

(I didn't want to admit I was too lazy to go on and PR it)

@SethTisue SethTisue removed the has PR label Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants