Make sure that a variable that references an enum has to be initialized.

This commit is contained in:
2023-03-16 00:01:31 +01:00
parent 2768b4429c
commit 55a5b8f54a
2 changed files with 21 additions and 1 deletions

View File

@@ -216,6 +216,11 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
variableDeclaration = new VariableDeclaration(variableName, (Expression) expression);
variableDeclaration.initialized = true;
} else {
if (enumDefs.containsKey(declaredType.getName())) {
var error = "Variable " + variableName + " references an enum but is not initialized.";
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
}
variableDeclaration = new VariableDeclaration(variableName);
}