Skip to content

Fix positions of enum cases #2722

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

Merged
merged 1 commit into from
Jun 13, 2017
Merged
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
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ object DesugarEnums {
val (tagMeth, scaffolding) = enumTagMeth(CaseKind.Object)
val impl1 = cpy.Template(impl)(body =
impl.body ++ List(tagMeth, toStringMeth) ++ registerCall)
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | Final).withPos(pos)
flatTree(scaffolding ::: vdef :: Nil).withPos(pos.startPos)
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | Final)
flatTree(scaffolding ::: vdef :: Nil).withPos(pos)
Copy link
Contributor

@odersky odersky Jun 10, 2017

Choose a reason for hiding this comment

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

Can you add an explanation how that makes a difference? I thought that the previous version would give pos to the actual value definition and startPos to scaffolding. Isn't that what we want?

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous version called withPos(pos.startPos) on the whole tree, since children positions have to be contained inside their parents positions, this means that the whole tree including vdef got position pos.startPos.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see now. There are some subtleties involved here.

}

/** Expand a simple enum case */
Expand All @@ -175,7 +175,7 @@ object DesugarEnums {
else {
val (tag, scaffolding) = nextEnumTag(CaseKind.Simple)
val creator = Apply(Ident(nme.DOLLAR_NEW), List(Literal(Constant(tag)), Literal(Constant(name.toString))))
val vdef = ValDef(name, enumClassRef, creator).withMods(mods | Final).withPos(pos)
flatTree(scaffolding ::: vdef :: Nil).withPos(pos.startPos)
val vdef = ValDef(name, enumClassRef, creator).withMods(mods | Final)
flatTree(scaffolding ::: vdef :: Nil).withPos(pos)
}
}