Skip to content

REPL renders syntax highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and leading val #11555

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
bjornregnell opened this issue Feb 27, 2021 · 7 comments

Comments

@bjornregnell
Copy link
Contributor

Compiler version

3.0.0-RC1 and also in 3.0.0-RC2-bin-20210226-63a467b-NIGHTLY

Minimized code

If you enter this in REPL strange colors will emerge in echo: (see output png below)

scala> "a A"
val res0: String = a A

scala> "a: A"
val res1: String = a: A

scala> "a: A B C"                                                                                                              
val res2: String = a: A B C

scala> "a: A, B, C"                                                                                                            
val res3: String = a: A, B, C

scala> "val a: A, B, C"                                                                                                        
val res4: String = val a: A, B, C

Output

image

Expectation

Syntax highlighting should not be activated when rendering of characters inside string values when echoed.

@bjornregnell
Copy link
Contributor Author

Perhaps related to #10615

@bjornregnell bjornregnell changed the title REPL renders synatx highlighting colors inside strings when echo string evaluated values, happens after colon : and for leading val REPL renders synatx highlighting colors inside strings when echo evaluated String-values, happens after colon : and for leading val Feb 27, 2021
@bjornregnell bjornregnell changed the title REPL renders synatx highlighting colors inside strings when echo evaluated String-values, happens after colon : and for leading val REPL renders synatx highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and for leading val Feb 27, 2021
@bjornregnell bjornregnell changed the title REPL renders synatx highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and for leading val REPL renders synatx highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and leading val Feb 27, 2021
@som-snytt
Copy link
Contributor

The echoed text is no longer in double quotes. (This is finally addressed in the scala 2 PR for repl printing.)

@bjornregnell
Copy link
Contributor Author

@som-snytt You mean this one? scala/scala#8885 (still open at time of writing)

The current Scala 2 REPL does correctly not try to syntax highlight inside arbitrary strings, so this is a regression in Scala 3.

@som-snytt
Copy link
Contributor

Yes, example diff from the PR

val res1: String = muuh
val res1: String = "muuh"

In Scala 3, compare

scala> """"val x: Int = 42""""
val res0: String = "val x: Int = 42"

The PR adds the double quotes via replStringOf.

The highlighter highlights what you render. Note that Scala 2 colorization doesn't really compare.

Scala 3 invokes ScalaRunTime.replStringOf reflectively; fortunately, the PR preserves the API; it adds an overload that takes a flag for "verbose" case class rendering, which would be nice to add once that PR is merged, one of these years.

@som-snytt
Copy link
Contributor

I goosed the Scala 2 PR again. I have no idea why they thought it was essential to put "val" in front of REPL output, but it doesn't matter whether strings are rendered with quotes. With quotes, Scala 3 colors are correct.

scala> "val a: B"
val res1: String = val a: B

scala> """"val a: B""""
val res2: String = "val a: B"

@bjornregnell
Copy link
Contributor Author

I think the val makes sense from a learner's perspective. It makes it obvious what happens semantically in the REPL session. And with your nice quotes in output the code is even executable ;) which is even better. I think the quotes should always be there when rendering strings in the output so the code is executable. And it the string contains quotes it should be tripple-quoted if we buy that logic (that the output of a evaluated value is valid code).

@som-snytt
Copy link
Contributor

som-snytt commented Sep 2, 2021

This is the Scala 2 REPL PR:

scala> """"hello, world""""
val res1: String = "\"hello, world\""

scala> """"hello,
     | world""""
val res2: String =
"""\"hello,
world\""""

The escaping triple quotes for multiline, but uses ordinary escape for internal quote.

Edit: actually, the second example is wrong, it shouldn't do both! thanks for the heads up, @bjornregnell

@SethTisue SethTisue changed the title REPL renders synatx highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and leading val REPL renders syntax highlighting colors INSIDE of strings when echoing evaluated values, happens after colon : and leading val Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants