Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SuperCl4sh
Copy link
Contributor

An addition to #23327 that adds a quick fix to remove unnecessary .nn's.

@SuperCl4sh
Copy link
Contributor Author

cc @olhotak @HarrisL2

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.
Copy link
Contributor

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.

Copy link
Contributor

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. (?)

Copy link
Contributor Author

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.

Copy link
Contributor

@olhotak olhotak left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants