From e3fc9e8e4a67f5ee39e38130757134b1e37bddcb Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Mon, 9 Mar 2026 00:35:53 +0200 Subject: [PATCH] Fixed method calls of JS type constructors throwing errors, made it dynamic --- .../interpreter/hover/TokenHoverInfo.java | 3 +++ .../interpreter/method/MethodCallInfo.java | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java index c172ec9db..75150e1e1 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java @@ -243,6 +243,9 @@ public class TokenHoverInfo { if (callInfo.hasStaticAccessError()) { errors.add(callInfo.getErrorMessage()); } + if (callInfo.getErrorType() == MethodCallInfo.ErrorType.UNRESOLVED_METHOD) { + errors.add(callInfo.getErrorMessage()); + } } // Show field access errors 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 bd73b497f..a0005efa0 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 @@ -331,13 +331,16 @@ public class MethodCallInfo { public void validate() { if (isConstructor) { if (resolvedMethod == null) { - // For constructors, check if the type has any constructors at all - if (receiverType != null && receiverType.hasConstructors()) { - setError(ErrorType.WRONG_ARG_COUNT, - "No constructor in '" + receiverType.getSimpleName() + "' matches " + arguments.size() + " argument(s)"); - } else { - setError(ErrorType.UNRESOLVED_METHOD, - "Cannot resolve constructor for '" + methodName + "'"); + // Don't report missing JS constructors as unresolved method error, since they may be created dynamically at runtime + boolean isJSType = receiverType != null && receiverType.isJSType(); + if (!isJSType) { + if (receiverType != null && receiverType.hasConstructors()) { + setError(ErrorType.WRONG_ARG_COUNT, + "No constructor in '" + receiverType.getSimpleName() + "' matches " + arguments.size() + " argument(s)"); + } else { + setError(ErrorType.UNRESOLVED_METHOD, + "Cannot resolve constructor for '" + methodName + "'"); + } } } else if (receiverType != null) { List cParams = resolvedMethod.getParameters();