In JavaScript mode, treat java.lang.Object as "any", universally compatible with all types

This commit is contained in:
bigguy345 committed 2026-03-05 03:50:37 +02:00
1 parent 5271f90fa9
commit bfcca3e6f9
2 files changed
+16

No files matched your search

@@ -385,6 +385,8 @@ public class ScriptDocument {
* ALL methods called here handle BOTH languages using the SAME data structures.
*/
private List<ScriptLine.Mark> formatUnified() {
TypeChecker.enterTypeCheckingContext(isJavaScript());
// Phase 1: Find excluded regions (strings/comments) - same for both
findExcludedRanges();
@@ -13,6 +13,16 @@ public final class TypeChecker {
private TypeChecker() {} // Utility class
private static boolean CURRENT_JAVASCRIPT_MODE;
public static void enterTypeCheckingContext(boolean javaScriptMode) {
CURRENT_JAVASCRIPT_MODE = javaScriptMode;
}
private static boolean isJavaScriptMode() {
return CURRENT_JAVASCRIPT_MODE;
}
/**
* Check if the actual type is compatible with (assignable to) the expected type.
* @param expected The expected/target type
@@ -33,6 +43,10 @@ public final class TypeChecker {
if ("any".equals(expected.getFullName()) || "any".equals(actual.getFullName())) {
return true;
}
// In JavaScript mode, treat java.lang.Object as "any"
if (isJavaScriptMode() && "Object".equals(expected.getSimpleName())) {
return true;
}
// Handle null literal - null is compatible with any reference type (non-primitive)
if ("<null>".equals(actual.getFullName())) {