Skip to content

Commit 887a63a

Browse files
committed
Make namePos a member of memberDef
That way it can be accessed by other parts which deal with error messages.
1 parent 992c72e commit 887a63a

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ object Trees {
297297
}
298298

299299
protected def setMods(mods: untpd.Modifiers) = myMods = mods
300+
301+
/** The position of the name defined by this definition.
302+
* This is a point position if the definition is synthetic, or a range position
303+
* if the definition comes from source.
304+
* It might also be that the definition does not have a position (for instance when synthesized by
305+
* a calling chain from `viewExists`), in that case the return position is NoPosition.
306+
*/
307+
def namePos =
308+
if (pos.exists)
309+
if (rawMods.is(Synthetic)) Position(pos.point, pos.point)
310+
else Position(pos.point, pos.point + name.length, pos.point)
311+
else pos
312+
313+
300314
}
301315

302316
/** A ValDef or DefDef tree */

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,10 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
731731
val mods =
732732
if (sym.annotations.isEmpty) untpd.EmptyModifiers
733733
else untpd.Modifiers(annotations = sym.annotations.map(_.tree))
734-
tree.withMods(mods) // record annotations in tree so that tree positions can be filled in.
734+
tree.withMods(mods)
735+
// record annotations in tree so that tree positions can be filled in.
736+
// Note: Once the inline PR with its changes to positions is in, this should be
737+
// no longer necessary.
735738
goto(end)
736739
setPos(start, tree)
737740
}

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,14 @@ class Namer { typer: Typer =>
274274

275275
val inSuperCall = if (ctx.mode is Mode.InSuperCall) InSuperCall else EmptyFlags
276276

277-
/** The position of the name defined by `tree`
278-
* This is a point position if tree is synthetic, a range position if it comes from source.
279-
* It might also be that tree does not have a position (for instance when synthesized by
280-
* a calling chain from `viewExists`), in that case the return position is NoPosition.
281-
*/
282-
def namePos(tree: MemberDef) =
283-
if (tree.pos.exists)
284-
if (tree.mods.is(Synthetic)) Position(tree.pos.point, tree.pos.point)
285-
else Position(tree.pos.point, tree.pos.point + tree.name.length, tree.pos.point)
286-
else tree.pos
287-
288277
tree match {
289278
case tree: TypeDef if tree.isClassDef =>
290279
val name = checkNoConflict(tree.name.encode).asTypeName
291280
val flags = checkFlags(tree.mods.flags &~ Implicit)
292281
val cls = recordSym(ctx.newClassSymbol(
293282
ctx.owner, name, flags | inSuperCall,
294283
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
295-
privateWithinClass(tree.mods), namePos(tree), ctx.source.file), tree)
284+
privateWithinClass(tree.mods), tree.namePos, ctx.source.file), tree)
296285
cls.completer.asInstanceOf[ClassCompleter].init()
297286
cls
298287
case tree: MemberDef =>
@@ -327,7 +316,7 @@ class Namer { typer: Typer =>
327316
recordSym(ctx.newSymbol(
328317
ctx.owner, name, flags | deferred | method | higherKinded | inSuperCall1,
329318
adjustIfModule(completer, tree),
330-
privateWithinClass(tree.mods), namePos(tree)), tree)
319+
privateWithinClass(tree.mods), tree.namePos), tree)
331320
case tree: Import =>
332321
recordSym(ctx.newSymbol(
333322
ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos), tree)

0 commit comments

Comments
 (0)