Skip to content

Commit

Permalink
Fix the ContextLocation toString that was broken by 8253738
Browse files Browse the repository at this point in the history
  • Loading branch information
dylemma committed May 9, 2021
1 parent 7152843 commit 52a6c18
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions core/src/main/scala/io/dylemma/spac/ContextTrace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ object ContextTrace {
*/
trait ContextLocation {
def get[A](tag: ContextLocation.Tag[A]): Option[A]

protected def tagsForToString: Iterable[ContextLocation.Tag[_]] = List(
ContextLocation.Tag.LineNumber,
ContextLocation.Tag.ColumnOffset,
ContextLocation.Tag.CharOffset,
)

override def toString = {
val entries = for {
tag <- tagsForToString.iterator
value <- get(tag)
} yield s"${tag.name}: $value"

if (entries.isEmpty) "{ <unknown location> }"
else entries.mkString("{", ", ", "}")
}
}

/**
Expand All @@ -39,10 +55,7 @@ object ContextLocation {
private class ContextLocationImpl(val dimensions: Map[ContextLocation.Tag[_], Any]) extends ContextLocation {
def get[A](tag: ContextLocation.Tag[A]): Option[A] = dimensions.get(tag).map(_.asInstanceOf[A])

override def toString = {
if (dimensions.isEmpty) "{ <unknown location> }"
else dimensions.view.map { case (k, v) => s"${ k.name }: $v" }.mkString("{", ", ", "}")
}
override def tagsForToString: Iterable[Tag[_]] = dimensions.keys
}

abstract class Tag[A](val name: String) {
Expand Down

0 comments on commit 52a6c18

Please sign in to comment.