Added MISSING_BODY error for method declarations

This commit is contained in:
bigguy345 committed 2025-12-31 14:46:00 +02:00
1 parent 20f1c7cb66
commit c97de07ef7
4 files changed
+37 -23

No files matched your search

@@ -111,7 +111,7 @@ public class ErrorUnderlineRenderer {
}
// Check all method declarations for errors
for (MethodInfo method : doc.getMethods()) {
for (MethodInfo method : doc.getAllMethods()) {
if (!method.isDeclaration() || !method.hasError())
continue;
@@ -124,21 +124,14 @@ public class ErrorUnderlineRenderer {
}
// Handle missing return error (underline the method name)
if (method.hasMissingReturnError()) {
else if (method.hasMissingReturnError()) {
int methodNameStart = method.getNameOffset();
int methodNameEnd = methodNameStart + method.getName().length();
drawUnderlineForSpan(methodNameStart, methodNameEnd, lineStartX, baselineY,
lineText, lineStart, lineEnd, ERROR_COLOR);
}
// Handle duplicate method error (underline from full declaration start to closing paren)
if (method.getErrorType() == MethodInfo.ErrorType.DUPLICATE_METHOD) {
drawUnderlineForSpan(method.getFullDeclarationOffset(), method.getDeclarationEnd(),
lineStartX, baselineY, lineText, lineStart, lineEnd, ERROR_COLOR);
}
// Handle parameter errors
if (method.hasParameterErrors()) {
else if (method.hasParameterErrors()) {
for (MethodInfo.ParameterError paramError : method.getParameterErrors()) {
FieldInfo param = paramError.getParameter();
if (param == null || param.getDeclarationOffset() < 0)
@@ -150,6 +143,13 @@ public class ErrorUnderlineRenderer {
lineText, lineStart, lineEnd, ERROR_COLOR);
}
}
// Handle all other errors
else if (method.hasError()) {
drawUnderlineForSpan(method.getFullDeclarationOffset(), method.getDeclarationEnd(), lineStartX,
baselineY, lineText, lineStart, lineEnd, ERROR_COLOR);
}
}
}
@@ -4482,6 +4482,13 @@ public class ScriptDocument {
return Collections.unmodifiableList(methods);
}
public List<MethodInfo> getAllMethods() {
List<MethodInfo> allMethods = new ArrayList<>(methods);
for (ScriptTypeInfo scriptType : scriptTypes.values())
allMethods.addAll(scriptType.getAllMethodsFlat());
return allMethods;
}
public List<MethodCallInfo> getMethodCalls() {
return Collections.unmodifiableList(methodCalls);
}
@@ -232,18 +232,8 @@ public class TokenHoverInfo {
}
}
// If hovering over duplicate method declaration, show the error
if (methodDecl.getErrorType() == MethodInfo.ErrorType.DUPLICATE_METHOD) {
int declStart = methodDecl.getFullDeclarationOffset();
int declEnd = methodDecl.getDeclarationEnd();
if (tokenStart >= declStart && tokenEnd <= declEnd) {
errors.add(methodDecl.getErrorMessage());
}
}
// If hovering over a parameter with an error, show that error
if (methodDecl.hasParameterErrors()) {
else if (methodDecl.hasParameterErrors()) {
for (MethodInfo.ParameterError paramError : methodDecl.getParameterErrors()) {
FieldInfo param = paramError.getParameter();
if (param != null && param.getDeclarationOffset() >= 0) {
@@ -258,7 +248,7 @@ public class TokenHoverInfo {
}
// If hovering over a return statement with a type error, show that error
if (methodDecl.hasReturnStatementErrors()) {
else if (methodDecl.hasReturnStatementErrors()) {
for (MethodInfo.ReturnStatementError returnError : methodDecl.getReturnStatementErrors()) {
int returnStart = returnError.getStartOffset();
int returnEnd = returnError.getEndOffset();
@@ -268,6 +258,17 @@ public class TokenHoverInfo {
}
}
}
// All other errors
else if (methodDecl.hasError()) {
int declStart = methodDecl.getFullDeclarationOffset();
int declEnd = methodDecl.getDeclarationEnd();
if (tokenStart >= declStart && tokenEnd <= declEnd) {
errors.add(methodDecl.getErrorMessage());
}
}
}
if(token.getType() == TokenType.UNDEFINED_VAR)
@@ -337,7 +338,7 @@ public class TokenHoverInfo {
ScriptDocument doc = line.getParent();
int tokenStart = token.getGlobalStart();
for (MethodInfo method : doc.getMethods()) {
for (MethodInfo method : doc.getAllMethods()) {
if (!method.isDeclaration())
continue;
@@ -34,6 +34,7 @@ public final class MethodInfo {
public enum ErrorType {
NONE,
MISSING_RETURN, // Non-void method missing return statement
MISSING_BODY, // Non-void method missing return statement
RETURN_TYPE_MISMATCH, // Return statement type doesn't match method return type
VOID_METHOD_RETURNS_VALUE, // Void method returns a value
DUPLICATE_METHOD, // Method with same signature already defined in scope
@@ -433,6 +434,11 @@ public final class MethodInfo {
//No need to check for return types/statements
if(bodyless)
return;
if (bodyStart == bodyEnd && !isAbstract() && !isNative()) {
setError(ErrorType.MISSING_BODY, "Method must have a body or be declared abstract/native.");
return;
}
// Validate return statement types FIRST if we have a type resolver
// This ensures type errors are shown even if there's also a missing return