Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Apr 16, 2020

Add surrounding quotes to Strings and use verbose toString for Products that are not Tuples.

The goal is limited pretty-printing in REPL.

When arity >= 2 and not opting out with deprecatedName, print param names.

The opt-out idiom is @deprecatedName("x") x: X, which means "don't call me by my name." If any parameter is annotated, just use ordinary toString.

Note: goal is not pretty-printing but to improve casual toString REPL experience.

If there is only one param, no disambiguation is required, and the name of the wrapped value is often uninteresting (supposition).

Fixes scala/bug#8603

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Apr 16, 2020
@som-snytt
Copy link
Contributor Author

som-snytt commented Apr 16, 2020

Check if param check is too forcing at time of invocation.

_toString0 not yet enshrined. (also mima)

@sjrd
Copy link
Member

sjrd commented Apr 16, 2020

That's a massive run-time behavior change for a lot of code. It's going to break so many things. I really don't we should do that in a minor version, and I would even be very hesitant to do it in a major version.

@som-snytt
Copy link
Contributor Author

som-snytt commented Apr 16, 2020

@sjrd yes, you've registered that position in the previous PR. This is mostly just for fun; given past discussion, it probably won't fly. But the problem space is small enough to revisit.

@dwijnand

This comment has been minimized.

@som-snytt
Copy link
Contributor Author

Previous art and discussion
#6936
https://contributors.scala-lang.org/t/case-class-tostring-new-behavior-proposal-with-implementation/2056

@som-snytt som-snytt closed this Apr 20, 2020
@SethTisue SethTisue removed this from the 2.13.3 milestone May 1, 2020
@som-snytt som-snytt reopened this May 9, 2020
@scala-jenkins scala-jenkins added this to the 2.13.3 milestone May 9, 2020
@SethTisue SethTisue modified the milestones: 2.13.3, 2.13.4 May 12, 2020
@som-snytt som-snytt closed this May 14, 2020
@som-snytt som-snytt deleted the issue/_toString branch May 14, 2020 18:04
@SethTisue SethTisue removed this from the 2.13.4 milestone May 14, 2020
@som-snytt som-snytt restored the issue/_toString branch May 27, 2020 07:03
@som-snytt
Copy link
Contributor Author

Reopening because before it was fixed you would see:

scala> List[String]()
res1: List[String] = List()

scala> List[String]("")
res2: List[String] = List()

@som-snytt som-snytt reopened this May 27, 2020
@scala-jenkins scala-jenkins added this to the 2.13.4 milestone May 27, 2020
@som-snytt som-snytt changed the title Alternative case class toString Improve REPL result printing for String and Product May 27, 2020
@som-snytt som-snytt force-pushed the issue/_toString branch 4 times, most recently from c6ddc99 to c176947 Compare May 28, 2020 04:42
@SethTisue
Copy link
Member

SethTisue commented Apr 20, 2022

I think this might fall into the category of things where you need to convince the Scala 3 folks first

And therefore I'm going to close this to get it out of the PR queue — we can always reopen later if things move forward on the Scala 3 side.

@SethTisue SethTisue closed this Apr 20, 2022
@som-snytt
Copy link
Contributor Author

There is a misunderstanding. Scala 3 is calling into our runtime, and Scala 3 will also benefit when this is merged.

@SethTisue SethTisue reopened this Apr 20, 2022
@SethTisue
Copy link
Member

SethTisue commented Apr 20, 2022

Okay. Let's summon a Scala 3 reviewer or two, but before we do that, can you attempt to make the PR description user-facing and country simple about what this does and why?

(And once you've stated your case, then I guess we can un-draft the PR.)

(To be clear, I believe I am in favor of this change, in my heart at least, and I'm trying to help you give it the best chance of making it through... I hope it doesn't come across as being difficult.)

@SethTisue SethTisue modified the milestones: 2.13.9, 2.13.10 Apr 25, 2022
`replStringOf` takes an int that is the max len
to print, not the max number of elements.

Special overloads also take a verbose flag
for printing element names and quotes around
String values.

The 3-param overload does not inject extra
newlines, so that Scala 3 REPL need not strip
them.
@som-snytt som-snytt changed the title Improve REPL result printing for String and Product Improve REPL result printing for String and Product [ci: last-only] Sep 4, 2022
@lrytz lrytz modified the milestones: 2.13.10, 2.13.11 Sep 26, 2022
@som-snytt
Copy link
Contributor Author

som-snytt commented Sep 29, 2022

Scala 3 literally needs at least an ellipsis. Can we spare them three dots?

scala/scala3#16011

Dots in #10178

@som-snytt
Copy link
Contributor Author

While forward-porting the tpolecat test, I realized the improved stringOf is still not merged for Scala 3 repl. How long, Oh Lord?

The message comment is updated to // return value of "tpolecat.toString" is null, which sounds like the NPE message.

It would be nice to backport, if there is something to backport it on top of.

@som-snytt
Copy link
Contributor Author

Sorry, PR, that I forgot your third birthday.

@som-snytt
Copy link
Contributor Author

@SethTisue said:

I'd cut off my pinky for this. (I mean, like, if it would grow back in a few months.)

scala/bug#3967 (comment)

@som-snytt
Copy link
Contributor Author

Comparing java record

image

@som-snytt
Copy link
Contributor Author

Relates to #10180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool:REPL Changes to the Scala REPL shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve REPL display of String values
8 participants