refactor: implemented labelAndExplain(), combining label and explain, and... #9

Merged
gc1523 merged 18 commits from error-messages into master 2025-02-06 20:30:26 +00:00
7 changed files with 488 additions and 133 deletions
Showing only changes of commit ae9625b586 - Show all commits

View File

@@ -120,12 +120,15 @@ object renamer {
globalNumbering: mutable.Map[String, Int], globalNumbering: mutable.Map[String, Int],
errors: mutable.Builder[Error, List[Error]] errors: mutable.Builder[Error, List[Error]]
): Unit = { ): Unit = {
scope.current.withDefault(scope.parent).get((ident.v, identType)) match { // Unfortunately map defaults only work with `.apply()`, which throws an error when the key is not found.
case Some(Ident(_, uid)) => ident.uid = uid // Neither is there a way to check whether a default exists, so we have to use a try-catch.
case None => { try {
val Ident(_, uid) = scope.current.withDefault(scope.parent)((ident.v, identType))
ident.uid = uid
} catch {
case _: NoSuchElementException =>
errors += Error.UndefinedIdentifier(ident, identType) errors += Error.UndefinedIdentifier(ident, identType)
scope.add(?, ident, identType) scope.add(?, ident, identType)
} }
} }
}
} }