mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 05:27:37 +00:00
Fixed .d.ts js types of same assignability/inheritance (ICustomNpc -> IEntity) not being checked properly
This commit is contained in:
1 parent
006766bc1e
commit
6328826c9e
1 file changed
+38
@@ -1,5 +1,10 @@
|
||||
package noppes.npcs.client.gui.util.script.interpreter.type;
|
||||
|
||||
import noppes.npcs.client.gui.util.script.interpreter.js_parser.JSTypeInfo;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class for checking type compatibility between types.
|
||||
* Handles primitive widening conversions, boxing/unboxing, and inheritance.
|
||||
@@ -62,6 +67,13 @@ public final class TypeChecker {
|
||||
if (isNumericType(expectedName) && isNumericType(actualName)) {
|
||||
return canWiden(actualName, expectedName);
|
||||
}
|
||||
|
||||
// JS/.d.ts type compatibility (check inheritance chain from actual -> parent)
|
||||
if (expected.isJSType() && actual.isJSType()) {
|
||||
if (isJSTypeAssignableFrom(expected.getJSTypeInfo(), actual.getJSTypeInfo())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Object type compatibility (check inheritance)
|
||||
if (expected.getJavaClass() != null && actual.getJavaClass() != null) {
|
||||
@@ -92,6 +104,32 @@ public final class TypeChecker {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check assignability for JS/.d.ts types by walking the resolved parent chain.
|
||||
*/
|
||||
private static boolean isJSTypeAssignableFrom(JSTypeInfo expected, JSTypeInfo actual) {
|
||||
if (expected == null || actual == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<String> visited = new HashSet<>();
|
||||
JSTypeInfo current = actual;
|
||||
while (current != null) {
|
||||
String currentFullName = current.getFullName();
|
||||
if (currentFullName == null || !visited.add(currentFullName)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (expected.getFullName() != null && expected.getFullName().equals(currentFullName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
current = current.getResolvedParent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the type is a numeric type (including wrappers).
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user