File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
compiler/src/dotty/tools/dotc/ast Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -895,7 +895,7 @@ object desugar {
895895 pats map {
896896 case id : Ident =>
897897 expandSimpleEnumCase(id.name.asTermName, mods,
898- Span (pdef .span.start, id.span.end, id.span.start))
898+ Span (id .span.start, id.span.end, id.span.start))
899899 }
900900 else {
901901 val pats1 = if (tpt.isEmpty) pats else pats map (Typed (_, tpt))
Original file line number Diff line number Diff line change @@ -354,7 +354,23 @@ object Trees {
354354 if (span.exists) {
355355 val point = span.point
356356 if (rawMods.is(Synthetic ) || name.toTermName == nme.ERROR ) Span (point)
357- else Span (point, point + name.stripModuleClassSuffix.lastPart.length, point)
357+ else {
358+ val realName = name.stripModuleClassSuffix.lastPart.toString
359+ val nameStart =
360+ if (point != span.start) point
361+ else {
362+ // Point might be too far away from start to be recorded. In this case we fall back to scanning
363+ // forwards from the start offset for the name.
364+ // Note: This might be inaccurate since scanning might hit accidentally the same
365+ // name (e.g. in a comment) before finding the real definition.
366+ // To make this behavior more robust we'd have to change the trees for definitions to contain
367+ // a fully positioned Ident in place of a name.
368+ val idx = source.content().indexOfSlice(realName, point)
369+ if (idx >= 0 ) idx
370+ else point // use `point` anyway. This is important if no source exists so scanning fails
371+ }
372+ Span (point, point + realName.length, point)
373+ }
358374 }
359375 else span
360376 }
You can’t perform that action at this time.
0 commit comments