diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-29 14:00:29 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-09-29 14:00:52 +0200 |
commit | 887a63a3dac0dcbaa7fc07ebb6ccac0dbe515427 (patch) | |
tree | f5c0addd467cbf0d6d1ce2ac456dee96cf763eaf | |
parent | 992c72ee5f2f105d587de20efd3858824fc7e7c8 (diff) | |
download | dotty-887a63a3dac0dcbaa7fc07ebb6ccac0dbe515427.tar.gz dotty-887a63a3dac0dcbaa7fc07ebb6ccac0dbe515427.tar.bz2 dotty-887a63a3dac0dcbaa7fc07ebb6ccac0dbe515427.zip |
Make namePos a member of memberDef
That way it can be accessed by other parts which deal with
error messages.
-rw-r--r-- | src/dotty/tools/dotc/ast/Trees.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 15 |
3 files changed, 20 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 619ac36e5..bb6fbd5ba 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -297,6 +297,20 @@ object Trees { } protected def setMods(mods: untpd.Modifiers) = myMods = mods + + /** The position of the name defined by this definition. + * This is a point position if the definition is synthetic, or a range position + * if the definition comes from source. + * It might also be that the definition does not have a position (for instance when synthesized by + * a calling chain from `viewExists`), in that case the return position is NoPosition. + */ + def namePos = + if (pos.exists) + if (rawMods.is(Synthetic)) Position(pos.point, pos.point) + else Position(pos.point, pos.point + name.length, pos.point) + else pos + + } /** A ValDef or DefDef tree */ diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 9d070e777..56bb8498a 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -731,7 +731,10 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { val mods = if (sym.annotations.isEmpty) untpd.EmptyModifiers else untpd.Modifiers(annotations = sym.annotations.map(_.tree)) - tree.withMods(mods) // record annotations in tree so that tree positions can be filled in. + tree.withMods(mods) + // record annotations in tree so that tree positions can be filled in. + // Note: Once the inline PR with its changes to positions is in, this should be + // no longer necessary. goto(end) setPos(start, tree) } diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index a0862ee38..cfd49fd87 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -274,17 +274,6 @@ class Namer { typer: Typer => val inSuperCall = if (ctx.mode is Mode.InSuperCall) InSuperCall else EmptyFlags - /** The position of the name defined by `tree` - * This is a point position if tree is synthetic, a range position if it comes from source. - * It might also be that tree does not have a position (for instance when synthesized by - * a calling chain from `viewExists`), in that case the return position is NoPosition. - */ - def namePos(tree: MemberDef) = - if (tree.pos.exists) - if (tree.mods.is(Synthetic)) Position(tree.pos.point, tree.pos.point) - else Position(tree.pos.point, tree.pos.point + tree.name.length, tree.pos.point) - else tree.pos - tree match { case tree: TypeDef if tree.isClassDef => val name = checkNoConflict(tree.name.encode).asTypeName @@ -292,7 +281,7 @@ class Namer { typer: Typer => val cls = recordSym(ctx.newClassSymbol( ctx.owner, name, flags | inSuperCall, cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree), - privateWithinClass(tree.mods), namePos(tree), ctx.source.file), tree) + privateWithinClass(tree.mods), tree.namePos, ctx.source.file), tree) cls.completer.asInstanceOf[ClassCompleter].init() cls case tree: MemberDef => @@ -327,7 +316,7 @@ class Namer { typer: Typer => recordSym(ctx.newSymbol( ctx.owner, name, flags | deferred | method | higherKinded | inSuperCall1, adjustIfModule(completer, tree), - privateWithinClass(tree.mods), namePos(tree)), tree) + privateWithinClass(tree.mods), tree.namePos), tree) case tree: Import => recordSym(ctx.newSymbol( ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos), tree) |