Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ object desugar {
pats map {
case id: Ident =>
expandSimpleEnumCase(id.name.asTermName, mods,
Span(pdef.span.start, id.span.end, id.span.start))
Span(id.span.start, id.span.end, id.span.start))
}
else {
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
Expand Down
18 changes: 17 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,23 @@ object Trees {
if (span.exists) {
val point = span.point
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Span(point)
else Span(point, point + name.stripModuleClassSuffix.lastPart.length, point)
else {
val realName = name.stripModuleClassSuffix.lastPart.toString
val nameStart =
if (point != span.start) point
else {
// Point might be too far away from start to be recorded. In this case we fall back to scanning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case that exercises this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test case was ErrorMessagesID, and I verified that the change here works for it. But c8265f1 fixes the problem by another means, so it's no longer a test case.

// forwards from the start offset for the name.
// Note: This might be inaccurate since scanning might hit accidentally the same
// name (e.g. in a comment) before finding the real definition.
// To make this behavior more robust we'd have to change the trees for definitions to contain
// a fully positioned Ident in place of a name.
val idx = source.content().indexOfSlice(realName, point)
if (idx >= 0) idx
else point // use `point` anyway. This is important if no source exists so scanning fails
}
Span(point, point + realName.length, point)
}
}
else span
}
Expand Down