Fix possible stack overflow in Listing/Mapping type checking (#826)

This commit is contained in:
Islon Scherer
2024-11-22 09:39:52 +01:00
committed by GitHub
parent 45302c8a00
commit 1abd174d77

View File

@@ -161,7 +161,11 @@ public abstract class TypeNode extends PklNode {
} }
/** Tells if this typenode is the same typecheck as the other typenode. */ /** Tells if this typenode is the same typecheck as the other typenode. */
public abstract boolean isEquivalentTo(TypeNode other); public boolean isEquivalentTo(TypeNode other) {
return this == other || doIsEquivalentTo(other);
}
protected abstract boolean doIsEquivalentTo(TypeNode other);
public @Nullable VmClass getVmClass() { public @Nullable VmClass getVmClass() {
return null; return null;
@@ -304,7 +308,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof UnknownTypeNode; return other instanceof UnknownTypeNode;
} }
@@ -371,7 +375,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof NothingTypeNode; return other instanceof NothingTypeNode;
} }
@@ -408,7 +412,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof FinalModuleTypeNode finalModuleTypeNode)) { if (!(other instanceof FinalModuleTypeNode finalModuleTypeNode)) {
return false; return false;
} }
@@ -460,7 +464,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof NonFinalModuleTypeNode nonFinalModuleTypeNode)) { if (!(other instanceof NonFinalModuleTypeNode nonFinalModuleTypeNode)) {
return false; return false;
} }
@@ -496,7 +500,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof StringLiteralTypeNode stringLiteralTypeNode)) { if (!(other instanceof StringLiteralTypeNode stringLiteralTypeNode)) {
return false; return false;
} }
@@ -551,7 +555,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof TypedTypeNode; return other instanceof TypedTypeNode;
} }
@@ -586,7 +590,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof DynamicTypeNode; return other instanceof DynamicTypeNode;
} }
@@ -636,7 +640,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof FinalClassTypeNode finalClassTypeNode)) { if (!(other instanceof FinalClassTypeNode finalClassTypeNode)) {
return false; return false;
} }
@@ -705,7 +709,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof NonFinalClassTypeNode nonFinalClassTypeNode)) { if (!(other instanceof NonFinalClassTypeNode nonFinalClassTypeNode)) {
return false; return false;
} }
@@ -772,7 +776,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof NullableTypeNode nullableTypeNode)) { if (!(other instanceof NullableTypeNode nullableTypeNode)) {
return false; return false;
} }
@@ -842,7 +846,7 @@ public abstract class TypeNode extends PklNode {
@Override @Override
@ExplodeLoop @ExplodeLoop
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof UnionTypeNode unionTypeNode)) { if (!(other instanceof UnionTypeNode unionTypeNode)) {
return false; return false;
} }
@@ -1016,7 +1020,7 @@ public abstract class TypeNode extends PklNode {
@Override @Override
@TruffleBoundary @TruffleBoundary
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof UnionOfStringLiteralsTypeNode unionOfStringLiteralsTypeNode)) { if (!(other instanceof UnionOfStringLiteralsTypeNode unionOfStringLiteralsTypeNode)) {
return false; return false;
} }
@@ -1092,7 +1096,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return false; return false;
} }
@@ -1223,7 +1227,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof ListTypeNode listTypeNode)) { if (!(other instanceof ListTypeNode listTypeNode)) {
return false; return false;
} }
@@ -1268,7 +1272,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof SetTypeNode setTypeNode)) { if (!(other instanceof SetTypeNode setTypeNode)) {
return false; return false;
} }
@@ -1360,7 +1364,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof MapTypeNode mapTypeNode)) { if (!(other instanceof MapTypeNode mapTypeNode)) {
return false; return false;
} }
@@ -1451,7 +1455,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof ListingTypeNode listingTypeNode)) { if (!(other instanceof ListingTypeNode listingTypeNode)) {
return false; return false;
} }
@@ -1509,7 +1513,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof MappingTypeNode mappingTypeNode)) { if (!(other instanceof MappingTypeNode mappingTypeNode)) {
return false; return false;
} }
@@ -1748,7 +1752,7 @@ public abstract class TypeNode extends PklNode {
@Override @Override
@ExplodeLoop @ExplodeLoop
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof FunctionTypeNode functionTypeNode)) { if (!(other instanceof FunctionTypeNode functionTypeNode)) {
return false; return false;
} }
@@ -1845,7 +1849,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof FunctionClassTypeNode functionClassTypeNode)) { if (!(other instanceof FunctionClassTypeNode functionClassTypeNode)) {
return false; return false;
} }
@@ -1883,7 +1887,7 @@ public abstract class TypeNode extends PklNode {
@Override @Override
@ExplodeLoop @ExplodeLoop
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof FunctionNClassTypeNode functionNClassTypeNode)) { if (!(other instanceof FunctionNClassTypeNode functionNClassTypeNode)) {
return false; return false;
} }
@@ -1986,7 +1990,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof PairTypeNode pairTypeNode)) { if (!(other instanceof PairTypeNode pairTypeNode)) {
return false; return false;
} }
@@ -2043,7 +2047,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if (!(other instanceof VarArgsTypeNode varArgsTypeNode)) { if (!(other instanceof VarArgsTypeNode varArgsTypeNode)) {
return false; return false;
} }
@@ -2095,7 +2099,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof TypeVariableNode; return other instanceof TypeVariableNode;
} }
@@ -2135,7 +2139,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof NonNullTypeAliasTypeNode; return other instanceof NonNullTypeAliasTypeNode;
} }
@@ -2184,7 +2188,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof UIntTypeAliasTypeNode aliasTypeNode && mask == aliasTypeNode.mask; return other instanceof UIntTypeAliasTypeNode aliasTypeNode && mask == aliasTypeNode.mask;
} }
@@ -2228,7 +2232,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof Int8TypeAliasTypeNode; return other instanceof Int8TypeAliasTypeNode;
} }
@@ -2272,7 +2276,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof Int16TypeAliasTypeNode; return other instanceof Int16TypeAliasTypeNode;
} }
@@ -2316,7 +2320,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof Int32TypeAliasTypeNode; return other instanceof Int32TypeAliasTypeNode;
} }
@@ -2471,7 +2475,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
if ((other instanceof TypeAliasTypeNode typeAliasTypeNode)) { if ((other instanceof TypeAliasTypeNode typeAliasTypeNode)) {
return aliasedTypeNode.isEquivalentTo(typeAliasTypeNode.aliasedTypeNode); return aliasedTypeNode.isEquivalentTo(typeAliasTypeNode.aliasedTypeNode);
} }
@@ -2581,7 +2585,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
// consider constrained types as always different // consider constrained types as always different
return false; return false;
} }
@@ -2622,7 +2626,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof AnyTypeNode; return other instanceof AnyTypeNode;
} }
@@ -2650,7 +2654,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof StringTypeNode; return other instanceof StringTypeNode;
} }
@@ -2714,7 +2718,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof NumberTypeNode; return other instanceof NumberTypeNode;
} }
@@ -2742,7 +2746,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof IntTypeNode; return other instanceof IntTypeNode;
} }
@@ -2787,7 +2791,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof FloatTypeNode; return other instanceof FloatTypeNode;
} }
@@ -2832,7 +2836,7 @@ public abstract class TypeNode extends PklNode {
} }
@Override @Override
public boolean isEquivalentTo(TypeNode other) { public boolean doIsEquivalentTo(TypeNode other) {
return other instanceof BooleanTypeNode; return other instanceof BooleanTypeNode;
} }