Skip to content

Simplify Source Positions #5713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 102 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
f21bd00
Rename nextId -> nextSymId in Context
odersky Dec 18, 2018
4e25176
Make nextTreeId counter a context field
odersky Dec 19, 2018
db6b9df
Adapt refelect.TreeOps to new scheme
odersky Dec 19, 2018
b2e17fd
@transientParam annotation
odersky Dec 19, 2018
75d338d
Apply @transientParam to compiler
odersky Dec 19, 2018
1a634c7
Produce tree ids in chunks
odersky Dec 19, 2018
c4ec3f6
Set source field of context directly
odersky Dec 19, 2018
e86057d
Make TreeCopiers preserve source
odersky Dec 19, 2018
6c13e88
Refactor getSource and withSource
odersky Dec 19, 2018
fc6daf0
Serialize source file changes
odersky Dec 20, 2018
3f938fb
Better caching of sources
odersky Dec 20, 2018
9e705e9
Allocate tree ids globally
odersky Dec 20, 2018
9abee3d
Follow source changes when unpickling
odersky Dec 21, 2018
945c296
Remove unpickleTypeTree
odersky Dec 23, 2018
c8454e5
Keep sourcefile info when pickling
odersky Dec 23, 2018
67786d0
Eliminate Decorators.sourcePos
odersky Dec 23, 2018
c85d707
Fix position of inline bodies in unpickler.
odersky Dec 25, 2018
eceeb1b
Lazy load contents of source position
odersky Dec 31, 2018
b62a156
Print full source positions in trees
odersky Dec 31, 2018
a68e776
Fix dropInlined
odersky Dec 31, 2018
36e0212
Check sources correspond under -Ytest-pickler
odersky Dec 31, 2018
b3ebfb2
Fix PositionPickler
odersky Dec 31, 2018
f0d1dfb
Make Inliner source-position aware
odersky Dec 31, 2018
3a23f4b
Fix Symbol#sourceFile
odersky Jan 1, 2019
6198884
Make PositionPickler work for shared trees
odersky Jan 1, 2019
7bb25bd
Make Modifiers not extend from Positioned
odersky Jan 2, 2019
4d3fa4a
Temporary hack to circumvent missing sourcefile info
odersky Jan 2, 2019
bae1f6b
Add source component to Positioned
odersky Jan 2, 2019
48f3367
Inliner tweaks
odersky Jan 2, 2019
7199965
withPos(Positioned) -> withPosOf
odersky Jan 3, 2019
cde9d60
Unpickler always takes source from context
odersky Jan 3, 2019
1b39bd0
withPos -> withSpan
odersky Jan 3, 2019
79eee51
Fix position pickler
odersky Jan 3, 2019
10a6db5
Harden IDE: Survive duplicate package and object
odersky Jan 3, 2019
8699aa7
Position -> Span
odersky Jan 3, 2019
2d7e819
Add missing check files
odersky Jan 3, 2019
50c3eef
Fix rebase breakage
odersky Jan 3, 2019
b136568
atPos -> atSpan
odersky Jan 3, 2019
a1a87d9
Rename SourcePos#pos -> SourcePos#span
odersky Jan 4, 2019
616bc85
Rename Span#pos -> Span#span
odersky Jan 4, 2019
f7c76c2
Rename Symbol#pos -> span, Comment#pos -> span
odersky Jan 4, 2019
7c99d35
Apply renamings to language server
odersky Jan 4, 2019
cc5e90c
Rename other uses of `pos` to `span`
odersky Jan 4, 2019
1404a4d
Polishings
odersky Jan 4, 2019
58d8fbc
Convert some checking methods to take Positioned arguments
odersky Jan 4, 2019
baf7dc1
Simplify Parser
odersky Jan 4, 2019
18eaae0
Fix rebase breakage
odersky Jan 6, 2019
b1462cc
Add missing source to context
nicolasstucki Jan 5, 2019
7d87656
Add missing contents to vitual files
nicolasstucki Jan 5, 2019
3de898e
Avoid memoization of virtual source files with same path
nicolasstucki Jan 5, 2019
bf6af32
Use non-virtual files in dottydoc tests
nicolasstucki Jan 6, 2019
e160073
Update test to use Spans
nicolasstucki Jan 6, 2019
57954c4
Update missing `pos` to `span`
nicolasstucki Jan 6, 2019
a8adf1b
Update implicit modifier test
nicolasstucki Jan 7, 2019
220a5fd
Add missing spans in closures
nicolasstucki Jan 7, 2019
ec322f6
Comment debug assertion
nicolasstucki Jan 7, 2019
f8be33f
Remove unnecessary workaround for repl
nicolasstucki Jan 7, 2019
14911e1
Fix rebase breakage
odersky Jan 9, 2019
70b5819
Avoid creating source positions in backend interface
odersky Jan 7, 2019
72a8765
Optimize computation of Sourcefile#content
odersky Jan 7, 2019
a22c366
Make SourceFile equals depend on file
odersky Jan 9, 2019
4cf02c5
Optimize equals + hashCode on PlainFile
odersky Jan 9, 2019
77b4b4c
Reduce concurrent hashmap lookups
odersky Jan 9, 2019
b915632
Refactor SourceFile operations
odersky Jan 9, 2019
e7c1d20
Optimize PlainFile.equals
odersky Jan 10, 2019
94b4b01
Implement -Ydebug-pos
odersky Jan 10, 2019
e021019
Revise PositionPickler
odersky Jan 10, 2019
570e95c
Fix rebase breakage
odersky Jan 10, 2019
a44d43f
Optimize initialPos in Positioned
odersky Jan 10, 2019
819f20f
Optimize SourceFile.fromId
odersky Jan 11, 2019
aabdc75
Optimize Symbol#source
odersky Jan 11, 2019
f740996
Use SourceFile implicits instead of SourceInfo
odersky Jan 11, 2019
a448629
Make virtual source files explicit
nicolasstucki Jan 14, 2019
fa3b4b9
Sourcefile refactoring
odersky Jan 14, 2019
729a3d1
Don't read contents when creating a source file
odersky Jan 14, 2019
ed45da0
Drop withPosOf and withSourcePos
odersky Jan 13, 2019
decc730
Don't ask defTree for Symbol's source after erasure
odersky Jan 15, 2019
1771a16
Fix diagnostics breakage
odersky Jan 15, 2019
17a901a
Simplify source positions
odersky Jan 15, 2019
fe2d3ae
Improve pickling of holes
odersky Jan 15, 2019
953a6b1
Avoid special cases in Positioned#envelope
odersky Jan 15, 2019
7100da8
Compare sourcefiles structurally
odersky Jan 15, 2019
7fa7a06
Add missing spans in Desugar
nicolasstucki Jan 16, 2019
e110858
Fixes after rebase
nicolasstucki Jan 16, 2019
c2acbf0
Add missing span for tab complete
nicolasstucki Jan 16, 2019
e2966a9
Add another missing span
nicolasstucki Jan 16, 2019
3558cb8
Inferred TypedSplice spans
nicolasstucki Jan 16, 2019
dec6b95
Use the same virtual file for parsing and compiling in REPL
nicolasstucki Jan 16, 2019
8e12771
Use the index in the repl state for the line module
nicolasstucki Jan 16, 2019
607ac1b
Revert "Add missing spans in Desugar"
nicolasstucki Jan 17, 2019
791eb2b
Add missing span when expanding FunctionAppliedTo
nicolasstucki Jan 17, 2019
cac4e18
Update to compile with latest master
odersky Jan 18, 2019
2244eb1
Add missing span when expanding FunctionAppliedTo
nicolasstucki Jan 18, 2019
4ef3cea
Optimization: change Array.copy to System.arrayCopy
odersky Jan 18, 2019
21b3904
Rename Parser.atPos -> atSpan
odersky Jan 18, 2019
360510c
Track source changes in TreeMap and TreeAccumulator
odersky Jan 18, 2019
829acf0
Address other review comments
odersky Jan 18, 2019
9fa170c
Rename transientParam -> constructorOnly
odersky Jan 18, 2019
8d3b7ef
Address overlooked comment
odersky Jan 18, 2019
652b570
Drop unnecessary compatibility hack
odersky Jan 18, 2019
570b26f
Talk consistently about spans in Parser
odersky Jan 18, 2019
fc2e654
Address more review comments
odersky Jan 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename Span#pos -> Span#span
Also, related uses of `pos` local variables are renamed to `span`.
  • Loading branch information
odersky committed Jan 18, 2019
commit 616bc851a0ff7b097be9ba07e3e65972bd39eb72
60 changes: 30 additions & 30 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class JSCodeGen()(implicit ctx: Context) {
* Other (normal) methods are emitted with `genMethodBody()`.
*/
private def genMethodWithCurrentLocalNameScope(dd: DefDef): Option[js.MethodDef] = {
implicit val pos = dd.pos
implicit val pos = dd.span
val sym = dd.symbol
val vparamss = dd.vparamss
val rhs = dd.rhs
Expand Down Expand Up @@ -579,7 +579,7 @@ class JSCodeGen()(implicit ctx: Context) {
private def genMethodDef(static: Boolean, methodName: js.PropertyName,
paramsSyms: List[Symbol], resultIRType: jstpe.Type,
tree: Tree, optimizerHints: OptimizerHints): js.MethodDef = {
implicit val pos = tree.pos
implicit val pos = tree.span

ctx.debuglog("genMethod " + methodName.encodedName)
ctx.debuglog("")
Expand All @@ -598,7 +598,7 @@ class JSCodeGen()(implicit ctx: Context) {
js.MethodDef(static, methodName, jsParams, resultIRType, Some(genBody()))(
optimizerHints, None)
/*} else {
assert(!static, tree.pos)
assert(!static, tree.span)

withScopedVars(
thisLocalVarIdent := Some(freshLocalIdent("this"))
Expand Down Expand Up @@ -639,7 +639,7 @@ class JSCodeGen()(implicit ctx: Context) {
private def genExpr(tree: Tree): js.Tree = {
val result = genStatOrExpr(tree, isStat = false)
assert(result.tpe != jstpe.NoType,
s"genExpr($tree) returned a tree with type NoType at pos ${tree.pos}")
s"genExpr($tree) returned a tree with type NoType at pos ${tree.span}")
result
}

Expand All @@ -649,7 +649,7 @@ class JSCodeGen()(implicit ctx: Context) {
* is transformed into an equivalent portion of the JS AST.
*/
private def genStatOrExpr(tree: Tree, isStat: Boolean): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

ctx.debuglog(" " + tree)
ctx.debuglog("")
Expand All @@ -660,7 +660,7 @@ class JSCodeGen()(implicit ctx: Context) {
/* Must have been eliminated by the tail call transform performed
* by genMethodBody(). */
assert(name != nme.THIS,
s"ValDef(_, nme.THIS, _, _) found at ${tree.pos}")
s"ValDef(_, nme.THIS, _, _) found at ${tree.span}")

val sym = tree.symbol
val rhs = tree.rhs
Expand Down Expand Up @@ -719,7 +719,7 @@ class JSCodeGen()(implicit ctx: Context) {
"Trying to access the this of another class: " +
"tree.symbol = " + tree.symbol +
", class symbol = " + currentClassSym.get +
" pos:" + pos)
" span:" + pos)
genLoadModule(tree.symbol)
}

Expand Down Expand Up @@ -856,7 +856,7 @@ class JSCodeGen()(implicit ctx: Context) {

case _ =>
throw new FatalError("Unexpected tree in genExpr: " +
tree + "/" + tree.getClass + " at: " + (tree.pos: Position))
tree + "/" + tree.getClass + " at: " + (tree.span: Position))
}
} // end of genStatOrExpr()

Expand Down Expand Up @@ -897,7 +897,7 @@ class JSCodeGen()(implicit ctx: Context) {
* primitives, JS calls, etc. They are further dispatched in here.
*/
private def genApply(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span
val args = tree.args
val sym = tree.fun.symbol

Expand Down Expand Up @@ -944,7 +944,7 @@ class JSCodeGen()(implicit ctx: Context) {
* irrelevant.
*/
private def genSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span
val Apply(fun @ Select(sup @ Super(_, mix), _), args) = tree
val sym = fun.symbol

Expand All @@ -955,7 +955,7 @@ class JSCodeGen()(implicit ctx: Context) {
genJSSuperCall(tree, isStat)
} else*/ {
val superCall = genApplyMethodStatically(
genThis()(sup.pos), sym, genActualArgs(sym, args))
genThis()(sup.span), sym, genActualArgs(sym, args))

// Initialize the module instance just after the super constructor call.
if (isStaticModule(currentClassSym) && !isModuleInitialized &&
Expand All @@ -980,7 +980,7 @@ class JSCodeGen()(implicit ctx: Context) {
* * regular new
*/
private def genApplyNew(tree: Apply): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
val ctor = fun.symbol
Expand Down Expand Up @@ -1038,7 +1038,7 @@ class JSCodeGen()(implicit ctx: Context) {
private def genPrimitiveOp(tree: Apply, isStat: Boolean): js.Tree = {
import scala.tools.nsc.backend.ScalaPrimitivesOps._

implicit val pos = tree.pos
implicit val pos = tree.span

val Apply(fun, args) = tree
val receiver = qualifierOf(fun)
Expand Down Expand Up @@ -1078,7 +1078,7 @@ class JSCodeGen()(implicit ctx: Context) {
private def genSimpleUnaryOp(tree: Apply, arg: Tree, code: Int): js.Tree = {
import scala.tools.nsc.backend.ScalaPrimitivesOps._

implicit val pos = tree.pos
implicit val pos = tree.span

val resultIRType = toIRType(tree.tpe)
val genArg = adaptPrimitive(genExpr(arg), resultIRType)
Expand Down Expand Up @@ -1120,7 +1120,7 @@ class JSCodeGen()(implicit ctx: Context) {
import scala.tools.nsc.backend.ScalaPrimitivesOps._
import js.UnaryOp._

implicit val pos = tree.pos
implicit val pos = tree.span

val lhsIRType = toIRType(lhs.tpe)
val rhsIRType = toIRType(rhs.tpe)
Expand Down Expand Up @@ -1423,7 +1423,7 @@ class JSCodeGen()(implicit ctx: Context) {
*/
private def genStringConcat(tree: Apply, receiver: Tree,
args: List[Tree]): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val arg = args.head

Expand All @@ -1450,7 +1450,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen JS code for a call to Any.## */
private def genScalaHash(tree: Apply, receiver: Tree): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

genModuleApplyMethod(defn.ScalaRuntimeModule.requiredMethod(nme.hash_),
List(genExpr(receiver)))
Expand All @@ -1460,7 +1460,7 @@ class JSCodeGen()(implicit ctx: Context) {
private def genArrayOp(tree: Tree, code: Int): js.Tree = {
import scala.tools.nsc.backend.ScalaPrimitivesOps._

implicit val pos = tree.pos
implicit val pos = tree.span

val Apply(fun, args) = tree
val arrayObj = qualifierOf(fun)
Expand Down Expand Up @@ -1512,7 +1512,7 @@ class JSCodeGen()(implicit ctx: Context) {
// common case for which there is no side-effect nor NPE
genArg
case _ =>
implicit val pos = tree.pos
implicit val pos = tree.span
/* TODO Check for a null receiver?
* In theory, it's UB, but that decision should be left for link time.
*/
Expand All @@ -1522,7 +1522,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen JS code for a coercion */
private def genCoercion(tree: Apply, receiver: Tree, code: Int): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val source = genExpr(receiver)
val resultType = toIRType(tree.tpe)
Expand All @@ -1531,7 +1531,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen a call to the special `throw` method. */
private def genThrow(tree: Apply, args: List[Tree]): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span
val exception = args.head
val genException = genExpr(exception)
js.Throw {
Expand All @@ -1555,7 +1555,7 @@ class JSCodeGen()(implicit ctx: Context) {
* * Regular method call
*/
private def genNormalApply(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val fun = tree.fun match {
case fun: Ident => desugarIdent(fun).get
Expand Down Expand Up @@ -1601,7 +1601,7 @@ class JSCodeGen()(implicit ctx: Context) {
jsSuperClassValue: Option[js.Tree] = None)(
implicit pos: Position): js.Tree = {

implicit val pos = tree.pos
implicit val pos = tree.span

def noSpread = !args.exists(_.isInstanceOf[js.JSSpread])
val argc = args.size // meaningful only for methods that don't have varargs
Expand Down Expand Up @@ -1759,7 +1759,7 @@ class JSCodeGen()(implicit ctx: Context) {
* primitive instead.)
*/
private def genTypeApply(tree: TypeApply): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val TypeApply(fun, targs) = tree

Expand Down Expand Up @@ -1787,7 +1787,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen JS code for a Java Seq literal. */
private def genJavaSeqLiteral(tree: JavaSeqLiteral): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span

val genElems = tree.elems.map(genExpr)
val arrayTypeRef = toTypeRef(tree.tpe).asInstanceOf[jstpe.ArrayTypeRef]
Expand Down Expand Up @@ -1836,7 +1836,7 @@ class JSCodeGen()(implicit ctx: Context) {
* available in the `body`.
*/
private def genClosure(tree: Closure): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span
val Closure(env, call, functionalInterface) = tree

val envSize = env.size
Expand All @@ -1852,7 +1852,7 @@ class JSCodeGen()(implicit ctx: Context) {
val allCaptureValues = qualifier :: env

val formalAndActualCaptures = allCaptureValues.map { value =>
implicit val pos = value.pos
implicit val pos = value.span
val formalIdent = value match {
case Ident(name) => freshLocalIdent(name.toString)
case This(_) => freshLocalIdent("this")
Expand Down Expand Up @@ -1975,7 +1975,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen JS code for an isInstanceOf test (for reference types only) */
private def genIsInstanceOf(tree: Tree, value: js.Tree, to: Type): js.Tree = {
implicit val pos = tree.pos
implicit val pos = tree.span
val sym = to.widenDealias.typeSymbol

if (sym == defn.ObjectClass) {
Expand Down Expand Up @@ -2193,7 +2193,7 @@ class JSCodeGen()(implicit ctx: Context) {
* to perform the conversion to js.Array, then wrap in a Spread
* operator.
*/
implicit val pos = arg.pos
implicit val pos = arg.span
val jsArrayArg = genModuleApplyMethod(
jsdefn.Runtime_toJSVarArgs,
List(genExpr(arg)))
Expand All @@ -2210,7 +2210,7 @@ class JSCodeGen()(implicit ctx: Context) {
*/
private def tryGenRepeatedParamAsJSArray(arg: Tree,
handleNil: Boolean): Option[List[js.Tree]] = {
implicit val pos = arg.pos
implicit val pos = arg.span

// Given a method `def foo(args: T*)`
arg match {
Expand Down
26 changes: 13 additions & 13 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ object desugar {
val constrVparamss =
if (originalVparamss.isEmpty) { // ensure parameter list is non-empty
if (isCaseClass && originalTparams.isEmpty)
ctx.error(CaseClassMissingParamList(cdef), cdef.sourcePos.withSpan(cdef.namePos))
ctx.error(CaseClassMissingParamList(cdef), cdef.sourcePos.withSpan(cdef.nameSpan))
ListOfNil
} else if (isCaseClass && originalVparamss.head.exists(_.mods.is(Implicit))) {
ctx.error("Case classes should have a non-implicit parameter list", cdef.sourcePos.withSpan(cdef.namePos))
ctx.error("Case classes should have a non-implicit parameter list", cdef.sourcePos.withSpan(cdef.nameSpan))
ListOfNil
}
else originalVparamss.nestedMap(toDefParam)
Expand Down Expand Up @@ -398,7 +398,7 @@ object desugar {

def appliedTypeTree(tycon: Tree, args: List[Tree]) =
(if (args.isEmpty) tycon else AppliedTypeTree(tycon, args))
.withSpan(cdef.pos.startPos)
.withSpan(cdef.span.startPos)

def isHK(tparam: Tree): Boolean = tparam match {
case TypeDef(_, LambdaTypeTree(tparams, body)) => true
Expand Down Expand Up @@ -704,19 +704,19 @@ object desugar {
if (mods is Package)
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
else if (isEnumCase)
expandEnumModule(moduleName, impl, mods, mdef.pos)
expandEnumModule(moduleName, impl, mods, mdef.span)
else {
val clsName = moduleName.moduleClassName
val clsRef = Ident(clsName)
val modul = ValDef(moduleName, clsRef, New(clsRef, Nil))
.withMods(mods.toTermFlags & RetainedModuleValFlags | ModuleValCreationFlags)
.withSpan(mdef.pos.startPos)
.withSpan(mdef.span.startPos)
val ValDef(selfName, selfTpt, _) = impl.self
val selfMods = impl.self.mods
if (!selfTpt.isEmpty) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.sourcePos)
val clsSelf = ValDef(selfName, SingletonTypeTree(Ident(moduleName)), impl.self.rhs)
.withMods(selfMods)
.withSpan(impl.self.pos.orElse(impl.pos.startPos))
.withSpan(impl.self.span.orElse(impl.span.startPos))
val clsTmpl = cpy.Template(impl)(self = clsSelf, body = impl.body)
val cls = TypeDef(clsName, clsTmpl)
.withMods(mods.toTypeFlags & RetainedModuleClassFlags | ModuleClassCreationFlags)
Expand Down Expand Up @@ -793,7 +793,7 @@ object desugar {
pats map {
case id: Ident =>
expandSimpleEnumCase(id.name.asTermName, mods,
Span(pdef.pos.start, id.pos.end, id.pos.start))
Span(pdef.span.start, id.span.end, id.span.start))
}
else {
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
Expand Down Expand Up @@ -842,7 +842,7 @@ object desugar {
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags)
val firstDef =
ValDef(tmpName, TypeTree(), matchExpr)
.withSpan(pat.pos.union(rhs.pos)).withMods(patMods)
.withSpan(pat.span.union(rhs.span)).withMods(patMods)
def selector(n: Int) = Select(Ident(tmpName), nme.selectorName(n))
val restDefs =
for (((named, tpt), n) <- vars.zipWithIndex)
Expand Down Expand Up @@ -879,7 +879,7 @@ object desugar {
def block(tree: Block)(implicit ctx: Context): Block = tree.expr match {
case EmptyTree =>
cpy.Block(tree)(tree.stats,
unitLiteral.withSpan(if (tree.stats.isEmpty) tree.pos else tree.pos.endPos))
unitLiteral.withSpan(if (tree.stats.isEmpty) tree.span else tree.span.endPos))
case _ =>
tree
}
Expand All @@ -904,9 +904,9 @@ object desugar {
}

if (isLeftAssoc(op.name))
makeOp(left, right, Span(left.pos.start, op.pos.end, op.pos.start))
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
else
makeOp(right, left, Span(op.pos.start, right.pos.end))
makeOp(right, left, Span(op.span.start, right.span.end))
}

/** Translate tuple expressions of arity <= 22
Expand Down Expand Up @@ -1021,15 +1021,15 @@ object desugar {
private def derivedValDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(implicit ctx: Context) = {
val vdef = ValDef(named.name.asTermName, tpt, rhs)
.withMods(mods)
.withSpan(original.pos.withPoint(named.pos.start))
.withSpan(original.span.withPoint(named.span.start))
val mayNeedSetter = valDef(vdef)
mayNeedSetter
}

private def derivedDefDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(implicit src: SourceInfo) =
DefDef(named.name.asTermName, Nil, Nil, tpt, rhs)
.withMods(mods)
.withSpan(original.pos.withPoint(named.pos.start))
.withSpan(original.span.withPoint(named.span.start))

/** Main desugaring method */
def apply(tree: Tree)(implicit ctx: Context): Tree = {
Expand Down
Loading