Skip to content

Commit 91afebf

Browse files
oderskynicolasstucki
authored andcommitted
atPos -> atSpan
1 parent a29c938 commit 91afebf

File tree

19 files changed

+39
-39
lines changed

19 files changed

+39
-39
lines changed

compiler/src/dotty/tools/backend/sjs/JSPositions.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import org.scalajs.ir
1111
class JSPositions()(implicit ctx: Context) {
1212

1313
/** Implicit conversion from dotty Position to ir.Position. */
14-
implicit def pos2irPos(pos: Span): ir.Position = {
15-
if (!pos.exists) ir.Position.NoPosition
14+
implicit def pos2irPos(span: Span): ir.Position = {
15+
if (!span.exists) ir.Position.NoPosition
1616
else {
1717
val source = pos2irPosCache.toIRSource(ctx.compilationUnit.source)
18-
val sourcePos = ctx.compilationUnit.source.atPos(pos)
18+
val sourcePos = ctx.compilationUnit.source.atSpan(span)
1919
// dotty positions are 1-based but IR positions are 0-based
2020
ir.Position(source, sourcePos.line-1, sourcePos.column-1)
2121
}
2222
}
2323

2424
/** Implicitly materializes an ir.Position from an implicit dotty Position. */
2525
implicit def implicitPos2irPos(
26-
implicit pos: Span): ir.Position = {
27-
pos2irPos(pos)
26+
implicit span: Span): ir.Position = {
27+
pos2irPos(span)
2828
}
2929

3030
private[this] object pos2irPosCache { // scalastyle:ignore

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object DesugarEnums {
5757
if (tparam.variance == 0) "is non variant"
5858
else "has bounds that depend on a type parameter in the same parameter list"
5959
errorType(i"""cannot determine type argument for enum parent $enumClass,
60-
|type parameter $tparam $problem""", ctx.source.atPos(pos))
60+
|type parameter $tparam $problem""", ctx.source.atSpan(pos))
6161
}
6262
}
6363
TypeTree(enumClass.typeRef.appliedTo(targs)).withSpan(pos)

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
3030

3131
protected def srcfile: AbstractFile = TreeIds.fileOfId(uniqueId)
3232
def source(implicit ctx: Context): SourceFile = ctx.getSource(srcfile)
33-
def sourcePos(implicit ctx: Context): SourcePosition = source.atPos(pos)
33+
def sourcePos(implicit ctx: Context): SourcePosition = source.atSpan(pos)
3434

3535
setId(TreeIds.nextIdFor(initialFile(src)))
3636
setPos(initialSpan(), srcfile)

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ object Comments {
125125
val newName = ctx.freshNames.newName(tree.name, NameKinds.DocArtifactName)
126126
tree.copy(name = newName)
127127
case _ =>
128-
ctx.error(ProperDefinitionNotFound(), ctx.source.atPos(codePos))
128+
ctx.error(ProperDefinitionNotFound(), ctx.source.atSpan(codePos))
129129
tree
130130
}
131131
}

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ object Decorators {
168168
implicit def sourcePos(pos: Span)(implicit ctx: Context): SourcePosition = {
169169
def recur(inlinedCalls: List[Tree], pos: Span): SourcePosition = inlinedCalls match {
170170
case inlinedCall :: rest =>
171-
sourceFile(inlinedCall).atPos(pos).withOuter(recur(rest, inlinedCall.pos))
171+
sourceFile(inlinedCall).atSpan(pos).withOuter(recur(rest, inlinedCall.pos))
172172
case empty =>
173-
ctx.source.atPos(pos)
173+
ctx.source.atSpan(pos)
174174
}
175175
recur(enclosingInlineds, pos)
176176
}

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ object Symbols {
680680
ctx.source
681681
else ctx.getSource(f)
682682
}
683-
source.atPos(pos)
683+
source.atSpan(pos)
684684
}
685685

686686
// ParamInfo types and methods

compiler/src/dotty/tools/dotc/interactive/SourceTree.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import util._, util.Spans._
1717
case class SourceTree(tree: tpd.Tree /** really: tpd.Import | tpd.NameTree */, source: SourceFile) {
1818

1919
/** The position of `tree` */
20-
final def pos(implicit ctx: Context): SourcePosition = source.atPos(tree.pos)
20+
final def pos(implicit ctx: Context): SourcePosition = source.atSpan(tree.pos)
2121

2222
/** The position of the name in `tree` */
2323
def namePos(implicit ctx: Context): SourcePosition = tree match {
@@ -43,7 +43,7 @@ case class SourceTree(tree: tpd.Tree /** really: tpd.Import | tpd.NameTree */, s
4343
(treePos.end - nameLength, treePos.end)
4444
Span(start, end, start)
4545
}
46-
source.atPos(position)
46+
source.atSpan(position)
4747
}
4848
case _ =>
4949
NoSourcePosition

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object Parsers {
103103
if (in.token == BACKQUOTED_IDENT) in.offset + 1 else in.offset
104104

105105
def sourcePos(off: Int = in.offset): SourcePosition =
106-
source.atPos(Span(off))
106+
source.atSpan(Span(off))
107107

108108
/* ------------- ERROR HANDLING ------------------------------------------- */
109109
/** The offset where the last syntax error was reported, or if a skip to a
@@ -125,7 +125,7 @@ object Parsers {
125125
* updating lastErrorOffset.
126126
*/
127127
def syntaxError(msg: => Message, pos: Span): Unit =
128-
ctx.error(msg, source atPos pos)
128+
ctx.error(msg, source.atSpan(pos))
129129
}
130130

131131
trait OutlineParserCommon extends ParserCommon {
@@ -263,14 +263,14 @@ object Parsers {
263263
ctx.warning(msg, sourcePos)
264264

265265
def warning(msg: => Message, offset: Int = in.offset): Unit =
266-
ctx.warning(msg, source atPos Span(offset))
266+
ctx.warning(msg, source.atSpan(Span(offset)))
267267

268268
def deprecationWarning(msg: => Message, offset: Int = in.offset): Unit =
269-
ctx.deprecationWarning(msg, source atPos Span(offset))
269+
ctx.deprecationWarning(msg, source.atSpan(Span(offset)))
270270

271271
/** Issue an error at current offset that input is incomplete */
272272
def incompleteInputError(msg: => Message): Unit =
273-
ctx.incompleteInputError(msg, source atPos Span(in.offset))
273+
ctx.incompleteInputError(msg, source.atSpan(Span(in.offset)))
274274

275275
/** If at end of file, issue an incompleteInputError.
276276
* Otherwise issue a syntax error and skip to next safe point.
@@ -349,7 +349,7 @@ object Parsers {
349349

350350
def migrationWarningOrError(msg: String, offset: Int = in.offset): Unit =
351351
if (in.isScala2Mode)
352-
ctx.migrationWarning(msg, source atPos Span(offset))
352+
ctx.migrationWarning(msg, source.atSpan(Span(offset)))
353353
else
354354
syntaxError(msg, offset)
355355

@@ -700,7 +700,7 @@ object Parsers {
700700
if (inPattern) Block(Nil, inBraces(pattern()))
701701
else expr()
702702
else {
703-
ctx.error(InterpolatedStringError(), source atPos Span(in.offset))
703+
ctx.error(InterpolatedStringError(), source.atSpan(Span(in.offset)))
704704
EmptyTree
705705
}
706706
})
@@ -1196,7 +1196,7 @@ object Parsers {
11961196
else {
11971197
if (handler.isEmpty) warning(
11981198
EmptyCatchAndFinallyBlock(body),
1199-
source atPos Span(tryOffset, endOffset(body))
1199+
source.atSpan(Span(tryOffset, endOffset(body)))
12001200
)
12011201
EmptyTree
12021202
}

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ object Scanners {
6666

6767
/** Generate an error at the given offset */
6868
def error(msg: String, off: Offset = offset): Unit = {
69-
ctx.error(msg, source atPos Span(off))
69+
ctx.error(msg, source atSpan Span(off))
7070
token = ERROR
7171
errOffset = off
7272
}
7373

7474
/** signal an error where the input ended in the middle of a token */
7575
def incompleteInputError(msg: String): Unit = {
76-
ctx.incompleteInputError(msg, source atPos Span(offset))
76+
ctx.incompleteInputError(msg, source atSpan Span(offset))
7777
token = EOF
7878
errOffset = offset
7979
}
@@ -246,7 +246,7 @@ object Scanners {
246246

247247
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
248248
def testScala2Mode(msg: String, pos: Span = Span(offset)): Boolean = {
249-
if (isScala2Mode) ctx.migrationWarning(msg, source atPos pos)
249+
if (isScala2Mode) ctx.migrationWarning(msg, source atSpan pos)
250250
isScala2Mode
251251
}
252252

compiler/src/dotty/tools/dotc/transform/Staging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class Staging extends MacroTransformWithImplicits {
449449
}
450450
else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
451451
val spliceCtx = ctx.outer // drop the last `inlineContext`
452-
val pos: SourcePosition = spliceCtx.source.atPos(enclosingInlineds.head.pos)
452+
val pos: SourcePosition = spliceCtx.source.atSpan(enclosingInlineds.head.pos)
453453
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx).withPosOf(splice)
454454
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice)
455455
}

compiler/src/dotty/tools/dotc/typer/Docstrings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object Docstrings {
3838
case List(df: tpd.DefDef) =>
3939
usecase.typed(df)
4040
case _ =>
41-
ctx.error("`@usecase` was not a valid definition", ctx.source.atPos(usecase.codePos))
41+
ctx.error("`@usecase` was not a valid definition", ctx.source.atSpan(usecase.codePos))
4242
usecase
4343
}
4444
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ trait Implicits { self: Typer =>
714714
def implicitArgTree(formal: Type, pos: Span)(implicit ctx: Context): Tree = {
715715
val arg = inferImplicitArg(formal, pos)
716716
if (arg.tpe.isInstanceOf[SearchFailureType])
717-
ctx.error(missingArgMsg(arg, formal, ""), ctx.source.atPos(pos))
717+
ctx.error(missingArgMsg(arg, formal, ""), ctx.source.atSpan(pos))
718718
arg
719719
}
720720

@@ -884,7 +884,7 @@ trait Implicits { self: Typer =>
884884
case altResult: SearchSuccess =>
885885
ctx.migrationWarning(
886886
s"According to new implicit resolution rules, this will be ambiguous:\n${result.reason.explanation}",
887-
ctx.source.atPos(pos))
887+
ctx.source.atSpan(pos))
888888
altResult
889889
case _ =>
890890
result
@@ -1125,7 +1125,7 @@ trait Implicits { self: Typer =>
11251125
|the search will fail with a global ambiguity error instead.
11261126
|
11271127
|Consider using the scala.implicits.Not class to implement similar functionality.""",
1128-
ctx.source.atPos(pos))
1128+
ctx.source.atSpan(pos))
11291129

11301130
/** A relation that imfluences the order in which implicits are tried.
11311131
* We prefer (in order of importance)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Namer { typer: Typer =>
248248
else {
249249
val cls = ctx.owner.enclosingClassNamed(name)
250250
if (!cls.exists)
251-
ctx.error(s"no enclosing class or object is named $name", ctx.source.atPos(pos))
251+
ctx.error(s"no enclosing class or object is named $name", ctx.source.atSpan(pos))
252252
cls
253253
}
254254
}

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ class RefChecks extends MiniPhase { thisPhase =>
959959
currentLevel.levelAndIndex.get(sym) match {
960960
case Some((level, symIdx)) if symIdx <= level.maxIndex =>
961961
ctx.error(ForwardReferenceExtendsOverDefinition(sym, level.refSym),
962-
ctx.source.atPos(level.refPos))
962+
ctx.source.atSpan(level.refPos))
963963
case _ =>
964964
}
965965
}
@@ -1005,7 +1005,7 @@ class RefChecks extends MiniPhase { thisPhase =>
10051005
// An implementation restriction to avoid VerifyErrors and lazyvals mishaps; see SI-4717
10061006
ctx.debuglog("refsym = " + level.refSym)
10071007
ctx.error("forward reference not allowed from self constructor invocation",
1008-
ctx.source.atPos(level.refPos))
1008+
ctx.source.atSpan(level.refPos))
10091009
}
10101010
}
10111011
tree

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ class Typer extends Namer
17131713
val pcls = (defn.ObjectClass /: parents)(improve)
17141714
typr.println(i"ensure first is class $parents%, % --> ${parents map (_ baseType pcls)}%, %")
17151715
val first = ctx.typeComparer.glb(defn.ObjectType :: parents.map(_.baseType(pcls)))
1716-
checkFeasibleParent(first, ctx.source.atPos(pos), em" in inferred superclass $first") :: parents
1716+
checkFeasibleParent(first, ctx.source.atSpan(pos), em" in inferred superclass $first") :: parents
17171717
}
17181718
}
17191719

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
6767
/** The start of this file in the underlying source file */
6868
def start: Int = 0
6969

70-
def atPos(pos: Span): SourcePosition =
70+
def atSpan(pos: Span): SourcePosition =
7171
if (pos.exists) SourcePosition(underlying, pos)
7272
else NoSourcePosition
7373

@@ -155,6 +155,6 @@ object SourceFile {
155155

156156
@sharable object NoSource extends SourceFile(NoAbstractFile, Array[Char]()) {
157157
override def exists: Boolean = false
158-
override def atPos(pos: Span): SourcePosition = NoSourcePosition
158+
override def atSpan(pos: Span): SourcePosition = NoSourcePosition
159159
}
160160

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class ReplCompiler extends Compiler {
244244
case _ => List(
245245
new messages.Error(
246246
s"Couldn't parse '$expr' to valid scala",
247-
sourceFile.atPos(Span(0, expr.length))
247+
sourceFile.atSpan(Span(0, expr.length))
248248
)
249249
).errors
250250
}
@@ -253,7 +253,7 @@ class ReplCompiler extends Compiler {
253253
def unwrapped(tree: tpd.Tree, sourceFile: SourceFile)(implicit ctx: Context): Result[tpd.ValDef] = {
254254
def error: Result[tpd.ValDef] =
255255
List(new messages.Error(s"Invalid scala expression",
256-
sourceFile.atPos(Span(0, sourceFile.content.length)))).errors
256+
sourceFile.atSpan(Span(0, sourceFile.content.length)))).errors
257257

258258
import tpd._
259259
tree match {

doc-tool/src/dotty/tools/dottydoc/staticsite/Template.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ case class LiquidTemplate(path: String, content: SourceFile) extends Template wi
6868
s"unexpected end of file, expected: '$expected'"
6969
else
7070
s"unexpected token '$unexpected', expected: '$expected'",
71-
content atPos Span(mm.index)
71+
content atSpan Span(mm.index)
7272
)
7373

7474
None

doc-tool/src/dotty/tools/dottydoc/util/syntax.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ object syntax {
2121

2222
implicit class SymbolExtensions(val sym: Symbol) extends AnyVal {
2323
def sourcePosition(pos: Span)(implicit ctx: Context): SourcePosition =
24-
ctx.getSource(sym.sourceFile).atPos(pos)
24+
ctx.getSource(sym.sourceFile).atSpan(pos)
2525
}
2626
}

0 commit comments

Comments
 (0)