Skip to content

Commit

Permalink
SONARPY-2332 review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-serre-sonarsource committed Nov 22, 2024
1 parent 399db7e commit 4b342a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

public class RuntimeType implements InferredType {

// Name of the type returned by the type() function
private static final String TYPE_CLASS_NAME = "type";

private ClassSymbol typeClass;
private String builtinFullyQualifiedName;
private Set<String> typeClassSuperClassesFQN = null;
Expand All @@ -55,18 +52,16 @@ public boolean isIdentityComparableWith(InferredType other) {
if (other instanceof UnionType) {
return other.isIdentityComparableWith(this);
}
if (isComparingTypeWithMetaclass(other)) {
return true;
}
return this.equals(other);
return isComparingTypeWithMetaclass(other) || this.equals(other);
}

private boolean isComparingTypeWithMetaclass(InferredType other) {
if (other instanceof RuntimeType otherRuntimeType) {
String typeName = ((RuntimeType) InferredTypes.TYPE).getTypeClass().name();
boolean hasOtherMetaClass = hasMetaclassInHierarchy(otherRuntimeType);
boolean hasThisMetaClass = hasMetaclassInHierarchy(this);
return (TYPE_CLASS_NAME.equals(getTypeClass().name()) && hasOtherMetaClass)
|| (hasThisMetaClass && TYPE_CLASS_NAME.equals(otherRuntimeType.getTypeClass().name()));
return (typeName.equals(getTypeClass().name()) && hasOtherMetaClass)
|| (hasThisMetaClass && typeName.equals(otherRuntimeType.getTypeClass().name()));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ void isIdentityComparableWith() {

@Test
void isIdentityComparableWithMetaclass() {
RuntimeType typeType = new RuntimeType(new ClassSymbolImpl("type", "type"));

ClassSymbolImpl metaclassSymbol = new ClassSymbolImpl("Meta", "Meta");
metaclassSymbol.setHasMetaClass();
RuntimeType metaClassType = new RuntimeType(metaclassSymbol);
Expand All @@ -78,16 +76,16 @@ void isIdentityComparableWithMetaclass() {

UnknownClassType unknownClassType = new UnknownClassType(metaclassSymbol);

assertThat(typeType.isIdentityComparableWith(typeType)).isTrue();
assertThat(typeType.isIdentityComparableWith(metaClassType)).isTrue();
assertThat(typeType.isIdentityComparableWith(superMetaClassType)).isTrue();
assertThat(typeType.isIdentityComparableWith(unknownClassType)).isFalse();
assertThat(InferredTypes.TYPE.isIdentityComparableWith(InferredTypes.TYPE)).isTrue();
assertThat(InferredTypes.TYPE.isIdentityComparableWith(metaClassType)).isTrue();
assertThat(InferredTypes.TYPE.isIdentityComparableWith(superMetaClassType)).isTrue();
assertThat(InferredTypes.TYPE.isIdentityComparableWith(unknownClassType)).isFalse();

assertThat(metaClassType.isIdentityComparableWith(typeType)).isTrue();
assertThat(metaClassType.isIdentityComparableWith(InferredTypes.TYPE)).isTrue();
assertThat(metaClassType.isIdentityComparableWith(metaClassType)).isTrue();
assertThat(metaClassType.isIdentityComparableWith(superMetaClassType)).isFalse();

assertThat(superMetaClassType.isIdentityComparableWith(typeType)).isTrue();
assertThat(superMetaClassType.isIdentityComparableWith(InferredTypes.TYPE)).isTrue();
assertThat(superMetaClassType.isIdentityComparableWith(metaClassType)).isFalse();
assertThat(superMetaClassType.isIdentityComparableWith(superMetaClassType)).isTrue();
}
Expand Down

0 comments on commit 4b342a8

Please sign in to comment.