Skip to content

Make sure the span of EmptyTree and EmptyValDef are never set #5892

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 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,15 @@ object Trees {

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

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

@sharable val theEmptyTree: EmptyTree[Type] = new EmptyTree[Type]
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ object Parsers {
makeTypeDef(typeBounds())
case _ =>
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
EmptyTree
return EmptyTree // return to avoid setting the span to EmptyTree
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Staging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class Staging extends MacroTransform {
else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
val spliceCtx = ctx.outer // drop the last `inlineContext`
val pos: SourcePosition = spliceCtx.source.atSpan(enclosingInlineds.head.span)
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx).withSpan(splice.span)
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice)
val evaluatedSplice = Splicer.splice(splice.qualifier, pos, macroClassLoader)(spliceCtx)
if (ctx.reporter.hasErrors) splice else transform(evaluatedSplice.withSpan(splice.span))
}
else if (!ctx.owner.isInlineMethod) { // level 0 outside an inline method
ctx.error(i"splice outside quotes or inline method", splice.sourcePos)
Expand Down