diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java index 7dd10ba14..80c452317 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java @@ -1939,7 +1939,6 @@ public class ScriptDocument { // Resolve receiver using existing chain-based resolver and detect static access TypeInfo receiverType = resolveReceiverChain(nameStart); MethodInfo resolvedMethod = null; - boolean computedStaticAccess = isStaticAccessCall(nameStart); if (receiverType != null) { if (receiverType.hasMethod(methodName)) { @@ -1947,23 +1946,26 @@ public class ScriptDocument { TypeInfo[] argTypes = arguments.stream().map(MethodCallInfo.Argument::getResolvedType).toArray(TypeInfo[]::new); // Get best method overload based on argument types resolvedMethod = receiverType.getBestMethodOverload(methodName, argTypes); - - MethodCallInfo callInfo = new MethodCallInfo( - methodName, nameStart, nameEnd, openParen, closeParen, - arguments, receiverType, resolvedMethod, computedStaticAccess - ); - - // Set expected type for validation if this is the final expression - if (!isFollowedByDot(closeParen)) { - TypeInfo expectedType = findExpectedTypeAtPosition(nameStart); - if (expectedType != null) { - callInfo.setExpectedType(expectedType); + if (isStaticAccess && resolvedMethod != null && !resolvedMethod.isStatic()) { + TokenErrorMessage errorMsg = TokenErrorMessage + .from("Cannot call non-static method '" + methodName + "' from static context '" + receiverType.getSimpleName() + "'") + .clearOtherErrors(); + marks.add(new ScriptLine.Mark(nameStart, nameEnd, TokenType.UNDEFINED_VAR, errorMsg)); + } else { + MethodCallInfo callInfo = new MethodCallInfo(methodName, nameStart, nameEnd, openParen, + closeParen, arguments, receiverType, resolvedMethod, isStaticAccess); + // Set expected type for validation if this is the final expression + if (!isFollowedByDot(closeParen)) { + TypeInfo expectedType = findExpectedTypeAtPosition(nameStart); + if (expectedType != null) { + callInfo.setExpectedType(expectedType); + } } + + callInfo.validate(); + methodCalls.add(callInfo); + marks.add(new ScriptLine.Mark(nameStart, nameEnd, TokenType.METHOD_CALL, callInfo)); } - - callInfo.validate(); - methodCalls.add(callInfo); - marks.add(new ScriptLine.Mark(nameStart, nameEnd, TokenType.METHOD_CALL, callInfo)); } else { marks.add(new ScriptLine.Mark(nameStart, nameEnd, TokenType.UNDEFINED_VAR)); } diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodCallInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodCallInfo.java index 64438c8f9..8b7668fdf 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodCallInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodCallInfo.java @@ -324,6 +324,7 @@ public class MethodCallInfo { } // Check static/instance access (skip for constructors) + // NO LONGER CHECKED HERE, BUT DIRECTLY AT MARK CREATION if (!isConstructor && isStaticAccess && !resolvedMethod.isStatic()) { setError(ErrorType.STATIC_ACCESS_ERROR, "Cannot call instance method '" + methodName + "' on a class type"); diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/ScriptTypeInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/ScriptTypeInfo.java index 9f1f04a53..f1e9943bc 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/ScriptTypeInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/ScriptTypeInfo.java @@ -126,7 +126,7 @@ public class ScriptTypeInfo extends TypeInfo { /** * Get all method overloads with the given name. */ - public List getMethodOverloads(String methodName) { + public List getAllMethodOverloads(String methodName) { return methods.getOrDefault(methodName, new ArrayList<>()); }