resolveExpressionType now accounts for method arg types when resolving a method, to fetch the matching overload

This commit is contained in:
bigguy345 committed 2025-12-29 15:16:40 +02:00
1 parent 7e25b1c858
commit 790cfae476
1 file changed
+19 -4
@@ -2431,8 +2431,10 @@ public class ScriptDocument {
// Check if followed by parentheses (method call)
boolean isMethodCall = false;
String arguments = null;
if (i < expr.length() && expr.charAt(i) == '(') {
isMethodCall = true;
int argsStart = i + 1;
// Skip to the matching closing paren
int depth = 1;
i++;
@@ -2442,6 +2444,13 @@ public class ScriptDocument {
else if (c == ')') depth--;
i++;
}
// Extract argument text (between parentheses)
int argsEnd = i - 1; // Position of closing paren
if (argsEnd > argsStart) {
arguments = expr.substring(argsStart, argsEnd);
} else {
arguments = ""; // Empty arguments
}
}
// Check if followed by array brackets (array access)
@@ -2461,7 +2470,7 @@ public class ScriptDocument {
}
}
segments.add(new ChainSegment(name, start, i, isMethodCall));
segments.add(new ChainSegment(name, start, i, isMethodCall, arguments));
// Skip whitespace
while (i < expr.length() && Character.isWhitespace(expr.charAt(i))) {
@@ -2578,12 +2587,14 @@ public class ScriptDocument {
final int start;
final int end;
final boolean isMethodCall;
final String arguments; // The text between parentheses for method calls, or null for fields
ChainSegment(String name, int start, int end, boolean isMethodCall) {
ChainSegment(String name, int start, int end, boolean isMethodCall, String arguments) {
this.name = name;
this.start = start;
this.end = end;
this.isMethodCall = isMethodCall;
this.arguments = arguments;
}
}
@@ -2596,9 +2607,13 @@ public class ScriptDocument {
}
if (segment.isMethodCall) {
// Method call - get return type
// Method call - get return type with argument-based overload resolution
if (currentType.hasMethod(segment.name)) {
MethodInfo methodInfo = currentType.getMethodInfo(segment.name);
// Parse argument types from the method call
TypeInfo[] argTypes = parseArgumentTypes(segment.arguments, segment.start);
// Get the best matching overload based on argument types
MethodInfo methodInfo = currentType.getBestMethodOverload(segment.name, argTypes);
return (methodInfo != null) ? methodInfo.getReturnType() : null;
}
return null;