From 36e817925591197a1283dedc5b0a562d47b71d6c Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Wed, 25 Jan 2023 11:57:34 +0100
Subject: [PATCH] Make type check error messages a bit more helpful

---
 .../java/de/prob/voparser/VOTypeChecker.java   | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/de/prob/voparser/VOTypeChecker.java b/src/main/java/de/prob/voparser/VOTypeChecker.java
index e296814..3fa6385 100644
--- a/src/main/java/de/prob/voparser/VOTypeChecker.java
+++ b/src/main/java/de/prob/voparser/VOTypeChecker.java
@@ -94,11 +94,10 @@ public class VOTypeChecker extends DepthFirstAdapter {
 	private PersistentHashSet<AnimatorState> visitIdentifierNode(AIdentifierVo node, PersistentHashSet<AnimatorState> animatorState) {
 		final String id = node.getIdentifierLiteral().getText();
 		if (!voParser.getTasks().containsKey(id)) {
-			throw new VOTypeCheckException("Scope error in VO");
+			throw new VOTypeCheckException("Unknown validation task identifier: " + id);
 		}
 		VTType type = voParser.getTasks().get(id);
 		PersistentHashSet<AnimatorState> newAnimatorState = animatorState;
-		boolean valid = true;
 		switch (type) {
 			case RELOAD:
 				newAnimatorState = newAnimatorState.cons(AnimatorState.TRACE);
@@ -112,23 +111,26 @@ public class VOTypeChecker extends DepthFirstAdapter {
 				newAnimatorState = newAnimatorState.disjoin(AnimatorState.STATE_SPACE);
 				break;
 			case TRACE:
-				valid = newAnimatorState.contains(AnimatorState.TRACE);
+				if (!newAnimatorState.contains(AnimatorState.TRACE)) {
+					throw new VOTypeCheckException("Validation task " + id + " requires a trace");
+				}
 				break;
 			case STATE_SPACE:
-				valid = newAnimatorState.contains(AnimatorState.STATE_SPACE);
+				if (!newAnimatorState.contains(AnimatorState.STATE_SPACE)) {
+					throw new VOTypeCheckException("Validation task " + id + " requires a state space");
+				}
 				newAnimatorState = newAnimatorState.disjoin(AnimatorState.TRACE);
 				newAnimatorState = newAnimatorState.disjoin(AnimatorState.STATE_SPACE);
 				break;
 			case EXPLORE:
-				valid = newAnimatorState.contains(AnimatorState.TRACE);
+				if (!newAnimatorState.contains(AnimatorState.TRACE)) {
+					throw new VOTypeCheckException("Validation task " + id + " requires a trace");
+				}
 				newAnimatorState = newAnimatorState.disjoin(AnimatorState.TRACE);
 				break;
 			default:
 				break;
 		}
-		if(!valid) {
-			throw new VOTypeCheckException("Type error in VO");
-		}
 		return newAnimatorState;
 	}
 }
-- 
GitLab