Skip to content

Commit 4eb58a7

Browse files
committed
Make sure the span of EmptyTree and EmptyValDef are never set
1 parent 036ab3b commit 4eb58a7

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
113113

114114
/** Clone this node but assign it a fresh id which marks it as a node in `file`. */
115115
def cloneIn(src: SourceFile): this.type = {
116-
assert(this ne tpd.EmptyTree)
117-
assert(this ne tpd.EmptyValDef)
118-
assert(this ne tpd.ContextualEmptyTree)
119116
val newpd: this.type = clone.asInstanceOf[this.type]
120117
newpd.uniqueId = src.nextId
121118
newpd

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

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

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

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ class Staging extends MacroTransformWithImplicits {
448448
else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
449449
val spliceCtx = ctx.outer // drop the last `inlineContext`
450450
val pos: SourcePosition = spliceCtx.source.atSpan(enclosingInlineds.head.span)
451-
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx).withSpan(splice.span)
452-
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice)
451+
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx)
452+
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice.withSpan(splice.span))
453453
}
454454
else if (!ctx.owner.isInlineMethod) { // level 0 outside an inline method
455455
ctx.error(i"splice outside quotes or inline method", splice.sourcePos)

0 commit comments

Comments
 (0)