aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-24 13:50:27 +0200
committerMartin Odersky <odersky@gmail.com>2016-09-24 15:40:49 +0200
commitfb710457959d1c2d4b983986141875a8fde5992b (patch)
tree18883c09f001538303175148ecc3e50fee99d7c3 /src/dotty/tools/dotc/typer/Namer.scala
parent003ea0fba7d37156d890e0dae90f2ce765b08e04 (diff)
downloaddotty-fb710457959d1c2d4b983986141875a8fde5992b.tar.gz
dotty-fb710457959d1c2d4b983986141875a8fde5992b.tar.bz2
dotty-fb710457959d1c2d4b983986141875a8fde5992b.zip
Make positions fit for meta
In particular: - get rid of envelope, it's too complicated and hides too many errors - check that everywhere in parsed trees the position range of a parent node contains the position ranges of its children. - check that all non-empty trees coming from parser have positions. The commit contains lots of fixes to make these checks pass. In particular, it changes the scheme how definitions are positioned. Previously the position of a definition was the token range of the name defined by it. That does obviously not work with the parent/children invariant. Now, the position is the whole definition range, with the point at the defined name (care is taken to not count backticks). Namer is changed to still use the token range of defined name as the position of the symbol.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 7a2348cd3..a0862ee38 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -273,6 +273,18 @@ 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
@@ -280,7 +292,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), tree.pos, ctx.source.file), tree)
+ privateWithinClass(tree.mods), namePos(tree), ctx.source.file), tree)
cls.completer.asInstanceOf[ClassCompleter].init()
cls
case tree: MemberDef =>
@@ -315,7 +327,7 @@ class Namer { typer: Typer =>
recordSym(ctx.newSymbol(
ctx.owner, name, flags | deferred | method | higherKinded | inSuperCall1,
adjustIfModule(completer, tree),
- privateWithinClass(tree.mods), tree.pos), tree)
+ privateWithinClass(tree.mods), namePos(tree)), tree)
case tree: Import =>
recordSym(ctx.newSymbol(
ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos), tree)