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
Improve REPL display of method types #8319
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly bikeshedding, but that's the nature of the bug.
Thanks for taking this on!
also it would be quite good if protected def printedName(name: Name, decoded: Boolean = true) = {
import Chars._
val decName = name.decoded
val bslash = '\\'
val isDot = (x: Char) => x == '.'
val brackets = List('[',']','(',')','{','}')
def addBackquotes(s: String) =
if (decoded && (decName.exists(ch => brackets.contains(ch) || isWhitespace(ch) || isDot(ch)) ||
(name.isOperatorName && decName.exists(isOperatorPart) && decName.exists(isScalaLetter) && !decName.contains(bslash))))
s"`$s`" else s
if (name == nme.CONSTRUCTOR) "this"
else addBackquotes(quotedName(name, decoded))
} |
if (mods.isLazy) codegenln(false, "<lazy>") | ||
else any2stringOf(path, maxStringElements) | ||
if (mods.isLazy) """""""" | ||
else """" = " + """ + any2stringOf(path, maxStringElements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the cartoon quality of the long eyebrow, but maybe these lines could be clearer? Anything that doesn't entail counting quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I can't tell by looking if it helps me understand what lazy val i = 27
means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've cleaned up the quotes, but right now the repl would print
scala> lazy val i = 27
lazy val i: Int
scala>
is = <lazy>
noise or useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= ???
, perhaps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
scala> lazy val x = 0
lazy val x: Int // unevaluated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= ???
, perhaps
I'm concerned with triple question mark as a beginner could see that as the value in Predef and be confused.
This is more like what people ask for ("something I can cut/paste"), but I'm not sure about output for Just speculating, but what if
|
But then if there are too many members to a definition wouldn’t that be polluting to print them out? |
For things like highlighting lazy or verbose class printing, I'm thinking of the beginner use case. I don't have an answer, but I've often thought that beginner mode would be useful. I assumed that printing "val i" so it looks like code was also a beginner feature. Also, the jalapeno bagel at the office this morning is really hot, so I have to go get some water now. |
Very nice work! I think it's best to omit members from class definitions and generally the right-hand side of definitions. I like that everything echo'ed is valid syntax. We already have a way to print the tree after type checking (add |
I can't see an option to edit: or most likely you mean make a new Issue for it 😀 |
Sorry, it's not there yet. I meant we could make the secret |
Also, this could definitely be left for a follow-up PR. |
For future ref, I was futzing with repl recently and I thought verbose print could be a mode. print-tab is handy but going into print mode, I can try out a few things and just see it printed verbosely. It could also be a regular setting, |
(It seems like more noise/annoyance than benefit to me. Separate PR, please, if someone still wants to do it.) |
|
needs rebase (probably very minor) I suggest we push this to 2.13.2 |
ValDef repl output is source compatible Side effecting repl output is source compatible Method definition repl output is source compatible Lazy val repl output is source compatible REPL print remove comments from definitions, print macro as def also removed `= <method>` from def and `= <lazy>` from lazy val refactored implementation of withoutImplicit REPL print restore string2code use for types of valdefs REPL print, refactor quoted strings revert partest run/t7455 check for JDK 8 REPL print, add unevaluated comment to lazy val
d31a308
to
11a932b
Compare
Squashed and rebased |
Very nice, thanks @bishabosha! |
This is awesome. Thanks, @bishabosha! |
The following examples are implemented, my main question is should
methodTypeAsDef
stay in theIMain
class or go elsewhere - it currently computes the type String as if it will be appended to a method name.Current behaviour:
val
/var
def
/macro
definitions - I'd prefer to comment
// defined class A
to make it clear information is lostFixes scala/bug#10024