Skip to content

nameSpan is incorrect for backquoted names with escaped characters #16234

Open
@TheElectronWill

Description

@TheElectronWill

Compiler version

3.2.1-RC2

Minimized code

def `\r\n`() = ()

Output

val methodDef: DefDef = ... // get the DefDef of the method
val namePos = methodDef.namePos
println(namePos.span)
[45..47] // the span is only 2 chars long

The span is wrong because Trees#nameSpan computes the span's end from realName.length, but since the characters were escaped the count is wrong.

This is annoying for coverage reports, where namePos is used to "highlight" the method name in the coverage report.

Expectation

The correct span should match the original source, thus it should be [45..49] (not sure whether the quotes should be included or not).
The Parser produces an Ident with the correct span (here, I think), could this be used instead?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions