Skip to content

Commit 9f86c88

Browse files
authored
Merge pull request #5892 from dotty-staging/fix-position-of-empty-tree
Make sure the span of EmptyTree and EmptyValDef are never set
2 parents 89a87d3 + 48ee86e commit 9f86c88

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,15 @@ object Trees {
820820

821821
class EmptyTree[T >: Untyped] extends Thicket(Nil)(NoSource) {
822822
// assert(uniqueId != 1492)
823+
override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyTree")
823824
}
824825

825826
class EmptyValDef[T >: Untyped] extends ValDef[T](
826827
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T])(NoSource) with WithoutTypeOrPos[T] {
827828
myTpe = NoType.asInstanceOf[T]
828-
override def isEmpty: Boolean = true
829829
setMods(untpd.Modifiers(PrivateLocal))
830+
override def isEmpty: Boolean = true
831+
override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyValDef")
830832
}
831833

832834
@sharable val theEmptyTree: EmptyTree[Type] = new EmptyTree[Type]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ object Parsers {
24192419
makeTypeDef(typeBounds())
24202420
case _ =>
24212421
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
2422-
EmptyTree
2422+
return EmptyTree // return to avoid setting the span to EmptyTree
24232423
}
24242424
}
24252425
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ class Staging extends MacroTransform {
144144
else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
145145
val spliceCtx = ctx.outer // drop the last `inlineContext`
146146
val pos: SourcePosition = spliceCtx.source.atSpan(enclosingInlineds.head.span)
147-
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx).withSpan(splice.span)
148-
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice)
147+
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx)
148+
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice.withSpan(splice.span))
149149
}
150150
else if (!ctx.owner.isInlineMethod) { // level 0 outside an inline method
151151
ctx.error(i"splice outside quotes or inline method", splice.sourcePos)

0 commit comments

Comments
 (0)