-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add quick fix to add .nn #23598
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
base: main
Are you sure you want to change the base?
Add quick fix to add .nn #23598
Changes from 3 commits
f952dd2
6c2147d
8229c8b
70a169a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,6 +300,11 @@ extends NotFoundMsg(MissingIdentID) { | |
class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tree], addenda: => String*)(using Context) | ||
extends TypeMismatchMsg(found, expected)(TypeMismatchID): | ||
|
||
private val shouldSuggestNN = | ||
if expected.isValueType then | ||
found frozen_<:< OrNull(expected) | ||
else false | ||
|
||
def msg(using Context) = | ||
// replace constrained TypeParamRefs and their typevars by their bounds where possible | ||
// and the bounds are not f-bounds. | ||
|
@@ -360,6 +365,28 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre | |
val treeStr = inTree.map(x => s"\nTree:\n\n${x.show}\n").getOrElse("") | ||
treeStr + "\n" + super.explain | ||
|
||
override def actions(using Context) = | ||
if shouldSuggestNN then | ||
inTree match { | ||
case Some(tree) if tree != null => | ||
SuperCl4sh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val content = tree.source.content().slice(tree.srcPos.startPos.start, tree.srcPos.endPos.end).mkString | ||
val replacement = tree match | ||
case Apply(fun, args) => "(" + content + ").nn" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safer to add "( )" by default? For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like the best approach. The only problem I have is detecting a regular apply. Binary infix operators have ApplyKind Regular and I couldn't find another way to determine if Apply's were initially written as a regular non-infix apply in the source code. Do you know if there's a way to detect "true" regular apply's? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've addressed all the other comments in the latest commit, but I'm still unsure how to detect functions written Infix. For the time being, both ApplyKind Regular and InfixTuple have "()" added to them while ApplyKind Using has no brackets. |
||
case _ => content + ".nn" | ||
List( | ||
CodeAction(title = """Add .nn""", | ||
description = None, | ||
patches = List( | ||
ActionPatch(tree.srcPos.sourcePos, replacement) | ||
) | ||
) | ||
) | ||
SuperCl4sh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case _ => | ||
List() | ||
} | ||
else | ||
SuperCl4sh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List() | ||
|
||
end TypeMismatch | ||
|
||
class NotAMember(site: Type, val name: Name, selected: String, proto: Type, addendum: => String = "")(using Context) | ||
|
Uh oh!
There was an error while loading. Please reload this page.