Skip to content

Commit

Permalink
Allowing message annotations on any offending node
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed Nov 8, 2024
1 parent 133264d commit f77c1b8
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/main/scala/viper/silver/verifier/VerificationError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,23 @@ sealed abstract class AbstractVerificationError extends VerificationError {

def pos = offendingNode.pos

def readableMessage(withId: Boolean, withPosition: Boolean) = {
val customMessageAnnotation = "msg"

def customErrorMessage = offendingNode match {
case i: Infoed => i.info.getUniqueInfo[AnnotationInfo] match {
case Some(ai) if ai.values.contains(customMessageAnnotation) && ai.values(customMessageAnnotation).nonEmpty =>
Some(ai.values("msg").head)
case _ => None
}
case _ => None
}

def readableMessage(withId: Boolean, withPosition: Boolean) = customErrorMessage match {
case Some(msg) => msg
case _ => defaultReadableMessage(withId, withPosition)
}

def defaultReadableMessage(withId: Boolean, withPosition: Boolean) = {
val idStr = if (withId) s"[$fullId] " else ""
val posStr = if (withPosition) s" ($pos)" else ""

Expand Down Expand Up @@ -399,20 +415,18 @@ object errors {
val id = "assert.failed"
val text = "Assert might fail."

val customMessageAnnotation = "msg"

def customErrorMessage = offendingNode.info.getUniqueInfo[AnnotationInfo] match {
def customAssertErrorMessage = offendingNode.info.getUniqueInfo[AnnotationInfo] match {
case Some(ai) if ai.values.contains(customMessageAnnotation) && ai.values(customMessageAnnotation).nonEmpty =>
Some(ai.values("msg").head)
case _ => None
}

override def readableMessage: String = customErrorMessage match {
override def readableMessage: String = customAssertErrorMessage match {
case Some(msg) => msg
case None => super.readableMessage
}

override def readableMessage(withId: Boolean, withPosition: Boolean): String = customErrorMessage match {
override def readableMessage(withId: Boolean, withPosition: Boolean): String = customAssertErrorMessage match {
case Some(msg) => msg
case None => super.readableMessage(withId, withPosition)
}
Expand Down

0 comments on commit f77c1b8

Please sign in to comment.