Added constructor error validation

This commit is contained in:
bigguy345 committed 2025-12-28 16:19:15 +02:00
1 parent 323502aa5e
commit 8b95d61e0f
3 files changed
+24 -14

No files matched your search

@@ -305,7 +305,18 @@ public class MethodCallInfo {
*/
public void validate() {
if (resolvedMethod == null) {
setError(ErrorType.UNRESOLVED_METHOD, "Cannot resolve method '" + methodName + "'");
if (isConstructor) {
// For constructors, check if the type has any constructors at all
if (receiverType != null && receiverType.hasConstructors()) {
setError(ErrorType.WRONG_ARG_COUNT,
"No constructor in '" + methodName + "' matches " + arguments.size() + " argument(s)");
} else {
setError(ErrorType.UNRESOLVED_METHOD,
"Cannot resolve constructor for '" + methodName + "'");
}
} else {
setError(ErrorType.UNRESOLVED_METHOD, "Cannot resolve method '" + methodName + "'");
}
return;
}
@@ -3378,18 +3378,17 @@ public class ScriptDocument {
List<MethodCallInfo.Argument> arguments = parseMethodArguments(openParen + 1, closeParen);
int argCount = arguments.size();
if (info.hasConstructors()) {
MethodInfo constructor = info.findConstructor(argCount);
if (constructor != null) {
// Create MethodCallInfo for constructor
MethodCallInfo ctorCall = MethodCallInfo.constructor(
info, constructor, start, end, openParen, closeParen, arguments
);
ctorCall.validate();
marks.add(new ScriptLine.Mark(start, end, info.getTokenType(), ctorCall));
continue;
}
}
// Try to find matching constructor (may be null if not found)
MethodInfo constructor = info.hasConstructors() ? info.findConstructor(argCount) : null;
// Create MethodCallInfo for constructor (even if null, so errors are tracked)
MethodCallInfo ctorCall = MethodCallInfo.constructor(
info, constructor, start, end, openParen, closeParen, arguments
);
ctorCall.validate();
methodCalls.add(ctorCall); // Add to methodCalls list for error tracking
marks.add(new ScriptLine.Mark(start, end, info.getTokenType(), ctorCall));
continue;
}
}
}
@@ -171,7 +171,7 @@ public class TokenHoverInfo {
MethodCallInfo callInfo = token.getMethodCallInfo();
if (callInfo != null) {
if (callInfo.hasArgCountError()) {
errors.add("Expected " + getExpectedArgCount(callInfo) + " argument(s) but found " + callInfo.getArguments().size());
errors.add(callInfo.getErrorMessage());
}
if (callInfo.hasArgTypeError()) {
for (MethodCallInfo.ArgumentTypeError error : callInfo.getArgumentTypeErrors()) {