mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 02:12:19 +00:00
Improve JS 'any' propagation in expression typing
This commit is contained in:
1 parent
182c00b142
commit
12850bfe36
2 files changed
+20
No files matched your search
+3
@@ -92,6 +92,7 @@ public class ExpressionTypeResolver {
|
||||
ExpressionNode.MemberAccessNode ma = (ExpressionNode.MemberAccessNode) node;
|
||||
TypeInfo targetType = resolveNodeType(ma.getTarget());
|
||||
if (targetType == null || !targetType.isResolved()) return null;
|
||||
if (targetType == TypeInfo.ANY || "any".equals(targetType.getFullName())) return TypeInfo.ANY;
|
||||
return context.resolveMemberAccess(targetType, ma.getMemberName());
|
||||
}
|
||||
|
||||
@@ -99,6 +100,7 @@ public class ExpressionTypeResolver {
|
||||
ExpressionNode.MethodCallNode mc = (ExpressionNode.MethodCallNode) node;
|
||||
TypeInfo targetType = mc.getTarget() == null ? context.resolveIdentifier("this") : resolveNodeType(mc.getTarget());
|
||||
if (targetType == null || !targetType.isResolved()) return null;
|
||||
if (targetType == TypeInfo.ANY || "any".equals(targetType.getFullName())) return TypeInfo.ANY;
|
||||
TypeInfo[] argTypes = new TypeInfo[mc.getArguments().size()];
|
||||
for (int i = 0; i < argTypes.length; i++) argTypes[i] = resolveNodeType(mc.getArguments().get(i));
|
||||
return context.resolveMethodCall(targetType, mc.getMethodName(), argTypes);
|
||||
@@ -108,6 +110,7 @@ public class ExpressionTypeResolver {
|
||||
ExpressionNode.ArrayAccessNode aa = (ExpressionNode.ArrayAccessNode) node;
|
||||
TypeInfo arrayType = resolveNodeType(aa.getArray());
|
||||
if (arrayType == null || !arrayType.isResolved()) return null;
|
||||
if (arrayType == TypeInfo.ANY || "any".equals(arrayType.getFullName())) return TypeInfo.ANY;
|
||||
String typeName = arrayType.getFullName();
|
||||
if (typeName.endsWith("[]")) {
|
||||
String elementTypeName = typeName.substring(0, typeName.length() - 2);
|
||||
|
||||
+17
@@ -118,12 +118,18 @@ public class TypeRules {
|
||||
return null;
|
||||
|
||||
case LOGICAL:
|
||||
if (isAny(left) || isAny(right)) {
|
||||
return TypeInfo.ANY;
|
||||
}
|
||||
if (isBoolean(left) && isBoolean(right)) {
|
||||
return TypeInfo.fromPrimitive("boolean");
|
||||
}
|
||||
return null;
|
||||
|
||||
case BITWISE:
|
||||
if (isAny(left) || isAny(right)) {
|
||||
return validateAgainstExpectedType(TypeInfo.ANY);
|
||||
}
|
||||
if (op == OperatorType.LEFT_SHIFT || op == OperatorType.RIGHT_SHIFT ||
|
||||
op == OperatorType.UNSIGNED_RIGHT_SHIFT) {
|
||||
if (isIntegral(left)) {
|
||||
@@ -152,6 +158,13 @@ public class TypeRules {
|
||||
if (op == null || operand == null || !operand.isResolved()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isAny(operand)) {
|
||||
if (op == OperatorType.LOGICAL_NOT) {
|
||||
return TypeInfo.fromPrimitive("boolean");
|
||||
}
|
||||
return TypeInfo.ANY;
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case UNARY_PLUS:
|
||||
@@ -195,6 +208,10 @@ public class TypeRules {
|
||||
if (!targetType.isResolved())
|
||||
return true; // Can't validate against unresolved type
|
||||
|
||||
if (isAny(sourceType) || isAny(targetType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Null literal can be assigned to any reference type
|
||||
if ("<null>".equals(sourceType.getFullName())) {
|
||||
return !isPrimitive(targetType);
|
||||
|
||||
Reference in new issue
Block a user