}
}
// Variable we're matching must exist and be a tagged type
Type matchingOverType = matchingOver.getType();
String className = getTypeName(matchingOverType);
if (className == null){
//TODO change this to an error message
throw new RuntimeException("variable matching over must be a Class or Type");
}
TagBinding matchBinding = TagBinding.get(className);
if (matchBinding == null) {
//TODO change this to a typecheck error
throw new RuntimeException("Value is not tagged.");
}
//All things we match over must be tagged types
for (Case c : cases) {
if (c.isDefault()) continue;
String tagName = c.getTaggedTypeMatch();
Optional<ClassType> type = env.lookupBinding(tagName, ClassType.class);
NameBinding binding = env.lookup(tagName);
if (binding == null) {
// type wasn't declared...
ToolError.reportError(ErrorMessage.UNKNOWN_TAG, matchingOver);
}
Type t = binding.getType();
if (t instanceof ClassType) {
ClassType classType = (ClassType) t;
String name = classType.getName();