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
fix: handle backticked names in inffered-type #3791
Conversation
4b89643
to
9a39c5b
Compare
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.
LGTM!
Maybe we can backport this namePos
strategy (in Scala3) to Interactive#namePos
https://github.com/lampepfl/dotty/blob/73cda0c9ad9a23132dabc8f8a7a47663da3ee3fa/compiler/src/dotty/tools/dotc/interactive/SourceTree.scala#L34-L36 ?
tree.source.atSpan(Span(start, end, start)) | ||
case None => | ||
val ch = text.charAt(idx) | ||
if ch == realName.head then |
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.
Maybe it's too cautious, but can we use headOption
to avoid NoSuchElementException
here?
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.
Is it possible to get zero length name?
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 don't think it's possible, we could add a require with a proper message just in case
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.
added a check for that
|
||
def lookup( | ||
idx: Int, | ||
start: Option[(Int, List[Char])], |
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.
[note]
A pair of next position and trailing realName
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.
Maybe forge this note into code?
case class Lookup(position: Int, tralingName: List[Char])
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.
Looks good.
private def namePos(text: String, tree: untpd.NameTree)(using | ||
Context | ||
): SourcePosition = | ||
val realName = tree.name.stripModuleClassSuffix.lastPart.toString.toList |
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.
Could you provide some example how tree.name.stripModuleClassSuffix
and tree.name.stripModuleClassSuffix.lastPart
differs from each other?
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.
@kpodsiad I don't know. I just copied this line from from compiler impl for namePos
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.
Ok, adding info that this line from from compiler impl for namePos
will also be helpful for future us.
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.
ok, just removed lastPart
call. Tests pass without it.
val end = if withBacktick then idx + 1 else idx | ||
tree.source.atSpan(Span(start, end, start)) | ||
case None => | ||
val ch = text.charAt(idx) |
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.
Should we guard idx
with, for example, tree.sourcePos.end
?
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.
case None if idx < text.length
should probably suffice
I thought about that. Honestly, I don't like the approach in this pr but there is no other ways to fix it. |
tree.source.atSpan(Span(start, end, start)) | ||
case None => | ||
val ch = text.charAt(idx) | ||
if ch == realName.head then |
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 don't think it's possible, we could add a require with a proper message just in case
val end = if withBacktick then idx + 1 else idx | ||
tree.source.atSpan(Span(start, end, start)) | ||
case None => | ||
val ch = text.charAt(idx) |
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.
case None if idx < text.length
should probably suffice
): SourcePosition = | ||
val realName = tree.name.stripModuleClassSuffix.lastPart.toString.toList | ||
|
||
def lookup( |
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.
Could it be @tailrec
?
9a39c5b
to
f03d20e
Compare
f03d20e
to
8427aeb
Compare
Fixes #3785