Check that a parameter name of a function definition does not shadow an enum definition.
This commit is contained in:
@@ -851,10 +851,24 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
||||
var parameterName = ctx.IDENT().getText();
|
||||
var parameterType = Type.getByName(ctx.type_annotation().type().getText());
|
||||
|
||||
if (structDefs.containsKey(parameterName)) {
|
||||
var line = ctx.start.getLine();
|
||||
var col = ctx.start.getCharPositionInLine();
|
||||
var error = "Parameter name " + parameterName + " duplicates a struct of the same name.";
|
||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
||||
}
|
||||
|
||||
if (enumDefs.containsKey(parameterName)) {
|
||||
var line = ctx.start.getLine();
|
||||
var col = ctx.start.getCharPositionInLine();
|
||||
var error = "Parameter name " + parameterName + " duplicates an enum of the same name.";
|
||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
||||
}
|
||||
|
||||
if (!parameterType.isPrimitiveType() && !structDefs.containsKey(parameterType.getName()) && !enumDefs.containsKey(parameterType.getName())) {
|
||||
var line = ctx.type_annotation().start.getLine();
|
||||
var col = ctx.type_annotation().start.getCharPositionInLine();
|
||||
String error = "Type " + parameterType.getName() + " not defined.";
|
||||
var error = "Type " + parameterType.getName() + " not defined.";
|
||||
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user