Skip to content

Commit

Permalink
bugfix: Add checks if span exists
Browse files Browse the repository at this point in the history
For scalameta#4837

There are some other places that access span, but most of them seem safe.
  • Loading branch information
tgodzik committed Jan 25, 2023
1 parent 6dc5828 commit 6f095a4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ abstract class PcCollector[T](driver: InteractiveDriver, params: OffsetParams):
.Try(named.symbol.owner)
.toOption
.exists(_.isAnonymousFunction) &&
owners.exists(_.span.point == named.symbol.owner.span.point)
owners.exists(o =>
o.span.exists && o.span.point == named.symbol.owner.span.point
)

def soughtOrOverride(sym: Symbol) =
sought(sym) || sym.allOverriddenSymbols.exists(sought(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object CompletionPos:
head match
case i: Ident => i.sourcePos.point
case s: Select =>
if s.name.toTermName == nme.ERROR || pos.span.point < s.span.point
if s.name.toTermName == nme.ERROR || s.span.exists && pos.span.point < s.span.point
then fallback
else s.span.point
case Import(_, sel) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ object InterpolatorCompletions:

val qualType = for
parent <- path.tail.headOption.toList
if text.charAt(lit.span.point - 1) != '}'
if lit.span.exists && text.charAt(lit.span.point - 1) != '}'
identOrSelect <- path
.collectFirst(interpolatorMemberArg(lit, parent))
.flatten
Expand Down Expand Up @@ -242,7 +242,6 @@ object InterpolatorCompletions:
)(using ctx: Context): List[CompletionValue] =

val text = position.source.content().mkString
val offset: Int = position.span.point
val span = position.span
val nameStart =
span.withStart(span.start - interpolator.name.size)
Expand Down

0 comments on commit 6f095a4

Please sign in to comment.