-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add quick fix to remove unnecessary .nn #23461
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
Conversation
override def explain(using Context) = { | ||
val code1 = """val a: String = "foo".nn""" | ||
val code2 = """val a: String = "foo"""" | ||
i"""With -Yexplicit-nulls, this happens when use apply .nn to a term that is already non-null. |
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.
Depending on the reason
, this may not be accurate: it could also be because you're applying .nn
to a nullable term in a context that admits a nullable term.
I'd suggest changing reason
to a Boolean
, then have all the strings in this class, in the implementation of msg
and explain
.
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 explain
isn't really necessary at all. (?)
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 gone and removed the explain
, but I'll keep this comment thread open just in case someone comes along and has another idea.
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.
When I tried it out, it removes .n
but not the second n
. So null.nn
becomes nulln
, "foo".nn
becomes "foo" n
(not sure where the space comes from).
Please add test(s) to dotty/tools/dotc/reporting/CodeActionTest.scala
An extension to #23461 that adds a quick fix to add a .nn. For example, if the code were ```scala val t: String | Null = ??? val s: String = t ``` the quick fix would transform the code to: ```scala val t: String | Null = ??? val s: String = t.nn ```
An addition to #23327 that adds a quick fix to remove unnecessary .nn's.