Skip to content

Commit 2e53c9f

Browse files
committed
Abstract tasty positions
1 parent 06451fe commit 2e53c9f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

compiler/src/dotty/tools/dotc/tasty/TastyImpl.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object TastyImpl extends scala.tasty.Tasty {
3737
type Id = untpd.Ident
3838

3939
implicit def IdDeco(x: Id): AbstractId = new AbstractId {
40-
def pos(implicit ctx: Context): Position = new TastyPosition(x.pos)
40+
def pos(implicit ctx: Context): Position = x.pos
4141
}
4242

4343
def idClassTag: ClassTag[Id] = implicitly[ClassTag[Id]]
@@ -54,7 +54,7 @@ object TastyImpl extends scala.tasty.Tasty {
5454
type Tree = tpd.Tree
5555

5656
implicit def TreeDeco(t: Tree): AbstractTree = new AbstractTree {
57-
def pos(implicit ctx: Context): Position = new TastyPosition(t.pos)
57+
def pos(implicit ctx: Context): Position = t.pos
5858
}
5959

6060
type PackageClause = tpd.PackageDef
@@ -218,7 +218,7 @@ object TastyImpl extends scala.tasty.Tasty {
218218
type Term = tpd.Tree
219219

220220
implicit def TermDeco(t: Term): AbstractTerm = new AbstractTerm {
221-
def pos(implicit ctx: Context): Position = new TastyPosition(t.pos)
221+
def pos(implicit ctx: Context): Position = t.pos
222222
def tpe(implicit ctx: Context): Types.Type = t.tpe
223223
}
224224

@@ -398,7 +398,7 @@ object TastyImpl extends scala.tasty.Tasty {
398398
type Pattern = tpd.Tree
399399

400400
implicit def PatternDeco(x: Pattern): AbstractPattern = new AbstractPattern {
401-
def pos(implicit ctx: Context): Position = new TastyPosition(x.pos)
401+
def pos(implicit ctx: Context): Position = x.pos
402402
def tpe(implicit ctx: Context): Types.Type = x.tpe.stripTypeVar
403403
}
404404

@@ -458,7 +458,7 @@ object TastyImpl extends scala.tasty.Tasty {
458458
type TypeTree = tpd.Tree
459459

460460
implicit def TypeTreeDeco(x: TypeTree): AbstractTypeTree = new AbstractTypeTree {
461-
def pos(implicit ctx: Context): Position = new TastyPosition(x.pos)
461+
def pos(implicit ctx: Context): Position = x.pos
462462
def tpe(implicit ctx: Context): Types.Type = x.tpe.stripTypeVar
463463
}
464464

@@ -901,9 +901,11 @@ object TastyImpl extends scala.tasty.Tasty {
901901
}
902902

903903

904-
// ===== Private Methods ==========================================
904+
// ===== Positions ================================================
905905

906-
private class TastyPosition(val pos: SourcePosition) extends Position {
906+
type Position = SourcePosition
907+
908+
def PositionDeco(pos: Position): AbstractPosition = new AbstractPosition {
907909
def start = pos.start
908910
def end = pos.end
909911

@@ -914,7 +916,6 @@ object TastyImpl extends scala.tasty.Tasty {
914916

915917
def startColumn = pos.startColumn
916918
def endColumn = pos.endColumn
917-
918-
override def toString: String = s"Position(${pos.line}, ${pos.column})"
919919
}
920+
920921
}

library/src/scala/tasty/Tasty.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ abstract class Tasty {
687687

688688
// ===== Positions ================================================
689689

690-
trait Position {
690+
type Position
691+
692+
trait AbstractPosition {
691693
def start: Int
692694
def end: Int
693695

@@ -698,6 +700,7 @@ abstract class Tasty {
698700
def endLine: Int
699701
def endColumn: Int
700702
}
703+
implicit def PositionDeco(pos: Position): AbstractPosition
701704

702705
trait Positioned {
703706
def pos(implicit ctx: Context): Position

0 commit comments

Comments
 (0)