mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 04:59:05 +00:00
Fixed broken null assignments i.e. var npc = null
This commit is contained in:
1 parent
4fa7a73704
commit
6b7563cab3
3 files changed
+17
-6
No files matched your search
@@ -1495,7 +1495,10 @@ public class ScriptDocument {
|
||||
|
||||
// Priority 2: Infer type from initializer if no JSDoc type
|
||||
if (typeInfo == null && initializer != null && !initializer.isEmpty()) {
|
||||
typeInfo = resolveExpressionType(initializer, bodyStart + initializerStart);
|
||||
TypeInfo inferred = resolveExpressionType(initializer, bodyStart + initializerStart);
|
||||
if (!TypeInfo.NULL.equals(inferred)) {
|
||||
typeInfo = inferred;
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: Use "any" type for uninitialized variables
|
||||
@@ -1767,7 +1770,10 @@ public class ScriptDocument {
|
||||
|
||||
// Priority 2: Infer from initializer
|
||||
if (varType == null && initializer != null && !initializer.isEmpty()) {
|
||||
varType = resolveExpressionType(initializer, start + initializerStart);
|
||||
TypeInfo inferred = resolveExpressionType(initializer, start + initializerStart);
|
||||
if (!TypeInfo.NULL.equals(inferred)) {
|
||||
varType = inferred;
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: Use "any" type
|
||||
@@ -2480,7 +2486,10 @@ public class ScriptDocument {
|
||||
|
||||
// Priority 2: Infer from initializer if no JSDoc type
|
||||
if (typeInfo == null && initializer != null && !initializer.isEmpty()) {
|
||||
typeInfo = resolveExpressionType(initializer, initializerStart);
|
||||
TypeInfo inferred = resolveExpressionType(initializer, initializerStart);
|
||||
if (!TypeInfo.NULL.equals(inferred)) {
|
||||
typeInfo = inferred;
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: Use "any" type for uninitialized variables
|
||||
@@ -4849,7 +4858,7 @@ public class ScriptDocument {
|
||||
|
||||
// Null literal
|
||||
if (expr.equals("null")) {
|
||||
return TypeInfo.unresolved("null", "<null>"); // null is compatible with any reference type
|
||||
return TypeInfo.NULL; // null is compatible with any reference type
|
||||
}
|
||||
|
||||
// Numeric literals with precision checking
|
||||
|
||||
@@ -37,8 +37,8 @@ public final class TypeChecker {
|
||||
// Handle null literal - null is compatible with any reference type (non-primitive)
|
||||
if ("<null>".equals(actual.getFullName())) {
|
||||
Class<?> expectedClass = expected.getJavaClass();
|
||||
if (expectedClass != null && !expectedClass.isPrimitive()) {
|
||||
return true; // null can be assigned to any reference type
|
||||
if (expectedClass != null && !expectedClass.isPrimitive() || "<null>".equals(expected.getFullName())) {
|
||||
return true; // null can be assigned to any reference type and null
|
||||
}
|
||||
// null cannot be assigned to primitive types
|
||||
return false;
|
||||
|
||||
@@ -48,6 +48,8 @@ public class TypeInfo {
|
||||
|
||||
public static final TypeInfo STRING = TypeInfo.fromClass(String.class);
|
||||
|
||||
public static final TypeInfo NULL = TypeInfo.unresolved("null", "<null>");
|
||||
|
||||
/**
|
||||
* Singleton constant for the "any" type (used in JavaScript/TypeScript).
|
||||
* The "any" type is universally compatible - it can be assigned to anything
|
||||
|
||||
Reference in new issue
Block a user