File tree 2 files changed +18
-2
lines changed
compiler/src/dotty/tools/dotc/ast
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -895,7 +895,7 @@ object desugar {
895
895
pats map {
896
896
case id : Ident =>
897
897
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))
899
899
}
900
900
else {
901
901
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 {
354
354
if (span.exists) {
355
355
val point = span.point
356
356
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
+ }
358
374
}
359
375
else span
360
376
}
You can’t perform that action at this time.
0 commit comments