Check that a struct field name of a struct declaration does not shadow an enum or a struct definition.

This commit is contained in:
2023-03-15 23:48:57 +01:00
parent 30dfbbbbba
commit 2768b4429c
2 changed files with 42 additions and 0 deletions

View File

@@ -799,6 +799,16 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
}
if (structDefs.containsKey(structFieldName)) {
var error = "Struct field name " + structFieldName + " shadows a struct of the same name.";
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
}
if (enumDefs.containsKey(structFieldName)) {
var error = "Struct field name " + structFieldName + " shadows an enum of the same name.";
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
}
var structField = new StructField(structFieldName);
structField.type = structFieldType;
structField.line = line;